Skip to content

Commit c5a8b2d

Browse files
authored
Merge pull request #129 from copilot-community-sdk/copilot/upstream-sync-new-commits
[upstream-sync] Port session context, filtering, and context_changed event (e40d57c)
2 parents 430afc9 + 74cd8e4 commit c5a8b2d

16 files changed

Lines changed: 465 additions & 10 deletions

.github/scripts/upstream-sync/merge-upstream-diff.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# ──────────────────────────────────────────────────────────────
1818
set -euo pipefail
1919

20-
ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
20+
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
2121
ENV_FILE="$ROOT_DIR/.merge-env"
2222

2323
if [[ ! -f "$ENV_FILE" ]]; then

.github/scripts/upstream-sync/merge-upstream-finish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# ──────────────────────────────────────────────────────────────
1616
set -euo pipefail
1717

18-
ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
18+
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
1919
ENV_FILE="$ROOT_DIR/.merge-env"
2020

2121
if [[ ! -f "$ENV_FILE" ]]; then

.github/scripts/upstream-sync/merge-upstream-start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# ──────────────────────────────────────────────────────────────
1515
set -euo pipefail
1616

17-
ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
17+
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
1818
cd "$ROOT_DIR"
1919

2020
UPSTREAM_REPO="https://github.com/github/copilot-sdk.git"

.lastmerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4dc562951a51097618a69a1837f7af06c73d1113
1+
e40d57c86e18b495722adbf42045288c03924342

CHANGELOG.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,49 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
88
99
## [Unreleased]
1010

11-
> **Upstream sync:** [`github/copilot-sdk@05e3c46`](https://github.com/github/copilot-sdk/commit/05e3c46c8c23130c9c064dc43d00ec78f7a75eab)
11+
> **Upstream sync:** [`github/copilot-sdk@e40d57c`](https://github.com/github/copilot-sdk/commit/e40d57c86e18b495722adbf42045288c03924342)
12+
13+
### Added
14+
15+
#### Session Context and Filtering
16+
17+
Added session context tracking and filtering capabilities to help manage multiple Copilot sessions across different repositories and working directories.
18+
19+
**New Classes:**
20+
- `SessionContext` - Represents working directory context (cwd, gitRoot, repository, branch) with fluent setters
21+
- `SessionListFilter` - Filter sessions by context fields (extends SessionContext)
22+
- `SessionContextChangedEvent` - Event fired when working directory context changes between turns
23+
24+
**Updated APIs:**
25+
- `SessionMetadata.getContext()` - Returns optional context information for persisted sessions
26+
- `CopilotClient.listSessions(SessionListFilter)` - New overload to filter sessions by context criteria
27+
28+
**Example:**
29+
```java
30+
// List sessions for a specific repository
31+
var filter = new SessionListFilter()
32+
.setRepository("owner/repo")
33+
.setBranch("main");
34+
var sessions = client.listSessions(filter).get();
35+
36+
// Access context information
37+
for (var session : sessions) {
38+
var ctx = session.getContext();
39+
if (ctx != null) {
40+
System.out.println("CWD: " + ctx.getCwd());
41+
System.out.println("Repo: " + ctx.getRepository());
42+
}
43+
}
44+
45+
// Listen for context changes
46+
session.on(SessionContextChangedEvent.class, event -> {
47+
SessionContext newContext = event.getData();
48+
System.out.println("Working directory changed to: " + newContext.getCwd());
49+
});
50+
```
51+
52+
**Requirements:**
53+
- GitHub Copilot CLI 0.0.409 or later
1254

1355
## [1.0.8] - 2026-02-08
1456

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Java SDK for programmatic control of GitHub Copilot CLI, enabling you to build A
2525
### Requirements
2626

2727
- Java 17 or later
28-
- GitHub Copilot CLI 0.0.406 or later installed and in PATH (or provide custom `cliPath`)
28+
- GitHub Copilot CLI 0.0.409 or later installed and in PATH (or provide custom `cliPath`)
2929

3030
### Maven
3131

src/main/java/com/github/copilot/sdk/CopilotClient.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.github.copilot.sdk.json.ResumeSessionResponse;
3131
import com.github.copilot.sdk.json.SessionConfig;
3232
import com.github.copilot.sdk.json.SessionLifecycleHandler;
33+
import com.github.copilot.sdk.json.SessionListFilter;
3334
import com.github.copilot.sdk.json.SessionMetadata;
3435

3536
/**
@@ -474,9 +475,41 @@ public CompletableFuture<Void> deleteSession(String sessionId) {
474475
* @see #resumeSession(String)
475476
*/
476477
public CompletableFuture<List<SessionMetadata>> listSessions() {
477-
return ensureConnected()
478-
.thenCompose(connection -> connection.rpc.invoke("session.list", Map.of(), ListSessionsResponse.class)
479-
.thenApply(ListSessionsResponse::sessions));
478+
return listSessions(null);
479+
}
480+
481+
/**
482+
* Lists all available sessions with optional filtering.
483+
* <p>
484+
* Returns metadata about all sessions that can be resumed, including their IDs,
485+
* start times, summaries, and context information. Use the filter parameter to
486+
* narrow down sessions by working directory, git repository, or branch.
487+
*
488+
* <h2>Example Usage</h2>
489+
*
490+
* <pre>{@code
491+
* // List all sessions
492+
* var allSessions = client.listSessions().get();
493+
*
494+
* // Filter by repository
495+
* var filter = new SessionListFilter().setRepository("owner/repo");
496+
* var repoSessions = client.listSessions(filter).get();
497+
* }</pre>
498+
*
499+
* @param filter
500+
* optional filter to narrow down sessions by context fields, or
501+
* {@code null} to list all sessions
502+
* @return a future that resolves with a list of session metadata
503+
* @see SessionMetadata
504+
* @see SessionListFilter
505+
* @see #resumeSession(String)
506+
*/
507+
public CompletableFuture<List<SessionMetadata>> listSessions(SessionListFilter filter) {
508+
return ensureConnected().thenCompose(connection -> {
509+
Map<String, Object> params = filter != null ? Map.of("filter", filter) : Map.of();
510+
return connection.rpc.invoke("session.list", params, ListSessionsResponse.class)
511+
.thenApply(ListSessionsResponse::sessions);
512+
});
480513
}
481514

482515
/**

src/main/java/com/github/copilot/sdk/events/AbstractSessionEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public abstract sealed class AbstractSessionEvent permits
5454
SessionStartEvent, SessionResumeEvent, SessionErrorEvent, SessionIdleEvent, SessionInfoEvent,
5555
SessionModelChangeEvent, SessionHandoffEvent, SessionTruncationEvent, SessionSnapshotRewindEvent,
5656
SessionUsageInfoEvent, SessionCompactionStartEvent, SessionCompactionCompleteEvent, SessionShutdownEvent,
57+
SessionContextChangedEvent,
5758
// Assistant events
5859
AssistantTurnStartEvent, AssistantIntentEvent, AssistantReasoningEvent, AssistantReasoningDeltaEvent,
5960
AssistantMessageEvent, AssistantMessageDeltaEvent, AssistantTurnEndEvent, AssistantUsageEvent, AbortEvent,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk.events;
6+
7+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
import com.github.copilot.sdk.json.SessionContext;
10+
11+
/**
12+
* Event: session.context_changed
13+
* <p>
14+
* Fired when the working directory context changes between turns. Contains the
15+
* updated context information including cwd, git root, repository, and branch.
16+
*
17+
* @since 1.0.0
18+
*/
19+
@JsonIgnoreProperties(ignoreUnknown = true)
20+
public final class SessionContextChangedEvent extends AbstractSessionEvent {
21+
22+
@JsonProperty("data")
23+
private SessionContext data;
24+
25+
@Override
26+
public String getType() {
27+
return "session.context_changed";
28+
}
29+
30+
public SessionContext getData() {
31+
return data;
32+
}
33+
34+
public void setData(SessionContext data) {
35+
this.data = data;
36+
}
37+
}

src/main/java/com/github/copilot/sdk/events/SessionEventParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class SessionEventParser {
6161
TYPE_MAP.put("session.usage_info", SessionUsageInfoEvent.class);
6262
TYPE_MAP.put("session.compaction_start", SessionCompactionStartEvent.class);
6363
TYPE_MAP.put("session.compaction_complete", SessionCompactionCompleteEvent.class);
64+
TYPE_MAP.put("session.context_changed", SessionContextChangedEvent.class);
6465
TYPE_MAP.put("user.message", UserMessageEvent.class);
6566
TYPE_MAP.put("pending_messages.modified", PendingMessagesModifiedEvent.class);
6667
TYPE_MAP.put("assistant.turn_start", AssistantTurnStartEvent.class);

0 commit comments

Comments
 (0)