Skip to content

Commit 6b93c37

Browse files
NagyViktNagyVikt
andauthored
Restore missing branch-start assets so doctor branches can finish safely (#43)
Repeated gx doctor sandboxes were left dirty because essential guardex-managed entries were absent and had to be regenerated each run. This commit captures those repairs so new doctor branches stop repeating the same drift. Constraint: Keep protected main read-only; changes must flow through agent branch PR Rejected: Drop doctor-generated changes locally per run | branch state keeps regressing Confidence: medium Scope-risk: narrow Reversibility: clean Directive: If doctor keeps recreating the same files, merge the first repair branch before rerunning doctor Tested: gx scan output before/after doctor on main workspace Not-tested: full npm test suite Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
1 parent d0a38ff commit 6b93c37

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ scripts/install-agent-git-hooks.sh
1212
scripts/openspec/init-plan-workspace.sh
1313
.githooks/pre-commit
1414
oh-my-codex/
15-
.codex/skills/musafety/SKILL.md
16-
.claude/commands/musafety.md
15+
.codex/skills/guardex/SKILL.md
16+
.claude/commands/guardex.md
1717
.omx/state/agent-file-locks.json
1818
# multiagent-safety:END

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"agent:codex": "bash ./scripts/codex-agent.sh",
1616
"agent:branch:start": "bash ./scripts/agent-branch-start.sh",
1717
"agent:branch:finish": "bash ./scripts/agent-branch-finish.sh",
18-
"agent:cleanup": "bash ./scripts/agent-worktree-prune.sh --base dev",
18+
"agent:cleanup": "gx cleanup",
1919
"agent:hooks:install": "bash ./scripts/install-agent-git-hooks.sh",
2020
"agent:locks:claim": "python3 ./scripts/agent-file-locks.py claim",
2121
"agent:locks:allow-delete": "python3 ./scripts/agent-file-locks.py allow-delete",

scripts/agent-branch-start.sh

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
TASK_NAME="${1:-task}"
5-
AGENT_NAME="${2:-agent}"
6-
BASE_BRANCH="${3:-}"
4+
TASK_NAME="task"
5+
AGENT_NAME="agent"
6+
BASE_BRANCH=""
77
BASE_BRANCH_EXPLICIT=0
88
WORKTREE_MODE=1
9+
ALLOW_IN_PLACE=0
910
WORKTREE_ROOT_REL=".omx/agent-worktrees"
10-
11-
if [[ -n "${3:-}" ]]; then
12-
BASE_BRANCH_EXPLICIT=1
13-
fi
11+
POSITIONAL_ARGS=()
1412

1513
while [[ $# -gt 0 ]]; do
1614
case "$1" in
@@ -31,25 +29,53 @@ while [[ $# -gt 0 ]]; do
3129
WORKTREE_MODE=0
3230
shift
3331
;;
32+
--allow-in-place)
33+
ALLOW_IN_PLACE=1
34+
shift
35+
;;
3436
--worktree-root)
3537
WORKTREE_ROOT_REL="${2:-.omx/agent-worktrees}"
3638
shift 2
3739
;;
3840
--)
3941
shift
42+
while [[ $# -gt 0 ]]; do
43+
POSITIONAL_ARGS+=("$1")
44+
shift
45+
done
4046
break
4147
;;
4248
-*)
4349
echo "[agent-branch-start] Unknown option: $1" >&2
44-
echo "Usage: $0 [task] [agent] [base] [--in-place] [--worktree-root <path>]" >&2
50+
echo "Usage: $0 [task] [agent] [base] [--in-place --allow-in-place] [--worktree-root <path>]" >&2
4551
exit 1
4652
;;
4753
*)
48-
break
54+
POSITIONAL_ARGS+=("$1")
55+
shift
4956
;;
5057
esac
5158
done
5259

60+
if [[ "${#POSITIONAL_ARGS[@]}" -gt 3 ]]; then
61+
echo "[agent-branch-start] Too many positional arguments." >&2
62+
echo "Usage: $0 [task] [agent] [base] [--in-place --allow-in-place] [--worktree-root <path>]" >&2
63+
exit 1
64+
fi
65+
66+
if [[ "${#POSITIONAL_ARGS[@]}" -ge 1 ]]; then
67+
TASK_NAME="${POSITIONAL_ARGS[0]}"
68+
fi
69+
70+
if [[ "${#POSITIONAL_ARGS[@]}" -ge 2 ]]; then
71+
AGENT_NAME="${POSITIONAL_ARGS[1]}"
72+
fi
73+
74+
if [[ "${#POSITIONAL_ARGS[@]}" -ge 3 ]]; then
75+
BASE_BRANCH="${POSITIONAL_ARGS[2]}"
76+
BASE_BRANCH_EXPLICIT=1
77+
fi
78+
5379
sanitize_slug() {
5480
local raw="$1"
5581
local fallback="${2:-task}"
@@ -180,6 +206,12 @@ if git show-ref --verify --quiet "refs/heads/${branch_name}"; then
180206
fi
181207

182208
if [[ "$WORKTREE_MODE" -eq 0 ]]; then
209+
if [[ "$ALLOW_IN_PLACE" -ne 1 ]]; then
210+
echo "[agent-branch-start] --in-place is blocked by default to prevent accidental edits on protected branches." >&2
211+
echo "[agent-branch-start] If you really need it, pass both: --in-place --allow-in-place" >&2
212+
exit 1
213+
fi
214+
183215
if ! git diff --quiet || ! git diff --cached --quiet; then
184216
echo "[agent-branch-start] Working tree is not clean. Commit/stash changes before starting an in-place branch." >&2
185217
exit 1

0 commit comments

Comments
 (0)