Generate `.ai-context.json` and `README.working-tree.md` for existing worktree lacking metadata.
Creates metadata files for existing Git worktrees without context.
/plugin marketplace add poindexter12/waypoint/plugin install workflows@waypoint-marketplaceGenerate .ai-context.json and README.working-tree.md for existing worktree lacking metadata.
SYNTAX: /adopt:working-tree [--mode <mode>] [--description "<text>"]
OPTIONAL:
--mode <mode>
Type: enum[main, feature, bugfix, experiment, review]
Default: inferred from branch-name (see MODE_INFERENCE_ALGORITHM)
Validation: must match exactly one of the enum values
--description "<text>"
Type: string (quoted if contains spaces)
Default: "" (empty string)
Validation: any string, no restrictions
APPLY rules sequentially, first match wins:
def infer_mode(branch_name: str) -> str:
if branch_name.startswith("feature/"):
return "feature"
elif branch_name.startswith(("bugfix/", "fix/")):
return "bugfix"
elif branch_name.startswith(("exp/", "experiment/")):
return "experiment"
elif branch_name.startswith("review/"):
return "review"
elif branch_name.startswith("i18n/"):
return "feature" # i18n work is feature-type work
elif branch_name in ("main", "master"):
return "main"
else:
return "feature" # DEFAULT
DETERMINISTIC: Given same branch_name, always produces same mode.
Execute steps sequentially. Each step must complete successfully before proceeding.
EXECUTE:
REPO_ROOT=$(git rev-parse --show-toplevel 2>&1)
EXIT_CODE_ROOT=$?
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>&1)
EXIT_CODE_BRANCH=$?
VALIDATION:
DATA EXTRACTION:
WORKTREE_NAME=$(basename "$REPO_ROOT")
NEXT:
EXECUTE:
METADATA_PATH="$REPO_ROOT/.ai-context.json"
test -f "$METADATA_PATH"
EXISTS=$?
VALIDATION:
ACTION:
NEXT:
EXECUTE:
EXISTING_JSON=$(cat "$METADATA_PATH" 2>&1)
EXISTING_MODE=$(echo "$EXISTING_JSON" | jq -r '.mode // "unknown"' 2>&1)
EXISTING_DESC=$(echo "$EXISTING_JSON" | jq -r '.description // ""' 2>&1)
EXISTING_CREATED=$(echo "$EXISTING_JSON" | jq -r '.created // ""' 2>&1)
DISPLAY TO USER:
Current worktree already has metadata:
Directory: {WORKTREE_NAME}
Branch: {CURRENT_BRANCH}
Mode: {EXISTING_MODE}
Created: {EXISTING_CREATED}
Description: {EXISTING_DESC or "None"}
Do you want to overwrite this metadata?
USER DECISION (use AskUserQuestion):
NEXT:
PARSE:
# Parse --mode flag (if present)
if [[ "$@" =~ --mode[[:space:]]+([a-z]+) ]]; then
MODE_ARG="${BASH_REMATCH[1]}"
else
MODE_ARG=""
fi
# Parse --description flag (if present)
if [[ "$@" =~ --description[[:space:]]+\"([^\"]+)\" ]]; then
DESCRIPTION="${BASH_REMATCH[1]}"
elif [[ "$@" =~ --description[[:space:]]+([^[:space:]]+) ]]; then
DESCRIPTION="${BASH_REMATCH[1]}"
else
DESCRIPTION=""
fi
VALIDATION:
NEXT:
EXECUTE:
if [ -n "$MODE_ARG" ]; then
# Explicit mode provided
MODE="$MODE_ARG"
else
# Infer from branch name using MODE_INFERENCE_ALGORITHM
case "$CURRENT_BRANCH" in
feature/*)
MODE="feature"
;;
bugfix/*|fix/*)
MODE="bugfix"
;;
exp/*|experiment/*)
MODE="experiment"
;;
review/*)
MODE="review"
;;
i18n/*)
MODE="feature" # i18n work is feature-type work
;;
main|master)
MODE="main"
;;
*)
MODE="feature"
;;
esac
fi
VALIDATION:
DATA:
NEXT:
EXECUTE:
CREATED_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
FORMAT: ISO 8601 UTC (example: 2025-11-23T12:34:56Z)
VALIDATION:
NEXT:
CONTENT TEMPLATE:
{
"worktree": "{WORKTREE_NAME}",
"branch": "{CURRENT_BRANCH}",
"mode": "{MODE}",
"created": "{CREATED_TIMESTAMP}",
"description": "{DESCRIPTION}"
}
SUBSTITUTIONS:
EXECUTE:
cat > "$REPO_ROOT/.ai-context.json" <<EOF
{
"worktree": "$WORKTREE_NAME",
"branch": "$CURRENT_BRANCH",
"mode": "$MODE",
"created": "$CREATED_TIMESTAMP",
"description": "$DESCRIPTION"
}
EOF
VALIDATION:
jq empty "$REPO_ROOT/.ai-context.json"NEXT:
CHECK:
README_PATH="$REPO_ROOT/README.working-tree.md"
test -f "$README_PATH"
README_EXISTS=$?
ACTION:
CONTENT TEMPLATE:
# Worktree: {WORKTREE_NAME}
**Branch:** `{CURRENT_BRANCH}`
**Mode:** `{MODE}`
**Created:** {CREATED_TIMESTAMP}
## Purpose
{DESCRIPTION_OR_DEFAULT}
## Mode Semantics
- **main**: Minimal changes, stable work only
- **feature**: Active development, larger changes allowed
- **bugfix**: Isolated, surgical fixes only
- **experiment**: Prototypes, large swings, unsafe changes allowed
- **review**: Documentation, analysis, audits
## About This Worktree
This directory is an independent Git worktree attached to the main repository.
- Main repo: {REPO_ROOT}
- Worktree path: {REPO_ROOT}
- Branch: {CURRENT_BRANCH}
See `.ai-context.json` for machine-readable metadata.
SUBSTITUTIONS:
EXECUTE (only if README_EXISTS == 1):
DESCRIPTION_TEXT="${DESCRIPTION:-No description provided}"
cat > "$REPO_ROOT/README.working-tree.md" <<EOF
# Worktree: $WORKTREE_NAME
**Branch:** \`$CURRENT_BRANCH\`
**Mode:** \`$MODE\`
**Created:** $CREATED_TIMESTAMP
## Purpose
$DESCRIPTION_TEXT
## Mode Semantics
- **main**: Minimal changes, stable work only
- **feature**: Active development, larger changes allowed
- **bugfix**: Isolated, surgical fixes only
- **experiment**: Prototypes, large swings, unsafe changes allowed
- **review**: Documentation, analysis, audits
## About This Worktree
This directory is an independent Git worktree attached to the main repository.
- Main repo: $REPO_ROOT
- Worktree path: $REPO_ROOT
- Branch: $CURRENT_BRANCH
See \`.ai-context.json\` for machine-readable metadata.
EOF
VALIDATION:
NEXT:
OUTPUT FORMAT (exact):
Adopted worktree successfully!
Directory: {WORKTREE_NAME}
Branch: {CURRENT_BRANCH}
Mode: {MODE}
Description: {DESCRIPTION_OR_NONE}
Metadata files created:
✓ .ai-context.json
{README_STATUS}
Use /status:working-tree to view metadata anytime.
SUBSTITUTIONS:
NEXT:
DETECTION:
RESPONSE (exact):
Error: Not in a git repository
Run this command from within a git repository.
To create a new worktree with metadata:
/create:working-tree <branch-name>
CONTROL FLOW:
DETECTION:
RESPONSE (exact):
Error: Failed to read git information
Git error: {GIT_STDERR}
Check that:
- You're in a git repository
- Git is installed and working
TEMPLATE SUBSTITUTIONS:
CONTROL FLOW:
DETECTION:
RESPONSE (exact):
Error: Invalid mode '{MODE_ARG}'
Valid modes: main, feature, bugfix, experiment, review
Example:
/adopt:working-tree --mode feature --description "new feature work"
TEMPLATE SUBSTITUTIONS:
CONTROL FLOW:
DETECTION:
RESPONSE (exact):
Error: Failed to write .ai-context.json
Write error: {ERROR_MESSAGE}
Check that:
- You have write permission in this directory
- Disk space is available
- No file conflicts exist
TEMPLATE SUBSTITUTIONS:
CONTROL FLOW:
DETECTION:
RESPONSE (exact):
Warning: Failed to write README.working-tree.md
The .ai-context.json was created successfully.
You can manually create the README if needed.
CONTROL FLOW:
| Tool | Pattern | Permission | Pre-Check | Post-Check | On-Deny-Action |
|---|---|---|---|---|---|
| Bash | git:* | ALLOW | command_safe | validate_output | N/A |
| Bash | date:* | ALLOW | N/A | N/A | N/A |
| Bash | test:* | ALLOW | N/A | N/A | N/A |
| Bash | basename:* | ALLOW | N/A | N/A | N/A |
| Bash | cat > *.json | ALLOW | dir_writable | valid_json | N/A |
| Bash | cat > *.md | ALLOW | dir_writable | N/A | N/A |
| Bash | jq:* | ALLOW | N/A | N/A | N/A |
| Bash | rm:* | DENY | N/A | N/A | ABORT "Destructive operation" |
| Bash | sudo:* | DENY | N/A | N/A | ABORT "Elevated privileges" |
| Write | $REPO_ROOT/.ai-context.json | ALLOW | dir_exists | valid_json | N/A |
| Write | $REPO_ROOT/README.working-tree.md | ALLOW | dir_exists | N/A | N/A |
| Write | */.env | DENY | N/A | N/A | ABORT "Secrets file" |
| Read | $REPO_ROOT/.ai-context.json | ALLOW | file_exists | N/A | N/A |
SECURITY CONSTRAINTS:
PRECONDITIONS:
INPUT:
/adopt:working-tree
EXPECTED EXECUTION FLOW:
EXPECTED OUTPUT:
Adopted worktree successfully!
Directory: myapp
Branch: feature/login
Mode: feature
Description: None
Metadata files created:
✓ .ai-context.json
✓ README.working-tree.md (created)
Use /status:working-tree to view metadata anytime.
VALIDATION COMMANDS:
# Verify .ai-context.json created
test -f /Users/dev/myapp/.ai-context.json && echo "PASS" || echo "FAIL"
jq -r '.mode' /Users/dev/myapp/.ai-context.json | grep "feature" && echo "PASS" || echo "FAIL"
# Verify README created
test -f /Users/dev/myapp/README.working-tree.md && echo "PASS" || echo "FAIL"
PRECONDITIONS:
INPUT:
/adopt:working-tree --mode main --description "Primary development branch"
EXPECTED EXECUTION FLOW: 1-2. Standard detection 3. STEP 4 → MODE_ARG="main", DESCRIPTION="Primary development branch" 4. STEP 5 → MODE="main" (explicit, not inferred) 5-8. Standard flow
EXPECTED .ai-context.json:
{
"worktree": "myapp",
"branch": "main",
"mode": "main",
"created": "2025-11-23T12:34:56Z",
"description": "Primary development branch"
}
VALIDATION:
jq -r '.mode' .ai-context.json | grep "main" && echo "PASS" || echo "FAIL"
jq -r '.description' .ai-context.json | grep "Primary development branch" && echo "PASS" || echo "FAIL"
PRECONDITIONS:
INPUT:
/adopt:working-tree --mode experiment
EXPECTED EXECUTION FLOW:
EXPECTED OUTPUT:
Current worktree already has metadata:
Directory: myapp
Branch: feature/login
Mode: feature
Created: 2025-11-20T10:00:00Z
Description: Original description
Do you want to overwrite this metadata?
POSTCONDITIONS:
PRECONDITIONS:
INPUT:
/adopt:working-tree --mode experiment --description "New description"
EXPECTED EXECUTION FLOW: 1-2. Detect repo, metadata exists 3. STEP 3 → Display existing, ask user 4. USER SELECTS "Overwrite with new metadata" 5-9. Continue with creation (new timestamp, new mode, new description)
EXPECTED OUTPUT:
Current worktree already has metadata:
[existing data shown]
Do you want to overwrite this metadata?
[User confirms overwrite]
Adopted worktree successfully!
Directory: myapp
Branch: feature/login
Mode: experiment
Description: New description
Metadata files created:
✓ .ai-context.json
- README.working-tree.md (already exists)
Use /status:working-tree to view metadata anytime.
PRECONDITIONS:
INPUT:
/adopt:working-tree
EXPECTED EXECUTION FLOW: 1-7. Standard flow, create .ai-context.json 8. STEP 8 → README_EXISTS=0 (exists), skip creation 9. STEP 9 → Output shows README skipped
EXPECTED OUTPUT:
Adopted worktree successfully!
Directory: myapp
Branch: feature/login
Mode: feature
Description: None
Metadata files created:
✓ .ai-context.json
- README.working-tree.md (already exists)
Use /status:working-tree to view metadata anytime.
When working in main repo without worktrees:
cd ~/myapp
/adopt:working-tree --mode main --description "Primary development branch"
If worktree created without /create:working-tree:
cd ../myapp-feature-something
/adopt:working-tree
If worktree created without description:
/adopt:working-tree --description "Working on user authentication refactor"
(Will prompt to overwrite existing metadata)
If mode was inferred incorrectly:
/adopt:working-tree --mode experiment
(Will prompt to overwrite existing metadata)
For organizing worktree adoption strategy:
Task(
subagent_type='working-tree-consultant',
description='Worktree adoption strategy',
prompt='[question about when/how to adopt worktrees]'
)