Skip to content

API Reference parrot.sdd.scripts.ensure_worktree

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.sdd.scripts.ensure_worktree

View source

Idempotent feature/hotfix worktree provisioning for SDD commands (FEAT-552).

Replaces the hand-rolled git worktree add blocks that used to live in /sdd-task, /sdd-start, sdd-worker, sdd-planner, sdd-research and sdd-autopilot. Naming and base ref come from scripts.sdd.sdd_meta.plan_worktree — never built here.

Class EnsureWorktreeError

Raised when the worktree cannot be provisioned (CLI exit code 1).

Attribute NativeSyncReport

Alias WorktreePlan

Re-exported from parrot.sdd.scripts.sdd_meta.WorktreePlan.

Alias brief_worktree_plan

Re-exported from parrot.sdd.scripts.brief_meta.brief_worktree_plan.

Function ensure

Create the worktree if absent, reuse it if present, and verify it.

Steps, in order:

  1. Reuse — if git worktree list --porcelain already lists a worktree whose path basename is plan.name, confirm its checked-out branch is plan.name and return it. A path holding a DIFFERENT branch is an error, never a silent reuse.
  2. Sync (skipped when sync is False) — git fetch origin <base_branch>. No local branch is checked out; no local commit moves.
  3. Refuse when a branch named plan.name exists but is checked out nowhere — the operator decides (reuse it, or pick another slug).
  4. Create — git worktree add -b <name> <path> <base_ref>.
  5. Verify — every require_paths entry must exist inside the worktree. A miss means the base does not carry the task artifacts yet: the new worktree and branch are discarded, and when the paths are only on an unpushed local <base_branch> the error says to push it.
  6. Return (absolute_path, created).

ensure(plan: WorktreePlan, *, repo_root: Path, sync: bool = True, require_paths: Sequence[str] = (), dry_run: bool = False) -> tuple[Path, bool]

Parameter Type Default Description
plan WorktreePlan The naming/base-ref decision from plan_worktree.
repo_root Path Absolute path to the main clone.
sync bool True Fetch origin/<base_branch> before creating.
require_paths Sequence[str] () Repo-relative paths that must exist in the worktree.
dry_run bool False Resolve and report without running any mutating git command.

Returns: tuple[Path, bool] — (path, created) — created is False when an existing worktree was reused.

Raises:

  • EnsureWorktreeError — On any refusal above, or a failing git command.

Alias load_sdd_config

Re-exported from parrot.sdd.config.load_sdd_config.

Attribute logger

Function main

CLI entry point. Prints the worktree path to stdout; 0 on success.

With --json, prints one object instead — {"name": …, "path": …, "base_ref": …, "created": bool} — so sdd-planner/sdd-research can lift worktree_path straight into their PlannerOutput/ResearchOutput contracts (spec §8).

main(argv: Sequence[str] | None = None) -> int

Parameter Type Default Description
argv Sequence[str] | None None

Returns: int

Alias plan_worktree

Re-exported from parrot.sdd.scripts.sdd_meta.plan_worktree.

Alias resolve_flow

Re-exported from parrot.sdd.scripts.sdd_meta.resolve_flow.

Attribute sync_native_artifacts

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally