Skip to content

Conversation

@jmoseley
Copy link
Contributor

@jmoseley jmoseley commented Feb 10, 2026

Summary

Exposes working directory and repository context for sessions via listSessions(), adds optional filtering, and adds the session.context_changed event type for detecting context changes during a session.

Implemented across all SDK clients: Node.js, Python, Go, .NET.

New Types

SessionContext

interface SessionContext {
    cwd: string;        // Working directory where session was created
    gitRoot?: string;   // Git repository root (if in a git repo)
    repository?: string; // GitHub repo in owner/repo format
    branch?: string;    // Current git branch
}

SessionListFilter

interface SessionListFilter {
    cwd?: string;
    gitRoot?: string;
    repository?: string;
    branch?: string;
}

API Changes

SessionMetadata

Added context?: SessionContext field — available when listing sessions.

listSessions()

Now accepts optional filter parameter:

// List all sessions
const sessions = await client.listSessions();

// Filter by repository
const sessions = await client.listSessions({ repository: 'github/copilot-sdk' });

session.context_changed event

New session event emitted when the working directory context changes between turns (e.g., agent switches branch, user changes cwd):

session.on('session.context_changed', (event) => {
    console.log('Context changed:', event.data);
    // { cwd, gitRoot?, repository?, branch? }
});

Changes

  • Added SessionContext and SessionListFilter types to all SDKs
  • Updated SessionMetadata to include context field
  • Updated listSessions() to accept optional filter and return context
  • Added session.context_changed to generated session event types
  • Updated documentation

Runtime PRs (merged)

Fixes #413
Fixes #200

Copilot AI review requested due to automatic review settings February 10, 2026 21:06
@jmoseley jmoseley requested a review from a team as a code owner February 10, 2026 21:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds session “working directory / git repo” context to Node SDK SessionMetadata returned by listSessions(), and introduces an optional filter parameter to support server-side session filtering.

Changes:

  • Added new public types SessionContext and SessionListFilter, and extended SessionMetadata with context?: SessionContext.
  • Updated CopilotClient.listSessions() to accept an optional filter and to return the new context field.
  • Updated Node docs/cookbook examples and added an E2E assertion for the new context field.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
nodejs/src/types.ts Introduces SessionContext / SessionListFilter and adds context onto SessionMetadata.
nodejs/src/client.ts Extends listSessions() to accept a filter and map context from the JSON-RPC response.
nodejs/src/index.ts Re-exports SessionListFilter from the package entrypoint (but currently not SessionContext).
nodejs/test/e2e/session.test.ts Adds an E2E test asserting listSessions() returns a context.cwd.
nodejs/README.md Documents SessionMetadata.context and the SessionContext fields (but doesn’t yet document filtering).
cookbook/nodejs/persisting-sessions.md Adds example printing session context information.
cookbook/nodejs/multiple-sessions.md Adds example showing context?.cwd when listing sessions.

Adds SessionContext to SessionMetadata so SDK consumers can see the
working directory and repository information for each session.

Also adds optional filter parameter to listSessions() for filtering
by context fields (cwd, gitRoot, repository, branch).

Implemented in all SDK clients:
- Node.js
- Python
- Go
- .NET

Fixes #413
Fixes #200
@github-actions
Copy link

Cross-SDK Consistency Review: ✅ Excellent Consistency

I've reviewed this PR for cross-language SDK consistency. This PR adds session context information (SessionContext) and filtering capabilities (SessionListFilter) to the listSessions() method across all four SDK implementations. The changes maintain excellent consistency across languages.

✅ What's Consistent

1. Type Definitions

All SDKs define the same two new types with equivalent fields:

SessionContext:

  • cwd (string, required) - Working directory where session was created
  • gitRoot (string, optional) - Git repository root
  • repository (string, optional) - GitHub repository in "owner/repo" format
  • branch (string, optional) - Current git branch

SessionListFilter:

  • cwd (string, optional) - Filter by exact cwd match
  • gitRoot (string, optional) - Filter by git root
  • repository (string, optional) - Filter by repository
  • branch (string, optional) - Filter by branch

