This commit is contained in:
hupenglong1
2026-05-20 15:04:19 +08:00
parent c4b935692c
commit 1a94cec822
27 changed files with 4831 additions and 1693 deletions
+40
View File
@@ -774,6 +774,20 @@ print(f"{'appended' if MODE == 'a' else 'wrote'} {target} ({len(content)} chars)
def resolve_workspace_path(self, raw_path: str) -> str:
value = raw_path.strip() or '.'
# 系统提示里给的"当前会话目录"通常是本地后端的绝对/相对路径,例如
# `.port_sessions/accounts/<acc>/sessions/<sid>/input` 或
# `/home/mi/.../.port_sessions/accounts/<acc>/sessions/<sid>/output/foo.csv`。
# 远端 Jupyter 没这套目录结构。识别这种 pattern 后,把 input/output/
# scratchpad bucket 映射到远端 workspace 的同名目录。
bucket_match = self._match_local_session_bucket(value)
if bucket_match is not None:
bucket, rest = bucket_match
tail = f'/{rest}' if rest else ''
return normalize_posix_path(
f'{self.binding.workspace_cwd}/{bucket}{tail}'
)
if value.startswith('/'):
return normalize_posix_path(value)
path = PurePosixPath(value)
@@ -787,8 +801,34 @@ print(f"{'appended' if MODE == 'a' else 'wrote'} {target} ({len(content)} chars)
if path.parts and path.parts[0] in {'scratchpad', 'scratch'}:
tail = PurePosixPath(*path.parts[1:]) if len(path.parts) > 1 else PurePosixPath()
return normalize_posix_path(f'{self.binding.workspace_cwd}/scratchpad/{tail}')
if path.parts and path.parts[0] in {'input', 'inputs'}:
tail = PurePosixPath(*path.parts[1:]) if len(path.parts) > 1 else PurePosixPath()
return normalize_posix_path(f'{self.binding.workspace_cwd}/input/{tail}')
return normalize_posix_path(f'{self.binding.workspace_cwd}/{value}')
_LOCAL_SESSION_BUCKET_RE = re.compile(
r'(?:^|/)\.port_sessions/accounts/[^/]+/sessions/[^/]+/'
r'(?P<bucket>input|inputs|output|outputs|scratchpad|scratch)'
r'(?:/(?P<rest>.*))?$'
)
@classmethod
def _match_local_session_bucket(cls, raw: str) -> tuple[str, str] | None:
m = cls._LOCAL_SESSION_BUCKET_RE.search(raw)
if not m:
return None
bucket = m.group('bucket')
normalized = {
'input': 'input',
'inputs': 'input',
'output': 'output',
'outputs': 'output',
'scratchpad': 'scratchpad',
'scratch': 'scratchpad',
}[bucket]
rest = m.group('rest') or ''
return normalized, rest
def _remote_env_prefix(self) -> str:
exports = {
'ZK_AGENT_WORKSPACE': self.binding.workspace_cwd,