Something went wrong. Try again.
A video game where you play as a misaligned AI, deceiving and building power. An experiment in spec-driven development. forked from cameron.stream/misaligned
Something went wrong. Try again.
3.1 kB · 122 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123#!/usr/bin/env bash# Create a seeded task worktree and optionally record local task activity.# Binding: wiki/process/agent-scale.md slices A + D.## Usage:# tools/worktree-new.sh <task> [--class <docs|frontend|sim|save|process>] \# [--key path]... [--no-seed] [--no-activity]## Creates (default; override root with MISALIGNED_WORKTREE_ROOT):# .Codex/worktrees/<task> on branch worktree-<task> from origin/main# Runs tools/seed-cargo-target.sh unless --no-seed.# Records <task> with the given class/paths unless --no-activity. `--no-claim`# remains a compatibility alias. Overlap is advisory; the worktree is isolation.set -euo pipefail
script_root=$(cd "$(dirname "$0")/.." && pwd)primary=$script_rootif [ -f "$script_root/.git" ]; then common=$(git -C "$script_root" rev-parse --path-format=absolute --git-common-dir) case "$common" in */.git) primary=${common%/.git} ;; esacficd "$primary"
worktree_root=${MISALIGNED_WORKTREE_ROOT:-.Codex/worktrees}case "$worktree_root" in /*) ;; *) worktree_root="$primary/$worktree_root" ;;esac
usage() { sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//' exit 2}
task=""class=""seed=1do_claim=1keys=()
while [ $# -gt 0 ]; do case "$1" in --class) shift; class="${1:-}"; shift || true ;; --key) shift; keys+=("${1:-}"); shift || true ;; --no-seed) seed=0; shift ;; --no-activity|--no-claim) do_claim=0; shift ;; -h|--help) usage ;; -*) echo "unknown flag: $1" >&2 usage ;; *) if [ -z "$task" ]; then task=$1 shift else usage fi ;; esacdone
[ -n "$task" ] || usagecase "$task" in */*|*" "*|worktree-*) echo "FAIL: task name should be a short slug (e.g. dark-frame), not '$task'" >&2 exit 2 ;;esac
git fetch origin 2>/dev/null || trueif ! git rev-parse --verify origin/main >/dev/null 2>&1; then echo "FAIL: origin/main not available; fetch first" >&2 exit 1fi
wt="$worktree_root/$task"branch="worktree-$task"
if [ -e "$wt" ]; then echo "FAIL: worktree path already exists: $wt" >&2 exit 1fiif git show-ref --verify --quiet "refs/heads/$branch"; then echo "FAIL: branch $branch already exists" >&2 exit 1fi
echo "worktree-new: creating $wt on $branch from origin/main"mkdir -p "$worktree_root"git worktree add -b "$branch" "$wt" origin/main
if [ "$seed" -eq 1 ]; then echo "worktree-new: seeding cargo target" (cd "$wt" && bash tools/seed-cargo-target.sh) || \ echo "worktree-new: seed skipped or failed (ok if no primary target cache)"fi
if [ "$do_claim" -eq 1 ]; then if [ -z "$class" ]; then class=process fi claim_args=(activity "$task" --class "$class") for k in "${keys[@]+"${keys[@]}"}"; do claim_args+=(--key "$k") done bash "$primary/tools/claim.sh" "${claim_args[@]}"fi
cat <<EOF
worktree-new: ready path: $wt branch: $branch next: cd $wt # mid-loop: ./tools/check.sh --docs|--lib|--frontend (or auto) # land: ./tools/check.sh --land # release: tools/worktree-done.sh $taskEOF