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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ scripts/install-agent-git-hooks.sh
scripts/openspec/init-plan-workspace.sh
.githooks/pre-commit
oh-my-codex/
.codex/skills/musafety/SKILL.md
.claude/commands/musafety.md
.codex/skills/guardex/SKILL.md
.claude/commands/guardex.md
.omx/state/agent-file-locks.json
# multiagent-safety:END
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"agent:codex": "bash ./scripts/codex-agent.sh",
"agent:branch:start": "bash ./scripts/agent-branch-start.sh",
"agent:branch:finish": "bash ./scripts/agent-branch-finish.sh",
"agent:cleanup": "bash ./scripts/agent-worktree-prune.sh --base dev",
"agent:cleanup": "gx cleanup",
"agent:hooks:install": "bash ./scripts/install-agent-git-hooks.sh",
"agent:locks:claim": "python3 ./scripts/agent-file-locks.py claim",
"agent:locks:allow-delete": "python3 ./scripts/agent-file-locks.py allow-delete",
Expand Down
50 changes: 41 additions & 9 deletions scripts/agent-branch-start.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

TASK_NAME="${1:-task}"
AGENT_NAME="${2:-agent}"
BASE_BRANCH="${3:-}"
TASK_NAME="task"
AGENT_NAME="agent"
BASE_BRANCH=""
BASE_BRANCH_EXPLICIT=0
WORKTREE_MODE=1
ALLOW_IN_PLACE=0
WORKTREE_ROOT_REL=".omx/agent-worktrees"

if [[ -n "${3:-}" ]]; then
BASE_BRANCH_EXPLICIT=1
fi
POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case "$1" in
Expand All @@ -31,25 +29,53 @@ while [[ $# -gt 0 ]]; do
WORKTREE_MODE=0
shift
;;
--allow-in-place)
ALLOW_IN_PLACE=1
shift
;;
--worktree-root)
WORKTREE_ROOT_REL="${2:-.omx/agent-worktrees}"
shift 2
;;
--)
shift
while [[ $# -gt 0 ]]; do
POSITIONAL_ARGS+=("$1")
shift
done
break
;;
-*)
echo "[agent-branch-start] Unknown option: $1" >&2
echo "Usage: $0 [task] [agent] [base] [--in-place] [--worktree-root <path>]" >&2
echo "Usage: $0 [task] [agent] [base] [--in-place --allow-in-place] [--worktree-root <path>]" >&2
exit 1
;;
*)
break
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done

if [[ "${#POSITIONAL_ARGS[@]}" -gt 3 ]]; then
echo "[agent-branch-start] Too many positional arguments." >&2
echo "Usage: $0 [task] [agent] [base] [--in-place --allow-in-place] [--worktree-root <path>]" >&2
exit 1
fi

if [[ "${#POSITIONAL_ARGS[@]}" -ge 1 ]]; then
TASK_NAME="${POSITIONAL_ARGS[0]}"
fi

if [[ "${#POSITIONAL_ARGS[@]}" -ge 2 ]]; then
AGENT_NAME="${POSITIONAL_ARGS[1]}"
fi

if [[ "${#POSITIONAL_ARGS[@]}" -ge 3 ]]; then
BASE_BRANCH="${POSITIONAL_ARGS[2]}"
BASE_BRANCH_EXPLICIT=1
fi

sanitize_slug() {
local raw="$1"
local fallback="${2:-task}"
Expand Down Expand Up @@ -180,6 +206,12 @@ if git show-ref --verify --quiet "refs/heads/${branch_name}"; then
fi

if [[ "$WORKTREE_MODE" -eq 0 ]]; then
if [[ "$ALLOW_IN_PLACE" -ne 1 ]]; then
echo "[agent-branch-start] --in-place is blocked by default to prevent accidental edits on protected branches." >&2
echo "[agent-branch-start] If you really need it, pass both: --in-place --allow-in-place" >&2
exit 1
fi

if ! git diff --quiet || ! git diff --cached --quiet; then
echo "[agent-branch-start] Working tree is not clean. Commit/stash changes before starting an in-place branch." >&2
exit 1
Expand Down
Loading