All field names use consistent casing (camelCase for TypeScript, snake_case for Python, PascalCase for .NET/Go).

2. API Changes

All SDKs updated their listSessions method with equivalent signatures:

  • Node.js: listSessions(filter?: SessionListFilter)
  • Python: list_sessions(filter: SessionListFilter | None = None)
  • Go: ListSessions(ctx context.Context, filter *SessionListFilter)
  • .NET: ListSessionsAsync(SessionListFilter? filter = null, ...)

The filter parameter is optional/nullable in all implementations.

3. SessionMetadata Updates

All SDKs added the context field to SessionMetadata as an optional field.

4. Code Changes

All SDKs properly:

  • Export/expose the new types in their public API
  • Pass the filter to the JSON-RPC call correctly
  • Parse and populate the context field in responses

5. Tests

  • Node.js: Added test verifying context field is populated ✅
  • Go: Updated existing tests to pass nil filter ✅
  • Python: Existing tests still work (no filter passed) ✅
  • .NET: (no new tests, but existing integration should work)

📝 Minor Documentation Gap (Non-blocking)

The following READMEs document the new SessionContext type but don't yet document the filtering parameter:

  • Python README: No mention of SessionListFilter or the filter parameter (though docstrings in code are complete)
  • .NET README: Signature still shows ListSessionsAsync() with no parameters documented (line 119)

These are documentation-only gaps and don't affect API consistency. The in-code documentation (docstrings/JSDoc/XML comments) is complete in all languages.

🎯 Recommendation

Approve - This PR maintains excellent cross-SDK consistency. The API design is parallel across all four languages, accounting for language-specific idioms. The minor documentation gaps can be addressed in a follow-up if desired, but they don't affect the functionality or API design consistency.

Great work maintaining feature parity across all SDKs! 🚀

AI generated by SDK Consistency Review Agent

@github-actions
Copy link

✅ Cross-SDK Consistency Review

I've reviewed PR #427 for consistency across all four SDK implementations (Node.js, Python, Go, .NET), and I'm pleased to report that this PR maintains excellent cross-SDK consistency!

What was added:

  1. SessionContext type - provides working directory context (cwd, gitRoot, repository, branch)
  2. SessionListFilter type - enables filtering sessions by these context fields
  3. Enhanced listSessions() method to accept optional filter parameter
  4. Added context field to SessionMetadata

Consistency verification:

All four SDKs updated - Node.js, Python, Go, and .NET all include the changes
Type definitions match - All SDKs define the same fields with matching JSON names
API signatures are parallel - Each SDK follows its language conventions:

  • Node.js: listSessions(filter?: SessionListFilter)
  • Python: list_sessions(filter: SessionListFilter | None = None)
  • Go: ListSessions(ctx context.Context, filter *SessionListFilter)
  • .NET: ListSessionsAsync(SessionListFilter? filter = null, CancellationToken cancellationToken = default)

Naming conventions respected - camelCase (Node/Python JSON), PascalCase (Go/C#) as appropriate
Documentation complete - All SDKs have comprehensive doc comments
Tests updated - Go tests pass nil, Node.js has a skipped test ready for runtime support

Language-specific differences (appropriate):

  • Go includes context.Context as first parameter (Go standard practice)
  • .NET includes CancellationToken parameter (idiomatic for async methods)
  • These differences are correct and expected

No consistency issues found. This PR successfully maintains feature parity across all SDK implementations while respecting each language's conventions. Nice work! 🎉

AI generated by SDK Consistency Review Agent

@IeuanWalker
Copy link

IeuanWalker commented Feb 10, 2026

@jmoseley does the SDK track if the git branch changes? if it does could it expose an event for it?

Adds the session.context_changed event to generated session event types
in all SDK clients (Node.js, Python, Go, .NET).

The event fires when the working directory context changes between turns
and contains the updated context (cwd, gitRoot, repository, branch).
@github-actions
Copy link

✅ Cross-SDK Consistency Review

I've reviewed PR #427 for consistency across all four SDK implementations (Node.js, Python, Go, .NET). Overall, this is an excellent example of consistent cross-SDK development! 🎉

✅ What's Consistent

1. Type Definitions

  • All SDKs define SessionContext with the same four fields (cwd, gitRoot, repository, branch)
  • All SDKs define SessionListFilter with identical filtering options
  • All SDKs properly add context?: SessionContext to SessionMetadata
  • Naming conventions are correctly applied:
    • Node.js/TypeScript: camelCase fields
    • Python: camelCase fields (for JSON compatibility)
    • Go: PascalCase fields with camelCase JSON tags
    • .NET: PascalCase properties with camelCase serialization (via JsonSerializerDefaults.Web)

2. Method Signatures
All SDKs properly updated listSessions/list_sessions/ListSessions/ListSessionsAsync to accept an optional filter parameter:

  • Node.js: async listSessions(filter?: SessionListFilter)
  • Python: async def list_sessions(self, filter: SessionListFilter | None = None)
  • Go: func ListSessions(ctx context.Context, filter *SessionListFilter)
  • .NET: async Task(List<SessionMetadata)> ListSessionsAsync(SessionListFilter? filter = null, CancellationToken cancellationToken = default)

3. Generated Session Events
All SDKs include the new session.context_changed event in their generated event types.

4. Public API Exports

  • Node.js: Exports SessionContext and SessionListFilter via index.ts
  • Python: Exports both types via __init__.py
  • Go: Both types are exported (PascalCase)
  • .NET: Both types are public classes

📝 Minor Documentation Gap

Issue: The .NET README documents ListSessionsAsync() but hasn't been updated to show the new optional filter parameter.

Current (line 119):

##### `ListSessionsAsync(): Task(List<SessionMetadata)>`

List all available sessions.

Suggestion: Update to match the API signature and document the new filtering capability:

##### `ListSessionsAsync(SessionListFilter? filter = null): Task(List<SessionMetadata)>`

List all available sessions. Optionally filter by working directory, git root, repository, or branch.

Note: The Go and Node.js READMEs were already updated with examples of the new filtering functionality. Python's README doesn't document list_sessions at all (no change from baseline).

🧪 Testing Note

Tests were updated for Node.js and Go:

  • Node.js: Added test for context field (currently skipped with TODO comment)
  • Go: Updated existing ListSessions calls to pass nil filter parameter

Python and .NET tests continue to work without changes since the filter parameter is optional.


Summary: This PR maintains excellent cross-SDK consistency. The only suggestion is to update the .NET README to reflect the new filter parameter. Great work! 👍

AI generated by SDK Consistency Review Agent

- Export SessionContext from index.ts
- Use SessionContext type instead of inline redeclaration in client.ts
- Update listSessions JSDoc with filter param docs and examples
- Update README with filter signature
- Update session-persistence docs to mention context field
@github-actions
Copy link

✅ Cross-SDK Consistency Review: PASSED

I've reviewed this PR for consistency across all four SDK implementations (Node.js/TypeScript, Python, Go, and .NET), and I'm pleased to report that this PR maintains excellent cross-SDK consistency.

What This PR Adds

This PR adds session context information and filtering capabilities to listSessions() across all SDKs:

  1. New SessionContext type - Captures working directory context:

    • cwd: Working directory where session was created
    • gitRoot: Git repository root (optional)
    • repository: GitHub repo in owner/repo format (optional)
    • branch: Current git branch (optional)
  2. New SessionListFilter type - Optional filter for listing sessions by:

    • cwd, gitRoot, repository, or branch
  3. Updated SessionMetadata - Now includes optional context field

  4. Updated listSessions() method - Now accepts optional filter parameter

Consistency Analysis

TypeScript (Node.js):

  • SessionContext interface defined ✓
  • SessionListFilter interface defined ✓
  • SessionMetadata.context?: SessionContext
  • listSessions(filter?: SessionListFilter)
  • Types exported in index.ts

Python:

  • SessionContext dataclass with proper serialization ✓
  • SessionListFilter dataclass with proper serialization ✓
  • SessionMetadata.context field ✓
  • list_sessions(filter: SessionListFilter | None = None)
  • Types exported in __init__.py

Go:

  • SessionContext struct with JSON tags ✓
  • SessionListFilter struct with JSON tags ✓
  • SessionMetadata.Context *SessionContext
  • ListSessions(ctx context.Context, filter *SessionListFilter)
  • Updated README ✓

.NET (C#):

  • SessionContext class ✓
  • SessionListFilter class ✓
  • SessionMetadata.Context property ✓
  • ListSessionsAsync(SessionListFilter? filter = null)
  • Proper JSON serialization attributes ✓

API Design Consistency

The PR correctly follows language-specific naming conventions:

  • TypeScript: camelCase (e.g., listSessions, gitRoot)
  • Python: snake_case (e.g., list_sessions) but preserves API field names like gitRoot for JSON compatibility
  • Go: PascalCase for exported types (e.g., ListSessions, GitRoot)
  • .NET: PascalCase (e.g., ListSessionsAsync, GitRoot)

All four SDKs maintain semantic equivalence in:

  • Method signatures (optional filter parameter)
  • Return types (list/array of SessionMetadata)
  • Filter field names (consistent JSON property names)
  • Documentation and examples

Testing

Tests have been updated consistently:

  • Node.js: Added test for context field (currently skipped pending CLI changes)
  • Go: Updated all ListSessions calls to include nil filter parameter
  • Documentation: Updated guides showing filter usage

Recommendation

This PR is ready to merge from a cross-SDK consistency perspective. The implementation demonstrates excellent attention to maintaining feature parity and consistent API design across all four language implementations.

Great work on maintaining consistency! 🎉

AI generated by SDK Consistency Review Agent

@jmoseley
Copy link
Contributor Author

@IeuanWalker yup that is included in this change now.

@jmoseley jmoseley changed the title Expose session context in listSessions and add filtering Expose session context, add filtering, and context_changed event Feb 12, 2026
- Node.js: Unskip context field test (runtime PR now merged)
- Python: Add context assertions to existing list_sessions test
- Go: Add context assertions to existing ListSessions test
- .NET: Add new test for listing sessions with context
Comment on lines +387 to +393
foreach (var s in sessions)
{
if (s.Context != null)
{
Assert.False(string.IsNullOrEmpty(s.Context.Cwd), "Expected context.Cwd to be non-empty when context is present");
}
}
@github-actions
Copy link

✅ Cross-SDK Consistency Review: PASS

Great work maintaining consistency across all four SDK implementations! This PR successfully implements session context exposure, filtering, and the session.context_changed event type uniformly across Node.js, Python, Go, and .NET.

What I Verified

Types & API Consistency:

  • SessionContext implemented in all SDKs with proper naming conventions (camelCase/snake_case/PascalCase)
  • SessionListFilter implemented consistently across all SDKs
  • SessionMetadata.context field added to all SDKs
  • listSessions()/list_sessions()/ListSessions() updated to accept optional filter parameter
  • session.context_changed event type defined in all generated session event files

Testing:

  • ✅ All SDKs include tests verifying the context field is populated
  • 💡 Note: The filter parameter is defined but not yet tested with actual filter values (e.g., filtering by repository). This is acceptable for initial implementation.
  • 💡 Note: The session.context_changed event is defined but not E2E tested (likely handled by runtime).

Language Conventions:

  • ✅ Node.js uses camelCase (gitRoot, listSessions)
  • ✅ Python uses snake_case (git_root, list_sessions)
  • ✅ Go uses PascalCase for exports + camelCase JSON tags (GitRoot, ListSessions)
  • ✅ .NET uses PascalCase (GitRoot, ListSessionsAsync)

Conclusion

This PR maintains excellent cross-SDK consistency. All four language implementations provide equivalent functionality with appropriate naming conventions. No inconsistencies detected. 🎉

AI generated by SDK Consistency Review Agent

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.

Exposing the working dir of a session Expose cwd/Repo information of a session

2 participants