feat(working-directory): add Session workspace roots with anchored relocation
Each Session now has three directories: the immutable original project in the header, the workspace root, and the current directory. `relocate` registers an entered checkout as an anchor through the optional `anchor` of one working-directory/change event, and the new workspaceRoot projection selects the longest anchor containing the current directory, so an ordinary cd inside a checkout moves only the cursor while entering another checkout moves the root with it. A log without anchors keeps the original project as its only anchor. Worktree creation relocates instead of setting the directory; a subagent that starts inside its parent's relocated root inherits that root; the SDK working-directory methods return the root beside cwd; the user context names the root while it differs from the current directory, and a notice that selects another root ends with it. Consumers keep reading the header or the current directory until a later change moves them. Refs #2658
This commit is contained in:
1 parent
27fb833732
commit
a71975faf6
78 files changed
+1009
-186
No files matched your search
@@ -24,5 +24,5 @@
|
||||
en: 979ad00fe498b2be
|
||||
zh: 4b656bd268292a13
|
||||
/deepseek-harness-python-sdk/results-and-notifications:
|
||||
en: 6b81899ea865ffd2
|
||||
zh: d9e326a3fb04e696
|
||||
en: 5ffe82e8d28abdbf
|
||||
zh: 94de9eeee9acb32f
|
||||
@@ -149,4 +149,4 @@ The selected home stores profiles, plugins, and every profile-owned durable reso
|
||||
|
||||
See the [Python tutorial](../../docs/user/guide/python-sdk.md), [runnable example](examples/README.md), and [runtime wheel reference](../sdk-runtime/README.md).
|
||||
|
||||
`Session.get_working_directory()` reads the effective working directory; `set_working_directory(path)` changes it and returns the validated absolute path. Both create an unknown Session without running a model turn. Relative paths use that Session's current directory. Origin metadata, permissions, and existing processes remain unchanged. The low-level client provides the same methods with a leading `session_id` argument.
|
||||
`Session.get_working_directory()` reads the effective working directory; `get_workspace_root()` reads the workspace root that directory is in; `set_working_directory(path)` changes the directory and returns the validated absolute path. Each creates an unknown Session without running a model turn. Relative paths use that Session's current directory. Origin metadata, permissions, and existing processes remain unchanged. The low-level client provides the same methods with a leading `session_id` argument.
|
||||
@@ -149,4 +149,4 @@ with DeepSeekHarness(
|
||||
|
||||
另见 [Python 教程](../../docs/user/guide/python-sdk.zh.md)、[可运行示例](examples/README.zh.md) 和 [运行时 wheel 包参考](../sdk-runtime/README.zh.md)。
|
||||
|
||||
`Session.get_working_directory()` 读取有效工作目录;`set_working_directory(path)` 修改目录并返回校验后的绝对路径。两者都可创建未知 Session,而不运行模型轮次。相对路径以该 Session 当前目录解析。起始目录元数据、权限与已有进程保持不变。底层客户端提供同名方法,并以 `session_id` 作为首个参数。
|
||||
`Session.get_working_directory()` 读取有效工作目录;`get_workspace_root()` 读取该目录所在的工作区根;`set_working_directory(path)` 修改目录并返回校验后的绝对路径。每个方法都可创建未知 Session,而不运行模型轮次。相对路径以该 Session 当前目录解析。起始目录元数据、权限与已有进程保持不变。底层客户端提供同名方法,并以 `session_id` 作为首个参数。
|
||||
@@ -206,6 +206,11 @@ class Session:
|
||||
self.harness.start()
|
||||
return self.harness.client.get_working_directory(self.id)
|
||||
|
||||
def get_workspace_root(self) -> str:
|
||||
"""Read the workspace root the effective directory is in, recovering a missing directory first."""
|
||||
self.harness.start()
|
||||
return self.harness.client.get_workspace_root(self.id)
|
||||
|
||||
def set_working_directory(self, path: str) -> str:
|
||||
"""Change the effective directory while existing processes retain their own directories."""
|
||||
self.harness.start()
|
||||
|
||||
@@ -249,6 +249,15 @@ class HarnessClient:
|
||||
)
|
||||
return response.cwd
|
||||
|
||||
def get_workspace_root(self, session_id: str) -> str:
|
||||
"""Read the workspace root the effective directory is in, recovering a missing directory first."""
|
||||
response = self.request(
|
||||
"session/working-directory/get",
|
||||
{"sessionId": session_id},
|
||||
response_model=_WorkingDirectoryResponse,
|
||||
)
|
||||
return response.root
|
||||
|
||||
def set_working_directory(self, session_id: str, path: str) -> str:
|
||||
"""Enter an absolute or Session-relative directory without changing origin or permissions."""
|
||||
response = self.request(
|
||||
@@ -717,6 +726,7 @@ class _SessionPromptResponse(BaseModel):
|
||||
|
||||
class _WorkingDirectoryResponse(BaseModel):
|
||||
cwd: str
|
||||
root: str
|
||||
|
||||
|
||||
class _EmptyResponse(BaseModel):
|
||||
|
||||
@@ -31,13 +31,13 @@ for line in sys.stdin:
|
||||
print(json.dumps({'jsonrpc': '2.0', 'id': frame['id'], 'result': {}}), flush=True)
|
||||
break
|
||||
elif method == 'session/working-directory/get':
|
||||
result = {'cwd': directories.get(params['sessionId'], origin)}
|
||||
result = {'cwd': directories.get(params['sessionId'], origin), 'root': origin}
|
||||
elif method == 'session/working-directory/set':
|
||||
assert not os.path.isabs(params['path']), 'client must preserve relative paths'
|
||||
previous = directories.get(params['sessionId'], origin)
|
||||
current = os.path.normpath(os.path.join(previous, params['path']))
|
||||
directories[params['sessionId']] = current
|
||||
result = {'cwd': 7 if params['path'] == 'malformed' else current}
|
||||
result = {'cwd': 7 if params['path'] == 'malformed' else current, 'root': origin}
|
||||
else:
|
||||
raise AssertionError(method)
|
||||
print(json.dumps({'jsonrpc': '2.0', 'id': frame['id'], 'result': result}), flush=True)
|
||||
@@ -49,6 +49,7 @@ for line in sys.stdin:
|
||||
assert first.get_working_directory() == str(tmp_path)
|
||||
assert first.set_working_directory("child") == str(tmp_path / "child")
|
||||
assert first.get_working_directory() == str(tmp_path / "child")
|
||||
assert first.get_workspace_root() == str(tmp_path)
|
||||
assert second.get_working_directory() == str(tmp_path)
|
||||
with pytest.raises(ValidationError):
|
||||
second.set_working_directory("malformed")
|
||||
Reference in new issue
Block a user