Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .agent/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,18 @@ Cross-session memory using SQLite FTS5 for fast full-text search.
**Parallel branch work** (git worktrees): For multiple terminals/sessions on different branches:

```bash
# Create worktree for a branch (separate directory)
~/.aidevops/agents/scripts/worktree-helper.sh add feature/my-feature
# Creates: ~/Git/{repo}-feature-my-feature/
# Recommended: Worktrunk (install: brew install max-sixty/worktrunk/wt)
wt switch -c feature/my-feature # Create worktree + cd into it
wt list # List with CI status
wt merge # Squash/rebase + cleanup

# List all worktrees
# Fallback: worktree-helper.sh (no dependencies)
~/.aidevops/agents/scripts/worktree-helper.sh add feature/my-feature
~/.aidevops/agents/scripts/worktree-helper.sh list

# Find sessions for open worktrees
~/.aidevops/agents/scripts/worktree-sessions.sh list

# Clean up after merge
~/.aidevops/agents/scripts/worktree-helper.sh clean
```

See `workflows/worktree.md` for full workflow.
See `workflows/worktree.md` for full workflow, `tools/git/worktrunk.md` for Worktrunk docs.

**Branch types**: `feature/`, `bugfix/`, `hotfix/`, `refactor/`, `chore/`, `experiment/`, `release/`

