# Explorer Directory → Project Current Contract Inventory

> Baseline: fresh `origin/main` at the PR cleanup point. This file records current facts only; it does not assert that Project behavior exists.

## Database facts

- There is no `projects` table and no `project_grants` table on the baseline.
- `review_contexts` has no `project_id` column.
- The saved Explorer resource is `directories`, created by `internal/tidb/migrations/00241_directories.sql` and mirrored in `internal/tidb/bootstrap.sql`.
- `directories` columns are:
  - `id`
  - `workspace_id`
  - `machine_id`
  - `root_path`
  - `display_name`
  - `kind`
  - `badge`
  - `created_by_member_id`
  - `updated_by_member_id`
  - `created_at`
  - `updated_at`
- Directory IDs are deterministic hashes of workspace + machine + normalized path.
- No database foreign key points from `review_contexts` to `directories`; Reviews independently store workspace, machine, and root.
- Production row counts are not available from the repository and must not be guessed.

## Backend production path

The saved Directory path is:

```text
Web Explorer
  → /api/v1/workspaces/:workspaceId/directories*
  → internal/api/webagent/api_directories.go
  → internal/store/review/directories.go
  → directories
```

Current routes:

```text
GET    /api/v1/workspaces/:workspaceId/directories
POST   /api/v1/workspaces/:workspaceId/directories
GET    /api/v1/workspaces/:workspaceId/directories/browse
DELETE /api/v1/workspaces/:workspaceId/directories/:directoryId
GET    /api/v1/workspaces/:workspaceId/directories/:directoryId/files
GET    /api/v1/workspaces/:workspaceId/directories/:directoryId/files/content
```

Current backend contracts to replace:

- `agent.Directory`
- `agent.UpsertDirectoryParams`
- `DirectoryHandler`
- `directoryCreateRequest`
- `directoryResource`
- `UpsertDirectoryForUser`
- `ListDirectoriesForUser`
- `GetDirectoryForUser`
- `DeleteDirectoryForUser`
- `internal/store/review/directories.go`
- `internal/api/webagent/api_directories.go`
- Directory methods in Webagent ports/fakes/routes/tests

## Desktop/MCP contracts

Saved-resource tools to replace:

```text
directory_list
directory_add
directory_delete
```

They are declared/handled in Desktop wire tool definitions/handlers, `desktop/internal/wire/agentspecs/specs.go`, registry/inventory tests, and `desktop/internal/wire/testdata/agentteam_mcp_tool_defs.golden.json`.

These are product-resource tools. Their removal does not ban ordinary filesystem directory operations.

## Web contracts

- Directory API DTOs and request functions are in `web/src/agentteam/api/machinesAgents.ts`.
- Explorer Directory components/state/navigation live under `web/src/agentteam/workspace/explorer/` and WorkspaceShell/sidebar modules.
- Saved-resource locale keys use the `explorer_directory*` family.
- Some Directory detail copy refers to real filesystem folders and must be renamed selectively, not with a repository-wide text replacement.

## Review facts retained from main

- PR #2702 is already in main and supplies Review fingerprint polling and identity/transport hardening.
- Current Review rows carry `workspace_id`, `machine_id`, `root_path`, refs, and `target_hash`; they do not reference Directory.
- Current Review create goes through `CreateReviewContextForAgent` and `ValidateReviewParams`.
- This Project work must preserve existing fingerprint/snapshot/diff behavior and add only the approved Project association.

## Explicitly out of scope for renaming

- Generic filesystem directories and folder tree entries.
- Machine path-picker internals where “directory” means a filesystem folder.
- Organization directory / SSO synchronization, including `web/src/agentteam/api/workspace/directory-sync.ts` and `/api/v1/orgs/.../units`.
- Agent working directories and runtime workdirs.
- Review fingerprint/caching internals already present in main.

## Cleanup assertions for PR #2709

The cleaned PR is docs/inventory only. Its net diff contains no production schema, migration, bootstrap, service, route, RPC, Desktop, Web, or test changes. Project schema begins only after this inventory and the minimal plan are approved.
