refactor: store workspaces as {workspace_id}/{repo_name} for natural git clone layout

Working copies were stored as /data/working-copies/{repo_id}/{workspace_name}/,
so git clone was forced into a user-named directory. That meant the container
mount basename was the workspace name (e.g. main) instead of the repo name.

- Generate the workspace UUID before cloning and clone into
  /data/working-copies/{workspace_id}/ so git creates {repo_name}/ naturally
- Set workspace.path to /data/working-copies/{workspace_id}/{repo_name}/
- Update _migrate_clone_into_workspace() to use the same layout
- _get_repository_mount_name() now prefers workspace.path basename and only
  falls back to remote URL / repo.name for legacy repo-only instances
- Update unit tests to assert workspace path basename is used for mounts

Quality gates:
- pytest tests/unit: 219 passed
- ruff: clean on changed files
- mypy: clean on changed files
This commit is contained in:
Developer
2026-06-15 09:40:59 +00:00
parent 6e33e8e4e9
commit b26ed7c3e4
27 changed files with 176 additions and 87 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
dir: openspec
## role
Defines a living documentation methodology and configuration framework for managing software requirements, specifications, and task tracking within a Docker-based coding agent platform.
Defines the OpenSpec methodology and project configuration for managing software requirements, specifications, and task tracking as living documentation within a Docker-based coding agent management platform.
## parent
index: ./.pi-map.index.md
map: ./.pi-map.md
+1 -1
View File
@@ -2,7 +2,7 @@
dir: openspec/changes
## role
Manages change tracking and versioning for OpenAPI specification modifications
Tracks and manages specification changes and versioning history for the OpenAPI specification evolution.
## parent
index: openspec/.pi-map.index.md
map: openspec/.pi-map.md
@@ -2,7 +2,7 @@
dir: openspec/changes/fix-pi-container-mount-permissions
## role
This is a change request/bug fix package for resolving filesystem permission issues with pi-agent container repository mounts and npm updates.
Documents a bug fix for container filesystem permission issues affecting Pi agent repository mounts and npm operations in containerized development environments.
## parent
index: openspec/changes/.pi-map.index.md
map: openspec/changes/.pi-map.md
@@ -4,14 +4,14 @@ dir: openspec/changes/fix-pi-container-mount-permissions
index: openspec/changes/fix-pi-container-mount-permissions/.pi-map.index.md
## role
This is a change request/bug fix package for resolving filesystem permission issues with pi-agent container repository mounts and npm updates.
Documents a bug fix for container filesystem permission issues affecting Pi agent repository mounts and npm operations in containerized development environments.
## files
- change.md | Documents a bug fix for pi-agent container repository mount paths and npm update permissions involving multiple code changes across manifest compilation, instance service, and database migrations. | dep: Alembic, manifest_compiler.py, instance_service.py, pytest, ruff, mypy, npm
- tasks.md | Tracks completion status of tasks for fixing a pi container's repository mount and npm update permissions in a software project
- change.md | Documents a bug fix for pi-agent container repository mounting paths and npm update permissions in a containerized development environment. | dep: Alembic, Docker, npm, git, pytest, ruff, mypy
- tasks.md | Task tracking document for fixing Pi container repository mount paths and npm update permission issues in a containerized agent system | dep: Alembic, manifest_compiler.py, instance_service.py, pytest, ruff, mypy
## arch
Issue-tracking documentation structure using lightweight markdown-based change management with separate change specification and task tracking files.
Documentation-only package using markdown-based change tracking (change.md for specifications, tasks.md for execution tracking) without active code artifacts.
## tags
npm, tasks, container, repository, mount, update, permissions, py
npm, agent, container, repository, paths, update, containerized, alembic
## symbols
-
## workflows
@@ -30,14 +30,16 @@ After implementing configurable tool container home directories, new `pi-agent`
- Remove any stale literal `{{WORKSPACE_NAME}}` directory left over from older images at container startup.
3. Update `instance_service.py` to pass `REPO_NAME` and `WORKSPACE_NAME` into manifest compilation.
4. Remove the explicit repo mount from the built-in `pi-agent` manifest so the repo mount is synthesized by `compile_compose` rather than depending on tool config. Add a follow-up Alembic data migration that strips the `source_type: repo` mount from the manifest.
5. Add `_get_repository_mount_name()` helper to derive the workspace directory name from the repository's remote URL (matching standard `git clone` behavior) and fall back to the user-provided repository name.
6. Update unit tests for the new behavior.
5. Add `_get_repository_mount_name()` helper. When the instance is bound to a workspace, the helper returns the basename of `workspace.path`. For legacy repo-only instances it falls back to parsing the remote URL like `git clone` would, then to the user-provided repository name.
6. Switch workspace storage layout to `/data/working-copies/{workspace_id}/{repo_name}/` so `git clone` creates the repo-named directory naturally, making `workspace.path.basename` the correct container mount name. This replaces the previous `/data/working-copies/{repo_id}/{workspace_name}/` layout.
7. Update unit tests for the new behavior.
## Affected files
- `apps/api/alembic/versions/2026_06_14_182955_fix_pi_agent_home_directory_mount.py`
- `apps/api/alembic/versions/2026_06_15_090500_remove_pi_agent_explicit_repo_mount.py`
- `apps/api/src/services/build/manifest_compiler.py`
- `apps/api/src/services/shared/workspace_manager.py`
- `apps/api/src/services/tool/instance_service.py`
- `apps/api/tests/unit/test_manifest_compiler.py`
- `apps/api/tests/unit/test_instance_service.py`
@@ -6,6 +6,7 @@
- [x] Update instance_service.py to pass REPO_NAME/WORKSPACE_NAME
- [x] Remove explicit repo mount from pi-agent manifest; synthesize mount in compile_compose
- [x] Add _get_repository_mount_name() helper to derive workspace name from remote URL
- [x] Switch workspace storage layout to /data/working-copies/{workspace_id}/{repo_name}/
- [x] Update unit tests
- [x] Run quality gates (pytest unit, ruff, mypy)
- [ ] Commit and push