diff --git a/CHANGELOG.md b/CHANGELOG.md index 588363d..26c9c8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This change ## [Unreleased] +### Added (v0.1.30 sync) +- `disconnect!` function as the preferred way to close a session. Same semantics as `destroy!` — sends `session.destroy` RPC and releases in-memory resources while preserving disk state for resumption (upstream PR #599). + +### Changed (v0.1.30 sync) +- `destroy!` is now deprecated and delegates to `disconnect!`. Matches upstream Node.js SDK where `destroy()` was deprecated in favor of `disconnect()` (upstream PR #599). +- `with-session` and `with-client-session` macros now call `disconnect!` instead of `destroy!` in their cleanup forms. +- `stop!` in client now internally calls `session/disconnect!` instead of `session/destroy!`. + ## [0.1.30.0] - 2026-03-04 ### Added (v0.1.30 sync) diff --git a/doc/reference/API.md b/doc/reference/API.md index 1b92942..7a93b60 100644 --- a/doc/reference/API.md +++ b/doc/reference/API.md @@ -780,12 +780,22 @@ Alias for `switch-model!`, matching the upstream SDK's `setModel()` API. ;; After: claude-sonnet-4.5 ``` +#### `disconnect!` + +```clojure +(copilot/disconnect! session) +``` + +Disconnect the session and free resources. Session data on disk is preserved for later resumption via `resume-session`. Use `delete-session!` to permanently remove session data from disk. + #### `destroy!` ```clojure (copilot/destroy! session) ``` +**Deprecated**: Use `disconnect!` instead. + Destroy the session and free resources. #### `session-id` diff --git a/doc/style.md b/doc/style.md index f5884e9..5c1603a 100644 --- a/doc/style.md +++ b/doc/style.md @@ -50,7 +50,7 @@ Short paragraphs (1–3 sentences). Use code blocks liberally. - Use `h` as the alias for `github.copilot-sdk.helpers` - Use `session` as the alias for `github.copilot-sdk.session` - Prefer `def` over `let` in top-level examples for clarity -- Include cleanup (`stop!`, `destroy!`) in lifecycle examples +- Include cleanup (`stop!`, `disconnect!`) in lifecycle examples ### What to Avoid diff --git a/src/github/copilot_sdk.clj b/src/github/copilot_sdk.clj index 457aea0..04d3671 100644 --- a/src/github/copilot_sdk.clj +++ b/src/github/copilot_sdk.clj @@ -409,7 +409,7 @@ (client/keyword) (:events result))))) -(defn destroy! - "Destroy the session and free resources. - Can be called with either a CopilotSession handle or (client, session-id)." +(defn disconnect! + "Disconnect the session and free resources. + Session data on disk is preserved for later resumption via resume-session. + Can be called with either a CopilotSession handle or (client, session-id). + + This is the preferred way to close a session. Use delete-session! in + client to permanently remove session data from disk." ([session] - (destroy! (:client session) (:session-id session))) + (disconnect! (:client session) (:session-id session))) ([client session-id] - (log/debug "Destroying session: " session-id) + (log/debug "Disconnecting session: " session-id) (when-not (:destroyed? (session-state client session-id)) (let [conn (connection-io client)] ;; Try to notify server, but don't block forever if connection is broken @@ -621,9 +625,20 @@ ;; Close the event source channel - this propagates to all tapped channels (when-let [{:keys [event-chan]} (session-io client session-id)] (close! event-chan)) - (log/debug "Session destroyed: " session-id) + (log/debug "Session disconnected: " session-id) nil)))) +(defn destroy! + "Destroy the session and free resources. + Can be called with either a CopilotSession handle or (client, session-id). + + Deprecated: Use disconnect! instead. This function will be removed in a + future release. disconnect! is the preferred method for closing sessions." + ([session] + (disconnect! session)) + ([client session-id] + (disconnect! client session-id))) + (defn events "Get the event mult for this session. Use tap to subscribe: