Skip to content

Commit dcb443e

Browse files
committed
AI: workspaces
1 parent e127b53 commit dcb443e

File tree

4 files changed

+490
-1
lines changed

4 files changed

+490
-1
lines changed

AGENTS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ Then to run the tests do
1717
just test
1818
```
1919

20+
## Agent Workspaces
21+
22+
Automation now runs inside dedicated Jujutsu workspaces that live outside of the
23+
repository tree. Use the helper recipes to inspect and control them:
24+
25+
- `just agents::consolidate <workspace-id> <start-change> <end-change>` – run the
26+
consolidate workflow inside a workspace. The workspace is trusted with `direnv`
27+
so the nix environment loads automatically.
28+
- `just agents::workspace-status [<workspace-id>]` – list all workspaces for this
29+
repository or show metadata for a single workspace.
30+
- `just agents::workspace-shell <workspace-id>` – attach an interactive shell to a
31+
workspace (the environment is prepared with `direnv allow`).
32+
- `just agents::workspace-clean <workspace-id>` – forget the workspace and delete
33+
its cached directory once the work is integrated.
34+
35+
Workspaces are stored under `${AI_WORKSPACES_ROOT:-$XDG_CACHE_HOME/ai-workspaces}`
36+
using a repository-specific namespace. See `design-docs/jj-workspaces.md` for the
37+
full rationale and lifecycle details.
38+
2039
# Code quality guidelines
2140

2241
- Strive to achieve high code quality.

agents.just

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
consolidate start_change_id end_change_id:
1+
consolidate workspace_id start_change_id end_change_id:
2+
bash -x scripts/agent-workspace.sh run {{workspace_id}} --workflow consolidate -- just --justfile agents.just --set workspace_id={{workspace_id}} consolidate-inner {{start_change_id}} {{end_change_id}}
3+
4+
consolidate-inner start_change_id end_change_id:
25
#!/usr/bin/env sh
36
read -r -d '' INSTRUCTIONS <<-EOF
47
You will be given a diff with 'jj diff --from {{start_change_id}} --to {{end_change_id}}'. The task is to write a specification which describes the introduced changes.
@@ -24,6 +27,19 @@ consolidate start_change_id end_change_id:
2427

2528
echo "$INSTRUCTIONS" | codex exec --full-auto --config model_reasoning_effort=high
2629

30+
workspace-status workspace_id='':
31+
@if [ -z "{{workspace_id}}" ]; then \
32+
scripts/agent-workspace.sh status; \
33+
else \
34+
scripts/agent-workspace.sh status {{workspace_id}}; \
35+
fi
36+
37+
workspace-shell workspace_id:
38+
scripts/agent-workspace.sh shell {{workspace_id}}
39+
40+
workspace-clean workspace_id:
41+
scripts/agent-workspace.sh clean {{workspace_id}}
42+
2743
questions-for-pm rev='@':
2844
#!/usr/bin/env sh
2945
CURRENT_CHANGE=`jj log -r @ --template 'change_id' --no-graph`
@@ -65,6 +81,9 @@ questions-for-pm rev='@':
6581
ITERATION=$((ITERATION + 1))
6682
done
6783

84+
# Abandon the last PM_CHANGE since it must have been empty
85+
jj abandon $PM_CHANGE
86+
6887
# Return to original change
6988
jj edit $CURRENT_CHANGE
7089

design-docs/jj-workspaces.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)