Skip to main content

Hook-agnostic git-worktree engine for the ai-hats framework (WorktreeManager + the L1-L4 concurrency model).

Project description

ai-hats-wt

A hook-agnostic git-worktree engine: create, merge, and discard linked git worktrees with a layered file-locking concurrency model — from a bare git repository, with no configuration.

ai-hats-wt is the worktree core extracted from the ai-hats framework. It has no dependency on ai-hats: everything below runs against a plain git init with no ai-hats.yaml, no composition, and no tracker. Its only runtime dependencies are ai-hats-core (dependency-free filesystem primitives) and filelock.

Install

pip install ai-hats-wt

Requires Python 3.11+.

Quickstart

Drive the full create → merge (or → discard) lifecycle on any git repo:

from pathlib import Path
from ai_hats_wt import WorktreeManager

project = Path("/path/to/a/git/repo")

# A manager for one linked worktree on its own branch.
mgr = WorktreeManager(project, branch_name="feature/x")

wt_path = mgr.create()   # linked worktree checked out on feature/x
mgr.save_state()         # persist state under <project>/.wt

# ... make commits inside wt_path ...

mgr.merge()              # land the branch on the base, remove the worktree
# or:
# mgr.discard()          # throw the worktree + branch away, land nothing

That is the entire happy path. WorktreeManager defaults to the no-op lifecycle and a project-local state directory (<project>/.wt), so a bare consumer needs nothing else. The same flow is exercised end-to-end by the package's test_wt_standalone.py.

Public API

The supported surface is ai_hats_wt.__all__:

Symbol Purpose
WorktreeManager Create / merge / discard a linked worktree; the git probes.
IsolationMode Isolation / teardown mode (DISCARD, SQUASH, BRANCH, NONE).
assert_head_is_canonical_base Guard: refuse to branch off a non-canonical HEAD.
WorktreeLifecycle, LifecycleContext, NOOP_LIFECYCLE The lifecycle extension-point (see below).
WorktreeDirtyError, WorktreeCreateError, WorktreeDriftError, … Typed exceptions — the clean failure seam.

The full exception set (WorktreePartialCleanupError, WorktreeRemoveError, OriginalBranchMissingError, WorktreeStateLostError, WorktreeStateIncompleteError, WorktreeBaseBranchError, WorktreeBaseBranchMismatchError, WorktreeMainRepoMidMergeError, WorktreeTeardownAborted, WorktreeLockError) lets a host catch precise failures instead of parsing git stderr. Per-method behaviour is documented on the code — import a symbol and read its docstring; this README is the entry point, not the reference.

Lifecycle hooks (extension-point)

WorktreeManager runs no hooks by default (NOOP_LIFECYCLE). A host can inject behaviour at the create/merge/discard boundaries by passing its own WorktreeLifecycle bundle:

from ai_hats_wt import WorktreeManager, WorktreeLifecycle, LifecycleContext

class MyLifecycle(WorktreeLifecycle):
    def on_created(self, ctx: LifecycleContext) -> None:
        ...  # e.g. seed files into ctx.worktree_path

    def before_teardown(self, event: str, ctx: LifecycleContext) -> None:
        ...  # event is "merge" / "discard" / "cleanup"

mgr = WorktreeManager(project, branch_name="feature/x", lifecycle=MyLifecycle())

This is the seam ai-hats uses to run its own carry/hook layer; a standalone consumer typically leaves the default no-op in place.

Concurrency

Worktree operations are serialized by a layered file-locking model (state locks, git-index-lock retry, ref-lock waits) so that concurrent create / merge calls on the same repo do not corrupt each other. It is on by default; there is nothing to configure.

Dependencies

Everything else is the Python standard library.

Versioning

SemVer. The public API is ai_hats_wt.__all__; breaking changes to it bump the major version. Submodule internals (anything not in __all__) are not part of the contract.

License

MIT. See the ai-hats repository for the full license and contribution guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_hats_wt-0.4.2.tar.gz (49.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_hats_wt-0.4.2-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_hats_wt-0.4.2.tar.gz.

File metadata

  • Download URL: ai_hats_wt-0.4.2.tar.gz
  • Upload date:
  • Size: 49.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ai_hats_wt-0.4.2.tar.gz
Algorithm Hash digest
SHA256 364c45b6c6a848e0b2df5b9aecc053b55db8d867fb03ce09f0b77fdbf10a0e9a
MD5 897a064d388cd6e5e40fbb9b24636d29
BLAKE2b-256 0de3e948a993b28d701ea8db8fc2d1bbe085f4472bee6d6498068bc987c426c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_hats_wt-0.4.2.tar.gz:

Publisher: release-packages.yml on muratovv/ai-hats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_hats_wt-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: ai_hats_wt-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ai_hats_wt-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 065af90e3e95211199fe1f788156d0ccc142ef7a85953d786d81e89a5b33cbed
MD5 5b6b64f20bde3dc1510c477c9c0ddf25
BLAKE2b-256 ee88cc566145016a076fecf815922183639d299ec55d55b73bfa09af6d2bbcad

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_hats_wt-0.4.2-py3-none-any.whl:

Publisher: release-packages.yml on muratovv/ai-hats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page