|
| 1 | +# AI Workflow Workspaces |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Agent-driven workflows now execute inside dedicated Jujutsu workspaces. Each run gets |
| 6 | +its own working copy outside of the repository root so that manual edits or parallel |
| 7 | +workflows never step on each other. The helper script `scripts/agent-workspace.sh` |
| 8 | +provisions these workspaces, keeps lightweight metadata, and guarantees the directory |
| 9 | +is trusted by `direnv` so the nix environment loads automatically. |
| 10 | + |
| 11 | +## Workspace Layout |
| 12 | + |
| 13 | +- Root directory: `${AI_WORKSPACES_ROOT:-$XDG_CACHE_HOME/ai-workspaces}`. |
| 14 | +- Repository namespace: `${basename(repo)}-${sha256(repo-root)[0..10]}` to avoid |
| 15 | + collisions between repos with the same name. |
| 16 | +- Workspace path: `<root>/<repo-namespace>/<workspace-id>`. |
| 17 | +- Metadata file: `.agent-workflow.json` within every workspace, recording the workflow |
| 18 | + name, status, timestamps, and the command that is running. |
| 19 | + |
| 20 | +Workspaces are never created under the repository itself. This keeps the main tree |
| 21 | +clean and prevents the permission issues we ran into when nesting workspaces inside |
| 22 | +tracking directories. |
| 23 | + |
| 24 | +## Helper Script Responsibilities |
| 25 | + |
| 26 | +`scripts/agent-workspace.sh` centralises workspace management. Key behaviours: |
| 27 | + |
| 28 | +- `run`: Create or reattach to the workspace, call `jj workspace add` if needed, |
| 29 | + optionally pin the workspace to a starting change, run `direnv allow`, and then |
| 30 | + execute the specified command via `direnv exec` so the nix shell is active. |
| 31 | +- Metadata updates before and after the command capture runtime details. Failures are |
| 32 | + recorded as `status: "error"` for easier triage. |
| 33 | +- `status`: Summarise all known workspaces or dump a single metadata file for inspection. |
| 34 | +- `shell`: Attach an interactive shell to an existing workspace (after running |
| 35 | + `direnv allow`). This is handy for manual interventions mid-workflow. |
| 36 | +- `clean`: Remove the workspace after telling Jujutsu to forget it. |
| 37 | + |
| 38 | +Every command run inside a workspace receives environment variables describing where it |
| 39 | +is running: `AGENT_WORKSPACE_ID`, `AGENT_WORKSPACE_PATH`, `AGENT_WORKSPACE_METADATA`, |
| 40 | +`AGENT_WORKSPACE_REPO_ROOT`. |
| 41 | + |
| 42 | +## Using the Workflows |
| 43 | + |
| 44 | +- `just agents::consolidate <workspace-id> <start-change> <end-change>` creates or |
| 45 | + reuses a workspace and delegates the existing automation to `consolidate-inner`. |
| 46 | +- Nested workflows should pass the same `workspace_id` down via `--set` so that every |
| 47 | + automated step stays inside the same working copy. |
| 48 | +- `just agents::workspace-status` lists all workspaces for the repo. Add an ID to view |
| 49 | + the raw metadata, e.g. `just agents::workspace-status wf-123`. |
| 50 | +- `just agents::workspace-shell <workspace-id>` opens an interactive, nix-enabled shell |
| 51 | + rooted at the workspace. |
| 52 | +- `just agents::workspace-clean <workspace-id>` forgets the workspace in Jujutsu and |
| 53 | + removes the cached directory. |
| 54 | + |
| 55 | +The helper does not auto-clean finished workspaces so that results can be inspected or |
| 56 | +rebased manually. Once the work is integrated, run the cleanup recipe to delete the |
| 57 | +working copy. |
0 commit comments