Add task sync push milestone
Tasks could start from host content in 2.2.0, but there was still no post-create path to update a live workspace from the host. This change adds the next host-to-task step so repeated fix or review loops do not require recreating the task for every local change. Add task sync push across the CLI, Python SDK, and MCP server, reusing the existing safe archive import path from seeded task creation instead of introducing a second transfer stack. The implementation keeps sync separate from workspace_seed metadata, validates destinations under /workspace, and documents the current non-atomic recovery path as delete-and-recreate. Validation: - uv lock - UV_CACHE_DIR=.uv-cache uv run pytest --no-cov tests/test_cli.py tests/test_vm_manager.py tests/test_api.py tests/test_server.py tests/test_public_contract.py - UV_CACHE_DIR=.uv-cache make check - UV_CACHE_DIR=.uv-cache make dist-check - real guest-backed smoke: task create --source-path, task sync push, task exec to verify both files, task delete
This commit is contained in:
parent
aa886b346e
commit
9e11dcf9ab
19 changed files with 461 additions and 41 deletions
|
|
@ -197,6 +197,23 @@ def _print_task_exec_human(payload: dict[str, Any]) -> None:
|
|||
)
|
||||
|
||||
|
||||
def _print_task_sync_human(payload: dict[str, Any]) -> None:
|
||||
workspace_sync = payload.get("workspace_sync")
|
||||
if not isinstance(workspace_sync, dict):
|
||||
print(f"Synced task: {str(payload.get('task_id', 'unknown'))}")
|
||||
return
|
||||
print(
|
||||
"[task-sync] "
|
||||
f"task_id={str(payload.get('task_id', 'unknown'))} "
|
||||
f"mode={str(workspace_sync.get('mode', 'unknown'))} "
|
||||
f"source={str(workspace_sync.get('source_path', 'unknown'))} "
|
||||
f"destination={str(workspace_sync.get('destination', TASK_WORKSPACE_GUEST_PATH))} "
|
||||
f"entry_count={int(workspace_sync.get('entry_count', 0))} "
|
||||
f"bytes_written={int(workspace_sync.get('bytes_written', 0))} "
|
||||
f"execution_mode={str(payload.get('execution_mode', 'unknown'))}"
|
||||
)
|
||||
|
||||
|
||||
def _print_task_logs_human(payload: dict[str, Any]) -> None:
|
||||
entries = payload.get("entries")
|
||||
if not isinstance(entries, list) or not entries:
|
||||
|
|
@ -250,7 +267,8 @@ def _build_parser() -> argparse.ArgumentParser:
|
|||
pyro run debian:12 -- git --version
|
||||
|
||||
Need repeated commands in one workspace after that?
|
||||
pyro task create debian:12
|
||||
pyro task create debian:12 --source-path ./repo
|
||||
pyro task sync push TASK_ID ./changes
|
||||
|
||||
Use `pyro mcp serve` only after the CLI validation path works.
|
||||
"""
|
||||
|
|
@ -456,6 +474,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|||
"""
|
||||
Examples:
|
||||
pyro task create debian:12 --source-path ./repo
|
||||
pyro task sync push TASK_ID ./repo --dest src
|
||||
pyro task exec TASK_ID -- sh -lc 'printf "hello\\n" > note.txt'
|
||||
pyro task logs TASK_ID
|
||||
"""
|
||||
|
|
@ -472,6 +491,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|||
Examples:
|
||||
pyro task create debian:12
|
||||
pyro task create debian:12 --source-path ./repo
|
||||
pyro task sync push TASK_ID ./changes
|
||||
"""
|
||||
),
|
||||
formatter_class=_HelpFormatter,
|
||||
|
|
@ -552,6 +572,56 @@ def _build_parser() -> argparse.ArgumentParser:
|
|||
"for example `pyro task exec TASK_ID -- cat note.txt`."
|
||||
),
|
||||
)
|
||||
task_sync_parser = task_subparsers.add_parser(
|
||||
"sync",
|
||||
help="Push host content into a started task workspace.",
|
||||
description=(
|
||||
"Push host directory or archive content into `/workspace` for an existing "
|
||||
"started task."
|
||||
),
|
||||
epilog=dedent(
|
||||
"""
|
||||
Examples:
|
||||
pyro task sync push TASK_ID ./repo
|
||||
pyro task sync push TASK_ID ./patches --dest src
|
||||
|
||||
Sync is non-atomic. If a sync fails partway through, delete and recreate the task.
|
||||
"""
|
||||
),
|
||||
formatter_class=_HelpFormatter,
|
||||
)
|
||||
task_sync_subparsers = task_sync_parser.add_subparsers(
|
||||
dest="task_sync_command",
|
||||
required=True,
|
||||
metavar="SYNC",
|
||||
)
|
||||
task_sync_push_parser = task_sync_subparsers.add_parser(
|
||||
"push",
|
||||
help="Push one host directory or archive into a started task.",
|
||||
description="Import host content into `/workspace` or a subdirectory of it.",
|
||||
epilog="Example:\n pyro task sync push TASK_ID ./repo --dest src",
|
||||
formatter_class=_HelpFormatter,
|
||||
)
|
||||
task_sync_push_parser.add_argument(
|
||||
"task_id",
|
||||
metavar="TASK_ID",
|
||||
help="Persistent task identifier.",
|
||||
)
|
||||
task_sync_push_parser.add_argument(
|
||||
"source_path",
|
||||
metavar="SOURCE_PATH",
|
||||
help="Host directory or .tar/.tar.gz/.tgz archive to push into the task workspace.",
|
||||
)
|
||||
task_sync_push_parser.add_argument(
|
||||
"--dest",
|
||||
default=TASK_WORKSPACE_GUEST_PATH,
|
||||
help="Workspace destination path. Relative values resolve inside `/workspace`.",
|
||||
)
|
||||
task_sync_push_parser.add_argument(
|
||||
"--json",
|
||||
action="store_true",
|
||||
help="Print structured JSON instead of human-readable output.",
|
||||
)
|
||||
task_status_parser = task_subparsers.add_parser(
|
||||
"status",
|
||||
help="Inspect one task workspace.",
|
||||
|
|
@ -821,6 +891,30 @@ def main() -> None:
|
|||
if exit_code != 0:
|
||||
raise SystemExit(exit_code)
|
||||
return
|
||||
if args.task_command == "sync" and args.task_sync_command == "push":
|
||||
if bool(args.json):
|
||||
try:
|
||||
payload = pyro.push_task_sync(
|
||||
args.task_id,
|
||||
args.source_path,
|
||||
dest=args.dest,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
_print_json({"ok": False, "error": str(exc)})
|
||||
raise SystemExit(1) from exc
|
||||
_print_json(payload)
|
||||
else:
|
||||
try:
|
||||
payload = pyro.push_task_sync(
|
||||
args.task_id,
|
||||
args.source_path,
|
||||
dest=args.dest,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"[error] {exc}", file=sys.stderr, flush=True)
|
||||
raise SystemExit(1) from exc
|
||||
_print_task_sync_human(payload)
|
||||
return
|
||||
if args.task_command == "status":
|
||||
payload = pyro.status_task(args.task_id)
|
||||
if bool(args.json):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue