Merge branch 'feat/session-workspace-root' into feat/session-workspace-root-consumers
Brings master (23c1d884226) through the parent branch. The SDK client README keeps master's resume-permission paragraph and this branch's statement that `setWorkingDirectory` moves the `workspace-write` boundary.
This commit is contained in:
commit
cb0ebcc032
54 files changed
+1103
-155
No files matched your search
@@ -3,7 +3,7 @@ from .client import HarnessClient, HarnessConfig, UserQuestionHandler
|
||||
from .errors import SdkProtocolError
|
||||
from .models import (
|
||||
ApprovalRequestParams, ApprovalRequestResult, IncomingRequest, InitializeResponse,
|
||||
JsonObject, Notification, ServerInfo, UserQuestionAnswer, UserQuestionAnswerItem, UserQuestionRequest,
|
||||
JsonObject, Notification, ResumeSessionOptions, ServerInfo, UserQuestionAnswer, UserQuestionAnswerItem, UserQuestionRequest,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -11,6 +11,7 @@ __all__ = [
|
||||
"DeepSeekHarnessConfig",
|
||||
"Session",
|
||||
"RunResult",
|
||||
"ResumeSessionOptions",
|
||||
"HarnessClient",
|
||||
"HarnessConfig",
|
||||
"UserQuestionHandler",
|
||||
|
||||
@@ -7,7 +7,7 @@ from typing import Callable, Literal
|
||||
|
||||
from .client import HarnessClient, HarnessConfig, UserQuestionHandler
|
||||
from .errors import SdkProtocolError
|
||||
from .models import CommandExecution, JsonObject, Notification
|
||||
from .models import CommandExecution, JsonObject, Notification, ResumeSessionOptions
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -176,13 +176,15 @@ class DeepSeekHarness:
|
||||
self.start()
|
||||
return Session(self, session_id or f"session-{uuid.uuid4().hex}")
|
||||
|
||||
def resume_session(self, session_id: str) -> "Session":
|
||||
"""Restore persisted history from the configured Harness home without sending input.
|
||||
def resume_session(self, session_id: str, options: ResumeSessionOptions | None = None) -> "Session":
|
||||
"""Restore persisted history without sending input.
|
||||
|
||||
Omit options to retain saved permissions, or set options["permission_mode"] to a configured preset
|
||||
to persist before resumed execution. Invalid option keys raise TypeError. Unsupported presets or profiles raise.
|
||||
Missing, unreadable, incompatible, or occupied sessions raise instead of creating a new session.
|
||||
"""
|
||||
self.start()
|
||||
self._client.resume_session(session_id)
|
||||
self._client.resume_session(session_id, options)
|
||||
return Session(self, session_id)
|
||||
|
||||
def run(
|
||||
|
||||
@@ -15,7 +15,7 @@ from typing import Callable, TypeAlias, TypeVar
|
||||
from pydantic import BaseModel, ValidationError
|
||||
|
||||
from .errors import JsonRpcError, SdkProtocolError, TransportClosedError
|
||||
from .models import CommandExecution, IncomingRequest, InitializeResponse, JsonObject, JsonValue, Notification, UserQuestionAnswer, UserQuestionRequest
|
||||
from .models import CommandExecution, IncomingRequest, InitializeResponse, JsonObject, JsonValue, Notification, ResumeSessionOptions, UserQuestionAnswer, UserQuestionRequest
|
||||
|
||||
ModelT = TypeVar("ModelT", bound=BaseModel)
|
||||
NotificationFilter: TypeAlias = Callable[[Notification], bool]
|
||||
@@ -217,11 +217,20 @@ class HarnessClient:
|
||||
)
|
||||
return response.messageId
|
||||
|
||||
def resume_session(self, session_id: str) -> None:
|
||||
"""Restore a persisted session without sending a prompt; propagate restoration failures."""
|
||||
def resume_session(self, session_id: str, options: ResumeSessionOptions | None = None) -> None:
|
||||
"""Restore history; an explicit permission preset replaces saved permissions before execution."""
|
||||
params: JsonObject = {"sessionId": session_id}
|
||||
if options is not None:
|
||||
if not isinstance(options, dict):
|
||||
raise TypeError("resume_session options must be a dict or None")
|
||||
for key in options:
|
||||
if key != "permission_mode":
|
||||
raise TypeError(f"unknown resume_session option {key!r}; expected 'permission_mode'")
|
||||
if "permission_mode" in options:
|
||||
params["permissionMode"] = options["permission_mode"]
|
||||
self.request(
|
||||
"session/resume",
|
||||
{"sessionId": session_id},
|
||||
params,
|
||||
response_model=_EmptyResponse,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Annotated, Literal, TypeAlias
|
||||
from typing import Annotated, Literal, TypeAlias, TypedDict
|
||||
|
||||
from pydantic import BaseModel, Field, JsonValue as PydanticJsonValue, field_validator
|
||||
|
||||
@@ -10,6 +10,12 @@ JsonValue: TypeAlias = JsonScalar | dict[str, "JsonValue"] | list["JsonValue"]
|
||||
JsonObject: TypeAlias = dict[str, JsonValue]
|
||||
|
||||
|
||||
class ResumeSessionOptions(TypedDict, total=False):
|
||||
"""Options applied before a restored session resumes execution."""
|
||||
|
||||
permission_mode: str
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Notification:
|
||||
method: str
|
||||
|
||||
Reference in new issue
Block a user