Skip to content

[auto-research 1.1] Auto-init git repo in create_worktree #830

@Trecek

Description

@Trecek

Part of Unit 1 — Local-mode empty-folder unblock (P0) from the auto-research master plan.

Scope

Prepend an idempotent git init + empty commit guard to the create_worktree step's cmd: block in research.yaml so that the recipe can run in a folder with no pre-existing .git directory. Local mode is expected to set up a local git repo automatically; the user retains the decision about whether to push to a remote afterward.

Rationale

Without this, the recipe fails at the first execution step in an empty folder — git worktree add requires an existing git repo. autoskillit init does not run git init. This is the primary blocker preventing a user from opening Claude Code in an empty folder and running the research recipe cold.

Files

  • src/autoskillit/recipes/research.yaml (step create_worktree, cmd block around line 208; note block around line 249)

Proposed change

Prepend to the existing cmd block:

if [ ! -d .git ]; then
  git init -q && git commit --allow-empty -m "autoskillit: init for research recipe" -q;
fi &&

Update the note block to document that the step auto-initializes a git repo when needed.

Acceptance criteria

  • Running the research recipe in a previously empty folder succeeds at create_worktree
  • Running in a folder that already has .git has NO behavior change (idempotency verified)
  • A test asserts the guard is present (string-match on the cmd block acceptable)
  • The guard is PREPENDED at the start, not appended (runs before existing commands)
  • task test-check passes

Relevant context diagram (C.8 — empty-folder timeline excerpt)

  t=0    $ cd /home/talon/runx1t1-research   (empty folder)
  t=0    $ claude                             (Tier 1 session opens)
  t=1    /autoskillit:order research task="..." output_mode=local
               │
               ▼
  PHASE 2 ── WORKTREE CREATION
    create_wkt. ── run_cmd →
                   ↳ ✖ FAILS unless this guard is applied (needs .git)
                   ↳ ✓ With guard: git init runs first, then git worktree add
                   ↳ creates ../worktrees/research-{timestamp}/

Hand-off notes

An empty initial commit is required because git worktree add -b needs at least one commit to branch from. Do not reorder any existing commands. See also Work Item 1.2 for the complementary push_branch fix — both must land together for local mode to work end-to-end in empty folders.

Dependencies


From master plan: .autoskillit/temp/runx1t1-preflight.md §11, Unit 1 + §11.5.1


Addendum (2026-05-03 codebase audit)

The fix location described above is incorrect for the current codebase. The create_worktree step (line 206 of research.yaml) no longer has an inline cmd: block with bash commands. It delegates entirely to an external shell script:

cmd: "bash scripts/recipe/create_worktree.sh '${{ inputs.source_dir }}' '${{ inputs.task }}' ..."

The git-init guard must be added inside scripts/recipe/create_worktree.sh (before line 17, which runs git -C "$SOURCE_DIR" worktree add ...), not prepended to the YAML cmd: value.

Test file correction: tests/recipe/test_bundled_recipes.py no longer exists. The bundled-recipe tests were split into per-recipe files. The correct target is tests/recipe/test_bundled_recipes_research.py or tests/recipe/test_research_recipe_diag.py.

Step line number: The create_worktree step is at line 206 (not 208 as originally stated — minor drift).

Metadata

Metadata

Assignees

No one assigned

    Labels

    recipe:implementationRoute: proceed directly to implementationstagedImplementation staged and waiting for promotion to main

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions