feat(minder): prepare to split agent sessions by project
Description
This is the groundwork for splitting an agent session into one GitLab session for each project it worked in. It changes no uploads on its own. The split itself is in !4513 (merged), which is stacked on this MR.
- A new router maps each entry's working folder to a GitLab project, and divides a session's data into one part for each project. A folder recorded by a hook keeps the project the hook resolved for it, and so does a subfolder in the same Git repository. A repository cloned inside a recorded folder, and any other folder, is looked up from its origin remote, once per folder for a run. Entries without a folder go to the session's project, and entries in a folder without a GitLab project are left out. A tool result goes with its call, including a result read in a later sync. Nothing uses the router yet.
- Session records are now replaced with a rename on every operating system, so a hook or the fallback sync reading a record at the same time never sees a partly written file. They are also changed under a lock, so that a hook and the fallback sync changing the same session do not lose each other's change. The lock is a no-op on Windows.
- Codex records the working folder on its
session_metaandturn_contextlines. A sync that starts in the middle of a turn now reads back from the sync position to the last of those lines, so every entry has the folder it was recorded in. A position past the end of a rollout that was cut short or replaced reads nothing, as before.
Related to https://gitlab.com/gitlab-org/cli/-/work_items/8722
How has this been tested?
Unit tests cover the router: folders recorded by a hook, subfolders in the same repository, a repository cloned inside one, folders without a project, entries without a folder, and results that follow their calls across syncs. They also cover concurrent changes to a session record, and a Codex sync that starts in the middle of a turn or past the end of a rollout.
go test ./internal/commands/govern/..., the race detector on the sync package, and golangci-lint run ./internal/commands/govern/... pass.