fix(sdk): tighten slash command observation and regression coverage

This commit is contained in:
LogosVeritas committed 2026-10-25 21:55:28 +08:00
1 parent 9c3971618a
commit f7379ef366
29 files changed
+346 -199

No files matched your search

+2 -2
View File
@@ -15,8 +15,8 @@
en: 3471642d8444d0e9
zh: 7831f28295a6e68a
/python-sdk-example/review-a-plan:
en: bd0da5138a033eba
zh: f291c3ae8967e936
en: 46758c022608af0f
zh: 09b5a59176c11176
/python-sdk-example/run-a-goal:
en: ae73e9fd9d402047
zh: f9694bc6a6e12929
+1 -1
View File
@@ -68,7 +68,7 @@ python python/sdk/examples/plan.py \
"Plan the requested change and present it for review."
```
The native plan is carried in `exit_plan_mode`, not written to a workspace document. Permissions remain workspace-write. Dismissal leaves plan mode active and ends the current turn. The example waits through `session/wait`; its question callback is independent of the protocol reader.
The native plan is carried in `exit_plan_mode`, not written to a workspace document. Permissions remain workspace-write. Dismissal leaves plan mode active and ends the current turn. The example waits through `session/wait` and rejects truncated or failed root turns; its question callback is independent of the protocol reader.
<a id="run-a-goal"></a>
## Run a goal
+1 -1
View File
@@ -68,7 +68,7 @@ python python/sdk/examples/plan.py \
"Plan the requested change and present it for review."
```
原生计划通过 `exit_plan_mode` 携带,而不是写入工作区文档。权限仍为 workspace-write。关闭审查会保留计划模式并结束当前轮次。示例通过 `session/wait` 等待,问答回调独立于协议读取线程。
原生计划通过 `exit_plan_mode` 携带,而不是写入工作区文档。权限仍为 workspace-write。关闭审查会保留计划模式并结束当前轮次。示例通过 `session/wait` 等待,并报告根轮次截断或失败;问答回调独立于协议读取线程。
<a id="run-a-goal"></a>
## 运行目标
+8 -3
View File
@@ -40,14 +40,19 @@ def review(request: UserQuestionRequest, cancelled: threading.Event) -> dict:
return {"cancelled": True}
def display(notification: Notification) -> None:
"""Print completed assistant text while the Session runs."""
def display(notification: Notification, session_id: str) -> None:
"""Print assistant text and report an unsuccessful root Session turn."""
if notification.method == "session.event":
event = notification.payload.get("event")
if isinstance(event, dict) and event.get("type") == "assistant/message":
text = final_response([event])
if text:
print(text)
elif (isinstance(event, dict) and event.get("type") == "turn/end"
and notification.payload.get("sessionId") == session_id):
reason = event["data"]["reason"]
if reason["kind"] != "completed":
raise RuntimeError(f"Agent turn ended: {reason}")
def main() -> None:
@@ -75,7 +80,7 @@ def main() -> None:
raise RuntimeError(message.result.text)
harness.client.request(
"session/wait", {"sessionId": session.id}, response_model=WaitResult,
on_notification=display, notification_subscription=notifications,
on_notification=lambda notice: display(notice, session.id), notification_subscription=notifications,
)