Skip to content

Conversation

@jmoseley
Copy link
Contributor

@jmoseley jmoseley commented Feb 10, 2026

Summary

Exposes the working directory and repository context for sessions via listSessions(), and adds optional filtering support.

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.

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' });

// Filter by cwd
const sessions = await client.listSessions({ cwd: '/path/to/project' });

Changes

  • Added SessionContext type to types.ts
  • Added SessionListFilter type to types.ts
  • Updated SessionMetadata to include context field
  • Updated listSessions() to accept optional filter and return context
  • Updated documentation and cookbook examples
  • Added tests

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.

Comment on lines 750 to +758
* }
* ```
*/
async listSessions(): Promise<SessionMetadata[]> {
async listSessions(filter?: SessionListFilter): Promise<SessionMetadata[]> {
if (!this.connection) {
throw new Error("Client not connected");
}

const response = await this.connection.sendRequest("session.list", {});
const response = await this.connection.sendRequest("session.list", { filter });
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Now that listSessions accepts an optional filter, the method-level docs should be updated to document that parameter and include a filtered example (e.g. by repository or cwd). Otherwise IDE docs and generated docs will be misleading.

Copilot uses AI. Check for mistakes.
SessionEventHandler,
SessionEventPayload,
SessionEventType,
SessionListFilter,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

SessionMetadata.context is typed as SessionContext, but SessionContext itself isn’t re-exported from the package entrypoint. This makes it awkward for consumers to reference the type directly (and the README now documents it). Re-export SessionContext alongside SessionListFilter in this file.

Suggested change
SessionListFilter,
SessionListFilter,
SessionContext,

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +114
##### `listSessions(): Promise<SessionMetadata[]>`

List all available sessions.

**SessionMetadata:**
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The README still documents listSessions(): Promise<SessionMetadata[]>, but the implementation now accepts an optional filter. Update the method signature docs and add a short description/example for the SessionListFilter parameter so the docs match the API.

Copilot uses AI. Check for mistakes.
Comment on lines 759 to +771
const { sessions } = response as {
sessions: Array<{
sessionId: string;
startTime: string;
modifiedTime: string;
summary?: string;
isRemote: boolean;
context?: {
cwd: string;
gitRoot?: string;
repository?: string;
branch?: string;
};
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

SessionContext is re-declared inline in the response cast, which can drift from the exported SessionContext interface over time. Reuse SessionContext in the response typing (e.g., context?: SessionContext) to keep a single source of truth.

Copilot uses AI. Check for mistakes.
Comment on lines +753 to +758
async listSessions(filter?: SessionListFilter): Promise<SessionMetadata[]> {
if (!this.connection) {
throw new Error("Client not connected");
}

const response = await this.connection.sendRequest("session.list", {});
const response = await this.connection.sendRequest("session.list", { filter });
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Filtering support was added to listSessions(filter?: SessionListFilter), but there’s no test exercising the filter behavior (only the presence of context). Add an E2E test that creates at least two sessions with different workingDirectory/repo context (or uses a filterable field) and asserts listSessions({ ... }) returns the expected subset.

Copilot uses AI. Check for mistakes.
Comment on lines 73 to 74
console.log(` Repository: ${session.context.repository}`);
console.log(` Branch: ${session.context.branch}`);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This example prints Repository: / Branch: even when those fields are undefined, which will produce noisy output like Repository: undefined. Consider printing those lines only when the value is present (or using a fallback like "(none)").

Suggested change
console.log(` Repository: ${session.context.repository}`);
console.log(` Branch: ${session.context.branch}`);
if (session.context.repository) {
console.log(` Repository: ${session.context.repository}`);
}
if (session.context.branch) {
console.log(` Branch: ${session.context.branch}`);
}

Copilot uses AI. Check for mistakes.
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?

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