Expand Down Expand Up @@ -387,7 +384,7 @@ Subagents provide specialized capabilities. Read them when tasks require domain
| `tools/conversion/` | Format conversion - document transformation between formats | pandoc |
| `tools/data-extraction/` | Data extraction - scraping business data, Google Maps, reviews | outscraper |
| `tools/deployment/` | Deployment automation - self-hosted PaaS, serverless, CI/CD | coolify, coolify-cli, vercel |
| `tools/git/` | Git operations - GitHub/GitLab/Gitea CLIs, Actions, authentication, AI PR automation | github-cli, gitlab-cli, gitea-cli, github-actions, opencode-github, opencode-gitlab |
| `tools/git/` | Git operations - GitHub/GitLab/Gitea CLIs, Actions, worktrees, AI PR automation | github-cli, gitlab-cli, gitea-cli, github-actions, worktrunk, opencode-github, opencode-gitlab |
| `tools/credentials/` | Secret management - API keys, password vaults, environment variables | api-key-setup, api-key-management, vaultwarden, environment-variables |
| `tools/opencode/` | OpenCode config - CLI setup, plugins, authentication, Oh-My-OpenCode extensions | opencode, opencode-anthropic-auth, oh-my-opencode |
| `tools/task-management/` | Task tracking - dependency graphs, blocking relationships, visual planning | beads |
Expand Down
1 change: 1 addition & 0 deletions .agent/scripts/tool-version-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ NPM_TOOLS=(
BREW_TOOLS=(
"brew|GitHub CLI|gh|--version|gh|brew upgrade gh"
"brew|GitLab CLI|glab|--version|glab|brew upgrade glab"
"brew|Worktrunk|wt|--version|max-sixty/worktrunk/wt|brew upgrade max-sixty/worktrunk/wt"
"brew|Beads CLI|bd|version|steveyegge/beads/bd|brew upgrade steveyegge/beads/bd"
"brew|jq|jq|--version|jq|brew upgrade jq"
"brew|ShellCheck|shellcheck|--version|shellcheck|brew upgrade shellcheck"
Expand Down
263 changes: 263 additions & 0 deletions .agent/tools/git/worktrunk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
---
description: Worktrunk (wt) - Git worktree management for parallel AI agent workflows
mode: subagent
tools:
read: true
write: false
edit: false
bash: true
glob: true
grep: true
webfetch: true
task: false
---

# Worktrunk Guide

<!-- AI-CONTEXT-START -->

## Quick Reference

- **CLI Tool**: `wt` (Worktrunk) - Git worktree management for parallel AI workflows
- **Install**: `brew install max-sixty/worktrunk/wt` (macOS/Linux) | `cargo install worktrunk`
- **Shell Integration**: `wt config shell install` (enables directory switching)
- **Docs**: https://worktrunk.dev

**Core Commands**:

```bash
wt switch feat # Switch/create worktree (with cd)
wt switch -c feat # Create new branch + worktree
wt switch -c -x claude feat # Create + start Claude Code
wt list # List worktrees with CI status + PR links
wt remove # Remove current worktree + branch
wt merge # Squash/rebase/merge + cleanup
wt select # fzf-like worktree selector
```

**Fallback**: `~/.aidevops/agents/scripts/worktree-helper.sh` (no dependencies)
<!-- AI-CONTEXT-END -->

## Overview

Worktrunk makes git worktrees as easy as branches. It's designed for running multiple AI agents in parallel, each in their own working directory.

**Why Worktrunk over raw git worktree?**

| Task | Worktrunk | Plain git |
|------|-----------|-----------|
| Switch worktrees | `wt switch feat` | `cd ../repo.feat` |
| Create + start Claude | `wt switch -c -x claude feat` | `git worktree add -b feat ../repo.feat && cd ../repo.feat && claude` |
| Clean up | `wt remove` | `cd ../repo && git worktree remove ../repo.feat && git branch -d feat` |
| List with status | `wt list` | `git worktree list` (paths only) |

## Installation

```bash
# Homebrew (macOS & Linux) - recommended
brew install max-sixty/worktrunk/wt && wt config shell install

# Cargo (Rust)
cargo install worktrunk && wt config shell install

# Windows (winget)
winget install max-sixty.worktrunk
git-wt config shell install # Note: 'wt' conflicts with Windows Terminal
```

**Shell integration is required** for `wt switch` to change directories. Without it, commands only print the path.

## Core Commands

### wt switch - Switch/Create Worktrees

```bash
# Switch to existing worktree (or create if branch exists)
wt switch feature/auth

# Create new branch + worktree
wt switch -c feature/new-thing

# Create + execute command (e.g., start Claude Code)
wt switch -c -x claude feature/ai-task
wt switch -c -x "npm install" feature/setup
```

### wt list - List Worktrees

```bash
wt list

# Output includes:
# - Branch name
# - Path
# - CI status (if GitHub Actions configured)
# - PR link (if PR exists)
# - Dirty/clean status
```

### wt remove - Remove Worktree

```bash
# Remove current worktree (prompts for confirmation)
wt remove

# Remove specific worktree
wt remove feature/old-thing

# Force remove (skip confirmation)
wt remove -f feature/old-thing
```

### wt merge - Merge Workflow

```bash
# Interactive merge (choose squash/rebase/merge)
wt merge

# Squash merge directly
wt merge --squash

# Rebase merge
wt merge --rebase
```

After merge, worktrunk:
1. Switches to main/master
2. Pulls latest changes
3. Removes the worktree
4. Deletes the local branch

### wt select - Interactive Selector

```bash
# fzf-like selector for worktrees
wt select
```

## Hooks

Worktrunk supports hooks for automated setup. Create `.worktrunk/hooks/` in your repo:

```bash
# .worktrunk/hooks/post-create
#!/bin/bash
# Runs after creating a new worktree
npm install
```

Available hooks:
- `post-create` - After worktree creation
- `pre-merge` - Before merge
- `post-merge` - After merge
- `pre-remove` - Before removal

## Configuration

```bash
# View current config
wt config show

# Set path template (default: ../repo.branch)
wt config set path_template "../{repo}.{branch}"

# Set default merge strategy
wt config set merge_strategy squash
```

## LLM Commit Messages

Worktrunk integrates with [llm](https://llm.datasette.io/) for AI-generated commit messages:

```bash
# Install llm
pip install llm

# Configure (uses your default LLM)
wt config set llm_commits true

# Now commits auto-generate messages from diffs
git add .
wt commit # Generates message via LLM
```
Comment on lines +168 to +182
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the current state of worktrunk.md
fd worktrunk.md

Repository: marcusquinn/aidevops

Length of output: 93


🏁 Script executed:

# Search for existing credential storage patterns in documentation
rg -t md "mcp-env.sh|api.?key|credential" --max-count 20

Repository: marcusquinn/aidevops

Length of output: 34366


🏁 Script executed:

# Look for documentation about the llm tool in the codebase
rg -t md "llm" -B 2 -A 5 | head -100

Repository: marcusquinn/aidevops

Length of output: 5320


🌐 Web query:

llm datasette API keys configuration and requirements

💡 Result:

Summary — how Datasette's llm tooling and LLM-based plugins handle API keys, and what you must configure

  1. Where keys are stored / ways to provide them
  • llm tool built‑in key store: run llm keys set to save a key (stored in keys.json). The saved alias can be used with llm and many Datasette plugins. [1]
  • Environment variables: common for containers/servers (e.g. OPENAI_API_KEY). Plugins will read provider‑specific env vars if present. [1][3]
  • Datasette plugin config / metadata: some plugins let you map model IDs to env vars or define keys in metadata.yml/json (plugins -> -> keys / key_env_var). Example: datasette-llm-embed and other plugins support configuring keys in metadata.yml pointing at an $env var. [2][3][4]
  1. Resolution / precedence (typical)
  • Plugin-specific config in metadata.json/yml (if provided) → llm keys alias (keys.json) → environment variable → error if none present. Exact precedence can vary per plugin; check plugin docs. [3][4]
  1. What plugins expect (requirements)
  • The underlying llm package must be installed and configured for the provider/model you intend to use (e.g., llm-openai plugin for OpenAI models). Some plugins require async-capable models or structured-output support — see each plugin for details. [1][5]
  • Provide the full model ID when mapping keys where requested (e.g., ada-002). [2]
  • For container deployments, prefer env vars; for local dev the llm key store is convenient. [1][3]
  1. Common config examples
  • llm keys set openai (interactive storage in keys.json). [1]
  • Environment variable: export OPENAI_API_KEY="sk-…". [1][3]
  • metadata.yml plugin key example:
    plugins:
    datasette-llm-embed:
    keys:
    ada-002:
    $env: OPENAI_API_KEY
    (or plugin-specific key_env_var / env_api_key_var settings). [2][3][4]
  1. Security & operational notes
  • Do not expose server-side API keys to client-side/localStorage. Plugins note that UI localStorage is used only for UI state/history; keys must be provided on the server. [3]
  • Sharing a Datasette instance with a configured key lets users potentially consume your paid LLM quota — be cautious about permissions and public access. [3]

References
[1] Datasette llm tool — Setup & API key management. (llm.datasette.io)
[2] datasette-llm-embed plugin docs (example metadata keys mapping). (datasette.io)
[3] datasette-llm-sql-writer README / PyPI (auth, env var config, warnings). (pypi.org)
[4] datasette-query-assistant plugin docs (model and key_env_var config). (datasette.io)
[5] datasette-extract plugin docs (requirements: async models, discovery of configured keys). (pypi.org)

If you want, tell me which Datasette plugin(s) you plan to use and whether you’re deploying locally or in a container, and I’ll give exact metadata.yml and environment-variable examples.

Citations:


Add secure storage guidance for llm API keys.
The llm tool requires API keys for LLM providers (OpenAI, Anthropic, etc.). Add a note directing developers to store credentials in ~/.config/aidevops/mcp-env.sh per project standards.

🔒 Suggested doc addition
 # Install llm
 pip install llm
+
+# If API keys are required, store them in ~/.config/aidevops/mcp-env.sh (600 perms)
+# Avoid placing secrets in repos or working directories.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## LLM Commit Messages
Worktrunk integrates with [llm](https://llm.datasette.io/) for AI-generated commit messages:
```bash
# Install llm
pip install llm
# Configure (uses your default LLM)
wt config set llm_commits true
# Now commits auto-generate messages from diffs
git add .
wt commit # Generates message via LLM
```
## LLM Commit Messages
Worktrunk integrates with [llm](https://llm.datasette.io/) for AI-generated commit messages:
🤖 Prompt for AI Agents
In @.agent/tools/git/worktrunk.md around lines 168 - 182, Update the "LLM Commit
Messages" section to include a short security note instructing developers to
store llm API keys in the project-standard credentials file
(~/.config/aidevops/mcp-env.sh) and reference any environment variable names
used by llm; mention this applies when enabling llm commits (e.g., wt config set
llm_commits true) and give a one-line reminder to keep the file permissions
restricted.


## Integration with aidevops

### Recommended Workflow

1. **Use `wt` as primary tool** when installed
2. **Fall back to `worktree-helper.sh`** if wt unavailable

```bash
# Check if wt is available
if command -v wt &>/dev/null; then
wt switch -c feature/my-feature
else
~/.aidevops/agents/scripts/worktree-helper.sh add feature/my-feature
cd ~/Git/repo-feature-my-feature
fi
```

### Pre-Edit Check Integration

The `pre-edit-check.sh` script works with both tools:
- Detects if on protected branch
- Suggests worktree creation
- In loop mode, auto-creates worktree

### Session Naming

After creating a worktree, sync the session name:
```bash
# Claude Code MCP tool
session-rename_sync_branch
```

## Comparison: Worktrunk vs worktree-helper.sh

| Feature | Worktrunk (`wt`) | worktree-helper.sh |
|---------|------------------|-------------------|
| Shell integration | Built-in (cd support) | Prints path only |
| Hooks | Yes (post-create, etc.) | No |
| CI status | Yes (in `wt list`) | No |
| PR links | Yes (in `wt list`) | No |
| Merge workflow | `wt merge` (squash/rebase) | Manual |
| LLM commits | Yes (via llm) | No |
| Dependencies | Rust binary | Bash only |
| Installation | brew/cargo/winget | Already deployed |

**Recommendation**: Use Worktrunk when available for better UX. Use worktree-helper.sh as fallback or in minimal environments.

## Troubleshooting

### "wt: command not found"

Shell integration not installed:
```bash
wt config shell install
source ~/.zshrc # or ~/.bashrc
```
Comment on lines +235 to +239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix markdownlint MD031 (blank lines around fences).
Add blank lines before/after the fenced blocks in Troubleshooting to keep linting clean.

🧹 Proposed fix
 Shell integration not installed:
+
 ```bash
 wt config shell install
 source ~/.zshrc  # or ~/.bashrc

"Branch already checked out"

@@
Each branch can only be in one worktree:
+

wt list  # Find where branch is checked out
wt remove feature/auth  # Remove if not needed

@@
On Windows, wt is aliased to Windows Terminal. Use git-wt instead:
+

git-wt switch feature/auth
</details>


Also applies to: 243-247, 251-254

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>

236-236: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

</details>

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

In @.agent/tools/git/worktrunk.md around lines 235 - 239, Add a blank line both
immediately before and immediately after each fenced code block in the
Troubleshooting sections (e.g., the block under the "Shell integration not
installed:" paragraph containing "wt config shell install" / "source ~/.zshrc",
the block under the "Branch already checked out" section with "wt list" / "wt
remove feature/auth", and the Windows note with "git-wt switch feature/auth") so
that each ```bash fence is separated by a blank line from surrounding text to
satisfy markdownlint MD031.


</details>

<!-- fingerprinting:phantom:poseidon:eagle -->

<!-- This is an auto-generated comment by CodeRabbit -->


### "Branch already checked out"

Each branch can only be in one worktree:
```bash
wt list # Find where branch is checked out
wt remove feature/auth # Remove if not needed
```

### Windows: "wt" opens Windows Terminal

On Windows, `wt` is aliased to Windows Terminal. Use `git-wt` instead:
```bash
git-wt switch feature/auth
```

Or disable the Windows Terminal alias in Settings.

## Related

- `workflows/worktree.md` - Full worktree workflow documentation
- `workflows/git-workflow.md` - Branch naming and conventions
- `scripts/worktree-helper.sh` - Fallback bash implementation
- https://worktrunk.dev - Official documentation
38 changes: 29 additions & 9 deletions .agent/workflows/worktree.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ tools:
- **Solution**: Separate working directories, each on its own branch
- **Core principle**: Main repo (`~/Git/{repo}/`) ALWAYS stays on `main`

**Key Commands**:
**Recommended Tool**: [Worktrunk](https://worktrunk.dev) (`wt`) - install via `brew install max-sixty/worktrunk/wt`

```bash
# Create worktree for a branch
~/.aidevops/agents/scripts/worktree-helper.sh add feature/my-feature
**Key Commands** (Worktrunk - preferred):

# List all worktrees
~/.aidevops/agents/scripts/worktree-helper.sh list
```bash
wt switch -c feature/my-feature # Create worktree + cd into it
wt list # List worktrees with CI status
wt merge # Squash/rebase/merge + cleanup
wt remove # Remove current worktree
```

# Remove worktree (keeps branch)
~/.aidevops/agents/scripts/worktree-helper.sh remove feature/my-feature
**Fallback** (worktree-helper.sh - no dependencies):

# Clean up merged worktrees
```bash
~/.aidevops/agents/scripts/worktree-helper.sh add feature/my-feature
~/.aidevops/agents/scripts/worktree-helper.sh list
~/.aidevops/agents/scripts/worktree-helper.sh clean
```

Expand Down Expand Up @@ -458,6 +461,23 @@ git stash pop

**Prevention**: Before closing a PR or deleting a branch, ensure no active sessions are using that worktree. Use `worktree-sessions.sh list` to check.

## Tool Comparison: Worktrunk vs worktree-helper.sh

| Feature | Worktrunk (`wt`) | worktree-helper.sh |
|---------|------------------|-------------------|
| Shell integration | Built-in (cd support) | Prints path only |
| Hooks | Yes (post-create, etc.) | No |
| CI status | Yes (in `wt list`) | No |
| PR links | Yes (in `wt list`) | No |
| Merge workflow | `wt merge` (squash/rebase) | Manual |
| LLM commits | Yes (via llm) | No |
| Dependencies | Rust binary | Bash only |
| Installation | brew/cargo/winget | Already deployed |

**Recommendation**: Use Worktrunk when available for better UX. Use worktree-helper.sh as fallback or in minimal environments.

See `tools/git/worktrunk.md` for full Worktrunk documentation.

## Comparison: Worktrees vs Alternatives

| Approach | Pros | Cons |
Expand Down
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
└── scripts/ # Helper scripts
```

**Before extending aidevops**: Read `.agent/aidevops/architecture.md` for:
- Agent design patterns (progressive disclosure, context offloading, Ralph loop)
- Extension guide (adding services, tools, documentation standards)
- Framework conventions (naming, code standards, security requirements)

<!-- AI-CONTEXT-END -->

## Two AGENTS.md Files
Expand Down
Loading
Loading