S05-04 - Naming
Purpose: How wb identifies a project, a session and its branch, and how
projects are registered, checked, moved and removed.
Design
Section titled “Design”Project key
Section titled “Project key”A project’s key is the host realm, and the absolute path of the
repository’s git common directory
(git rev-parse --path-format=absolute --git-common-dir).
- Every
git worktreeof one repository has the same common directory. So they are one project. - A submodule has a common directory of its own, under the parent
repository’s
modules/. So it is a project of its own. - The remote URLs aren’t part of the key. So a changed or added remote, or a token in a URL, doesn’t make a new project.
The parts of the key:
- Realm. The native host, or a WSL distribution by name. A repository
on a Windows drive, opened from WSL through
/mnt/c, and the same repository opened from native Windows are in two realms. So they are two projects. - Path. The key is the canonical form of the common directory git
returns, for every kind of
.gitentry (S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each., I293I293 (closed): wb-hostd: project records, identity check, registration and placement over local IPCwb-hostd owns state.db (S04-architecture, "Host state"), so the projects table, and each change to a project, go through it.): links resolved, and letter case as on disk. So~/Git/foo,~/git/fooand a link to it give one key.
Resolving the key
Section titled “Resolving the key”wb runs git for the key, the remotes and the root commits with the
git binary of S08-08-host-gitS08-08-host-git: Host GitWhich git binary runs on the host, the oldest version Wraith Box accepts, and where that is checked., core.hooksPath set to /dev/null
(NUL on Windows), core.fsmonitor set to false, and an otherwise
scrubbed environment, as wb-git runs git (S08-03-pushesS08-03-pushes: PushesWhere the guest's pushes land, the settings receive-pack runs with, which refs a push may write, and the push at session end.).
It sets only these variables:
HOME, from the user database, not from the environment;XDG_CONFIG_HOMEfrom the login environment, when set there to an absolute path of printable ASCII without a..component. Otherwise it stays unset, with a warning in the log;TMPDIR, the caller’s temporary directory, an absolute path;LC_ALL=C.
So no GIT_* variable, from the user’s shell or a .envrc, can point the
directory at another repository or add configuration. On Windows, Go’s
os/exec adds the caller’s SYSTEMROOT, and reads PATHEXT for the
binary’s extension. The Windows host work (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.) sets it itself.
The login environment belongs to the user’s login session. A variable exported in a
shell, or set by a .envrc, doesn’t reach it. On macOS, wb reads launchd’s with
/bin/launchctl getenv XDG_CONFIG_HOME, run with an empty environment.
A failed user database or launchctl lookup, or a relative temporary directory,
refuses the command. wb doesn’t take the caller’s value in its place.
Unlike wb-git, it reads the user’s global git configuration. So remote
URLs resolve as the user’s git resolves them (url.<base>.insteadOf).
Which directory
Section titled “Which directory”wb walks up from the current directory, in canonical form, to the first one
with a .git entry, as git does. The key must belong to that directory. A
.git directory must be both --git-dir and --git-common-dir. Any type
other than a directory or a file refuses the command. A symbolic link, for
one, could name another project’s .git.
A link in the git directory but the top-level hooks, or in a .git file’s
common directory, that resolves out of it refuses the command too
(project-git-dir-link-outside, project-git-dir-link-unresolved). So does a
directory with too many entries to check in time (project-git-dir-walk-incomplete).
An objects/info/alternates file refuses it (project-git-alternates), as does the
text of an include or includeIf header in a config or config.worktree git
reads (project-git-config-include). wb checks before git runs, or for a .git
file before it reads core.worktree. git rev-parse reads its config first,
which lets git read no more: the .git file can name any git directory.
git works in the tree core.worktree names. Each value of it, in the
common directory’s config or the git directory’s config.worktree, read
with includes off, must canonicalize, relative to --git-dir, to the
directory holding .git, for every kind of .git entry.
A .git file
Section titled “A .git file”A .git file (gitdir: …) is accepted only for a linked worktree or a
submodule:
- A linked worktree has
--git-dir<common>/worktrees/<name>, whosegitdirback-link names this.gitfile. Itscore.worktreemay be unset. - A submodule’s
--git-diris the common directory. It setscore.worktree.
wb doesn’t use --show-toplevel, which git derives from
core.worktree. Anything else refuses the command, such as a .git file
in a downloaded archive that names another project’s repository or submodule.
Failure
Section titled “Failure”Any failed git run, or a git config file that isn’t a readable regular file, refuses the command, “dubious ownership” included. Every refusal here says why (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.), and nothing is registered.
Which commands
Section titled “Which commands”Every command that resolves a project from a directory resolves it this
way: wb claude, wb trust, wb untrust, wb land, wb diff, and the
wb project commands and wb shell without --project. wb project move
resolves its <dir> this way even with --project.
wb land and wb diff find the user’s repository only this way, never
from a path in state.db or from wb-hostd. They refuse a session
that isn’t the resolved project’s (S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything.).
Wraith Box’s own directories
Section titled “Wraith Box’s own directories”A key under <data>, <config> or <logs> refuses the command. So no
command treats a repository that wb-hostd can write, such as a
landing.git, as the user’s. It compares in canonical form.
Project id
Section titled “Project id”A project’s id is 128 random bits, chosen at registration (FR02-any-repoFR02-any-repo: Any git repositoryWorks in any git repository.). It is written as 32 lowercase hexadecimal characters, the project ID format. It is kept for the project’s life.
The id isn’t derived from the key. So a new repository at a moved project’s old path never gets its id.
The projects table of state.db (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Host state”) maps
each key to one id. A key has at most one project.
Recorded identity
Section titled “Recorded identity”At registration, wb records every URL of each remote, as the user’s
git resolves it. It does that after the cleaning of
S08-01-into-the-guestS08-01-into-the-guest: Into the GuestHow the project's code reaches the guest: the clone, its transport, its remotes, and the uncommitted changes carried in at session start. (“Remote URLs”).
- An SSH remote is compared as its
https://host/pathform, without user, port, password, query or fragment. So a switch between SSH and HTTPS for the same repository isn’t a difference, and neither is a rotated token. - A URL the guest doesn’t get is compared with its user name, password, query string and fragment removed.
- A URL the cleaner can’t parse, or a
<helper>::URL, is recorded assha256:<hex>of its bytes, so a token in it is never stored.
For a repository with no remote, wb also records its root commits
(git rev-list --max-parents=0 --all). It doesn’t record them for a
repository with a remote. The walk reads the whole history at every
session start, and the URLs already tell repositories apart.
Grow-only
Section titled “Grow-only”At a session start, the recorded identity can be empty while the repository
now has a remote or a root commit. wb then records it, with a 5019 event.
A repository that has had neither a remote nor a commit at any session start has nothing recorded. So a replacement at its path before then is the same project.
Identity check
Section titled “Identity check”wb compares the recorded identity with the repository’s current one:
- at each session start;
- in every other command that resolves the project from a directory,
except
wb project confirmandwb project rm.
These refuse the command:
- a difference in the URLs;
- a recorded root commit that is no longer among the current root commits.
The message names what was recorded, what is there now, and
wb project confirm (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
Without this check, a different repository cloned into the same directory would inherit the old project’s approvals and policy.
Confirming
Section titled “Confirming”wb project confirm records the current identity, and clears
config_trust. So a replaced repository’s .wraithbox/ isn’t read
until the user runs wb trust and its boundary check again
(SEC09-host-policySEC09-host-policy: Policy is held on the hostThe guest cannot read or change policy.).
It prints the placement, and the approvals the project keeps. Its 5019
event holds both the URL set and the root commit set.
Moving
Section titled “Moving”wb project move <dir> resolves the key of <dir> by the rules above.
Then it changes the project’s key to it, and keeps the id. The
project’s Claude Code state (FR13-claude-stateFR13-claude-state: Claude Code state per projectClaude Code's conversation history, and the state it keeps only in the guest, persist per project, so --resume/--continue work within a project.), approvals, policy and
landing repository stay with it.
It runs the identity comparison for <dir>, and prints any difference.
The next session start then refuses until wb project confirm.
A move to another project’s key is refused, with that project named.
Registration
Section titled “Registration”The first command that registers an unknown key registers a new
project. That command is a session start, or wb project place. The
rules are the same for both.
wb first compares the repository’s identity with every existing
project’s. A match is the same URLs, or, for a repository without a
remote, a shared root commit.
- Moved. It matches a project whose location no longer resolves to
its key, decided without running git there (S04-06-git-confinementS04-06-git-confinement: Git and the `wb-hostd` ProfileHow git runs on data from the guest, what the wb-hostd profile lets it write, and what wb takes from wb-hostd.).
wbrefuses the command and names the project withwb project move, which keeps its state, orwb project rm, which drops it. - Second clone. Otherwise, a match is a second clone of a repository
whose first clone is still in place. It registers as its own project.
The registration notice names each matching project and its
placement(NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
When any matching project has placement = isolated, the new project
starts with placement = isolated too. So a clone of a repository the user
isolated doesn’t land in the work VM (T13-new-project-grantsT13-new-project-grants: New projects share the work VM's grantsA newly registered project has placement = work (S06-04-vms-and-placement).). Only the
placement is copied, never approvals, bindings, policy or config_trust.
Removing
Section titled “Removing”wb project rm removes the project:
- its settings, its policy and the credential bindings in it;
- the approvals, cached join approvals and learn list that name it;
export.gitandlanding.git;- its row in
state.db.
wb removes the project directory <data>/projects/<project-id>, with
both repositories, itself. wb-hostd can’t remove it
(S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Each host daemon is self-sandboxed”).
The secret store items behind its bindings stay. wb cred manages
them, and another project may use the same item. rm lists them, and
wb cred rm removes them.
The project user
Section titled “The project user”rm asks wb-guestd in each VM to remove the project user and its home.
- The pending removal is a record in
state.dbthat survives restarts. wb-hostdsends it when the VM runs, and otherwise at its next start.
wb-guestd’s reply is untrusted (SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy.):
- Only a removed reply for the project and UID sent clears the record.
- Any other reply keeps it, and the next connection sends it again.
- A false reply can only leave the home inside that guest.
The host-side state is gone before the request is sent. Ids are random, so no later project gets this one’s id.
When rm is refused
Section titled “When rm is refused”rm is refused while the project has a session, or returned work that
wasn’t landed or discarded. The refusal lists them.
A lost session doesn’t count as a session here. rm ends it with no
recovery push (S06-11-reconnect-and-recoveryS06-11-reconnect-and-recovery: Reconnect, Loss and RecoveryWhat happens when the host-guest link drops, when a session is lost, and how a lost session's work is recovered or discarded., “Discarding a lost session”).
Branches already landed in the user’s repository stay.
Replacing a project
Section titled “Replacing a project”A project can hold a key or identity that another project should have.
The user then removes it with wb project rm, and moves the other one.
wb project move never replaces a project. So dropping a project’s
state and approvals always takes this one explicit command.
A human-readable name comes from the directory that holds the common
directory, or a submodule’s own. wb project rename changes it. A name
keeps wb/<session-id> a valid branch, and prints without escapes.
Session id and branch
Section titled “Session id and branch”- Session id:
<project-name>-<yyyymmdd>-<hhmm>-<4 random chars>. - Returned work lands on host branches
wb/<session-id>by default.
Decisions
Section titled “Decisions”Project identity
Section titled “Project identity”The project key, the recorded identity and the rules for registration, moving and confirming above.
- Decided: I42I42 (closed): S05-cli, S06-vm-lifecycle, S09-policy-credentials-audit: separate configuration trust from VM placement; project identityThe specs use "trusted" for two different things and do not give a default: (B42-trust-placementB42-trust-placement: Where does a new project run, and what makes it the same project later?Split "trusted" into two named settings, start new projects in the isolated VM until the user moves them, and key project identity on the git directory rather than the remote URL.).
Status: Draft