Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Consolidate demo infrastructure and merge improvements

Maximilian Roos5b799ea13ae9
diff --git a/docs/demos/shared/__init__.py b/docs/demos/shared/__init__.py
index 82bf77e73..a0fb39b59 100644
--- a/docs/demos/shared/__init__.py
+++ b/docs/demos/shared/__init__.py
@@ -13,6 +13,11 @@ from .lib import (
prepare_base_repo,
setup_gh_mock,
prepare_demo_repo,
+ # Demo recording infrastructure
+ check_dependencies,
+ setup_demo_output,
+ build_shell_env,
+ record_all_themes,
)
from .themes import THEMES, format_theme_for_vhs
@@ -31,4 +36,9 @@ __all__ = [
"prepare_demo_repo",
"THEMES",
"format_theme_for_vhs",
+ # Demo recording infrastructure
+ "check_dependencies",
+ "setup_demo_output",
+ "build_shell_env",
+ "record_all_themes",
]
diff --git a/docs/demos/shared/lib.py b/docs/demos/shared/lib.py
index 72afcef67..99fe70044 100644
--- a/docs/demos/shared/lib.py
+++ b/docs/demos/shared/lib.py
@@ -7,6 +7,8 @@ from dataclasses import dataclass
from datetime import datetime, timedelta
from pathlib import Path
+from .themes import THEMES, format_theme_for_vhs
+
REAL_HOME = Path.home()
FIXTURES_DIR = Path(__file__).parent / "fixtures"
@@ -344,3 +346,100 @@ def _create_branch_hooks(env: DemoEnv):
lib_rs.write_text(lib_rs.read_text() + "// Division coming soon\n")
git(["-C", str(path), "add", "src/lib.rs"])
lib_rs.write_text(lib_rs.read_text() + "// TODO: add division\n")
+
+
+# =============================================================================
+# Demo recording infrastructure
+# =============================================================================
+
+
+def check_dependencies(commands: list[str]):
+ """Check that required commands are available, exit if not."""
+ for cmd in commands:
+ if not shutil.which(cmd):
+ raise SystemExit(f"Missing dependency: {cmd}")
+
+
+def setup_demo_output(out_dir: Path) -> Path:
+ """Set up demo output directory and copy starship config.
+
+ Returns the path to the starship config file.
+ """
+ out_dir.mkdir(parents=True, exist_ok=True)
+ starship_config = out_dir / "starship.toml"
+ shutil.copy(FIXTURES_DIR / "starship.toml", starship_config)
+ return starship_config
+
+
+def build_shell_env(demo_env: "DemoEnv", repo_root: Path, extra: dict = None) -> dict:
+ """Build environment dict for running shell commands in demo context.
+
+ Includes wt, fish, starship setup with isolated HOME.
+ """
+ starship_config = demo_env.out_dir / "starship.toml"
+ starship_cache = demo_env.root / "starship-cache"
+ starship_cache.mkdir(exist_ok=True)
+
+ env = os.environ.copy()
+ env.update({
+ "LANG": "en_US.UTF-8",
+ "LC_ALL": "en_US.UTF-8",
+ "COLUMNS": "140",
+ "RUSTUP_HOME": str(REAL_HOME / ".rustup"),
+ "CARGO_HOME": str(REAL_HOME / ".cargo"),
+ "HOME": str(demo_env.home),
+ "PATH": f"{repo_root}/target/debug:{demo_env.home}/bin:{os.environ['PATH']}",
+ "STARSHIP_CONFIG": str(starship_config),
+ "STARSHIP_CACHE": str(starship_cache),
+ "NO_COLOR": "1",
+ "CLICOLOR": "0",
+ })
+ if extra:
+ env.update(extra)
+ return env
+
+
+def record_all_themes(
+ demo_env: "DemoEnv",
+ tape_template: Path,
+ output_gifs: dict[str, Path],
+ repo_root: Path,
+ vhs_binary: str = "vhs",
+):
+ """Record demo GIFs for all themes.
+
+ Args:
+ demo_env: Demo environment with repo and home paths
+ tape_template: Path to the .tape template file
+ output_gifs: Dict of theme_name -> output GIF path (e.g., {"light": path, "dark": path})
+ repo_root: Path to worktrunk repo root (for target/debug)
+ vhs_binary: VHS binary to use (default "vhs", can be path to custom build)
+ """
+ tape_rendered = demo_env.out_dir / ".rendered.tape"
+ starship_config = demo_env.out_dir / "starship.toml"
+ docs_assets = repo_root / "docs" / "static" / "assets"
+ docs_assets.mkdir(parents=True, exist_ok=True)
+
+ for theme_name, output_gif in output_gifs.items():
+ theme = THEMES[theme_name]
+ replacements = {
+ "DEMO_REPO": demo_env.repo,
+ "DEMO_HOME": demo_env.home,
+ "REAL_HOME": REAL_HOME,
+ "STARSHIP_CONFIG": starship_config,
+ "OUTPUT_GIF": output_gif,
+ "TARGET_DEBUG": repo_root / "target" / "debug",
+ "THEME": format_theme_for_vhs(theme),
+ }
+
+ if not render_tape(tape_template, tape_rendered, replacements):
+ continue
+
+ print(f"\nRecording {theme_name} GIF...")
+ record_vhs(tape_rendered, vhs_binary)
+ tape_rendered.unlink(missing_ok=True)
+ print(f"GIF saved to {output_gif}")
+
+ # Copy to docs for local preview
+ shutil.copy(output_gif, docs_assets / output_gif.name)
+ print(f"Copied to {docs_assets / output_gif.name}")
diff --git a/docs/demos/wt-core/build b/docs/demos/wt-core/build
index f4989b6ff..f6909f89c 100755
--- a/docs/demos/wt-core/build
+++ b/docs/demos/wt-core/build
@@ -10,9 +10,7 @@ This demo shows the core workflow with hooks:
6. wt remove - remove worktree with pre-remove hook
"""
-import os
import re
-import shutil
import subprocess
import sys
from pathlib import Path
@@ -23,17 +21,14 @@ DEMOS_DIR = SCRIPT_DIR.parent
sys.path.insert(0, str(DEMOS_DIR))
from shared import (
- DemoEnv, run, git, render_tape, record_vhs, REAL_HOME, FIXTURES_DIR,
- prepare_demo_repo, commit_dated, THEMES, format_theme_for_vhs,
+ DemoEnv, git, prepare_demo_repo,
+ check_dependencies, setup_demo_output, build_shell_env, record_all_themes,
)
REPO_ROOT = DEMOS_DIR.parent.parent
OUT_DIR = SCRIPT_DIR / "out"
TAPE_TEMPLATE = SCRIPT_DIR / "demo.tape"
-TAPE_RENDERED = OUT_DIR / ".rendered.tape"
-STARSHIP_CONFIG = OUT_DIR / "starship.toml"
-# Output GIF paths for light and dark variants
OUTPUT_GIFS = {
"light": OUT_DIR / "wt-core.gif",
"dark": OUT_DIR / "wt-core-dark.gif",
@@ -42,7 +37,6 @@ OUTPUT_GIFS = {
def prepare_repo(env: DemoEnv):
"""Set up the demo repository with branches and worktrees."""
- # Use shared rich repo setup with custom hooks config
hooks_config = '''[post-start]
dev = "npm run dev"
@@ -75,7 +69,6 @@ fi
flyctl_mock.chmod(0o755)
# Demo-specific: user config with approved commands
- # Project ID for local path is the path without .git suffix
config_dir = env.home / ".config" / "worktrunk"
project_id = str(env.bare_remote).removesuffix(".git")
(config_dir / "config.toml").write_text(f'''[projects."{project_id}"]
@@ -90,15 +83,12 @@ def create_branch_billing(env: DemoEnv):
"""Create billing branch that's already merged (at same commit as main)."""
branch = "billing"
path = env.work_base / f"acme.{branch}"
-
- # Create worktree at main's commit (so it shows as merged/safe to delete)
git(["-C", str(env.repo), "worktree", "add", "-q", "-b", branch, str(path), "main"])
git(["-C", str(path), "push", "-u", "origin", branch, "-q"])
def record_text(demo_env: DemoEnv):
"""Record text output by running demo commands."""
- # Commands to run (matching demo.tape)
commands = [
"wt list",
"wt switch alpha",
@@ -109,23 +99,7 @@ def record_text(demo_env: DemoEnv):
"wt remove",
]
- # Set up environment
- env = os.environ.copy()
- env.update({
- "LANG": "en_US.UTF-8",
- "LC_ALL": "en_US.UTF-8",
- "COLUMNS": "140",
- "RUSTUP_HOME": str(REAL_HOME / ".rustup"),
- "CARGO_HOME": str(REAL_HOME / ".cargo"),
- "HOME": str(demo_env.home),
- "PATH": f"{REPO_ROOT}/target/debug:{demo_env.home}/bin:{os.environ['PATH']}",
- "STARSHIP_CONFIG": str(STARSHIP_CONFIG),
- "STARSHIP_CACHE": str(demo_env.root / "starship-cache"),
- "NO_COLOR": "1",
- "CLICOLOR": "0",
- })
-
- (demo_env.root / "starship-cache").mkdir(exist_ok=True)
+ env = build_shell_env(demo_env, REPO_ROOT)
# Run commands and capture output using fish with shell init
script = "wt config shell init fish | source\n"
@@ -147,18 +121,10 @@ def record_text(demo_env: DemoEnv):
def main():
- # Check dependencies
- for cmd in ["wt", "vhs", "starship", "bat"]:
- if not shutil.which(cmd):
- raise SystemExit(f"Missing dependency: {cmd}")
-
- OUT_DIR.mkdir(parents=True, exist_ok=True)
-
- # Copy starship config from fixtures
- shutil.copy(FIXTURES_DIR / "starship.toml", STARSHIP_CONFIG)
+ check_dependencies(["wt", "vhs", "starship", "bat"])
+ setup_demo_output(OUT_DIR)
# Create separate environments for text and VHS recording
- # so they don't interfere with each other
text_env = DemoEnv(name="text", out_dir=OUT_DIR, repo_name="acme")
vhs_env = DemoEnv(name="vhs", out_dir=OUT_DIR, repo_name="acme")
@@ -166,32 +132,7 @@ def main():
record_text(text_env)
prepare_repo(vhs_env)
-
- # Record both light and dark variants
- docs_assets = REPO_ROOT / "docs" / "static" / "assets"
- docs_assets.mkdir(parents=True, exist_ok=True)
-
- for theme_name, output_gif in OUTPUT_GIFS.items():
- theme = THEMES[theme_name]
- replacements = {
- "DEMO_REPO": vhs_env.repo,
- "DEMO_HOME": vhs_env.home,
- "REAL_HOME": REAL_HOME,
- "STARSHIP_CONFIG": STARSHIP_CONFIG,
- "OUTPUT_GIF": output_gif,
- "TARGET_DEBUG": REPO_ROOT / "target" / "debug",
- "THEME": format_theme_for_vhs(theme),
- }
- render_tape(TAPE_TEMPLATE, TAPE_RENDERED, replacements)
- print(f"\nRecording {theme_name} GIF...")
- record_vhs(TAPE_RENDERED)
- TAPE_RENDERED.unlink(missing_ok=True)
- print(f"GIF saved to {output_gif}")
-
- # Copy to docs for local preview
- asset_name = output_gif.name
- shutil.copy(output_gif, docs_assets / asset_name)
- print(f"Copied to {docs_assets / asset_name}")
+ record_all_themes(vhs_env, TAPE_TEMPLATE, OUTPUT_GIFS, REPO_ROOT)
print(f"\nText log saved to {OUT_DIR / 'run.txt'}")
diff --git a/docs/demos/wt-merge/build b/docs/demos/wt-merge/build
index 195f17982..740a69834 100755
--- a/docs/demos/wt-merge/build
+++ b/docs/demos/wt-merge/build
@@ -1,12 +1,9 @@
#!/usr/bin/env python3
"""Build script for wt-merge demo GIF."""
-import os
import re
-import shutil
import subprocess
import sys
-from datetime import datetime, timedelta
from pathlib import Path
# Add docs/demos/ to path for shared library
@@ -15,17 +12,14 @@ DEMOS_DIR = SCRIPT_DIR.parent
sys.path.insert(0, str(DEMOS_DIR))
from shared import (
- DemoEnv, run, git, render_tape, record_vhs, REAL_HOME, FIXTURES_DIR,
- prepare_demo_repo, THEMES, format_theme_for_vhs,
+ DemoEnv, prepare_demo_repo,
+ check_dependencies, setup_demo_output, build_shell_env, record_all_themes,
)
REPO_ROOT = DEMOS_DIR.parent.parent
OUT_DIR = SCRIPT_DIR / "out"
TAPE_TEMPLATE = SCRIPT_DIR / "demo.tape"
-TAPE_RENDERED = OUT_DIR / ".rendered.tape"
-STARSHIP_CONFIG = OUT_DIR / "starship.toml"
-# Output GIF paths for light and dark variants
OUTPUT_GIFS = {
"light": OUT_DIR / "wt-merge.gif",
"dark": OUT_DIR / "wt-merge-dark.gif",
@@ -34,10 +28,9 @@ OUTPUT_GIFS = {
def prepare_repo(env: DemoEnv):
"""Set up the demo repository using shared setup plus wt-specific config."""
- # Use shared rich repo setup
prepare_demo_repo(env, REPO_ROOT)
- # wt demo-specific: user config with llm commit generation
+ # wt-merge demo-specific: user config with llm commit generation
config_dir = env.home / ".config" / "worktrunk"
project_id = str(env.bare_remote).removesuffix(".git")
(config_dir / "config.toml").write_text(f'''[commit-generation]
@@ -56,34 +49,19 @@ def record_text(demo_env: DemoEnv):
for line in TAPE_TEMPLATE.read_text().splitlines():
if line.startswith("Type "):
cmd = line[5:].strip().strip('"').strip("'")
- # Skip setup commands (fish uses 'set -gx' instead of 'export')
+ # Skip setup commands
if not any(cmd.startswith(p) for p in ["set -gx", "export ", "eval ", "cd ", "clear", "exit", "starship init", "wt config shell init"]):
commands.append(cmd)
- # Set up environment
- env = os.environ.copy()
- env.update({
- "LANG": "en_US.UTF-8",
- "LC_ALL": "en_US.UTF-8",
+ env = build_shell_env(demo_env, REPO_ROOT, extra={
"COLUMNS": "160",
- "RUSTUP_HOME": str(REAL_HOME / ".rustup"),
- "CARGO_HOME": str(REAL_HOME / ".cargo"),
- "HOME": str(demo_env.home),
- "PATH": f"{REPO_ROOT}/target/debug:{demo_env.home}/bin:{os.environ['PATH']}",
- "STARSHIP_CONFIG": str(STARSHIP_CONFIG),
- "STARSHIP_CACHE": str(demo_env.root / "starship-cache"),
- "NO_COLOR": "1",
- "CLICOLOR": "0",
"NEXTEST_STATUS_LEVEL": "none",
"NEXTEST_FINAL_STATUS_LEVEL": "flaky",
"NEXTEST_NO_FAIL_FAST": "1",
})
- (demo_env.root / "starship-cache").mkdir(exist_ok=True)
-
# Run commands and capture output using fish with shell init
- script = '''wt config shell init fish | source
-'''
+ script = "wt config shell init fish | source\n"
for cmd in commands:
script += f'{cmd}\n'
if cmd.startswith("wt merge"):
@@ -94,11 +72,10 @@ def record_text(demo_env: DemoEnv):
cwd=demo_env.repo, env=env,
capture_output=True, text=True
)
- output = [result.stdout + result.stderr]
+ output = result.stdout + result.stderr
# Clean output
- raw = "".join(output)
- clean = re.sub(r"\x1B\[[0-9;?]*[A-Za-z]", "", raw) # Strip ANSI
+ clean = re.sub(r"\x1B\[[0-9;?]*[A-Za-z]", "", output) # Strip ANSI
clean = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", clean) # Strip control chars
clean = clean.replace("^D", "")
@@ -106,18 +83,10 @@ def record_text(demo_env: DemoEnv):
def main():
- # Check dependencies
- for cmd in ["wt", "vhs", "starship"]:
- if not shutil.which(cmd):
- raise SystemExit(f"Missing dependency: {cmd}")
-
- OUT_DIR.mkdir(parents=True, exist_ok=True)
-
- # Copy starship config from fixtures
- shutil.copy(FIXTURES_DIR / "starship.toml", STARSHIP_CONFIG)
+ check_dependencies(["wt", "vhs", "starship"])
+ setup_demo_output(OUT_DIR)
# Create separate environments for text and VHS recording
- # so they don't interfere with each other (different LLM-generated commits)
text_env = DemoEnv(name="text", out_dir=OUT_DIR, repo_name="acme")
vhs_env = DemoEnv(name="vhs", out_dir=OUT_DIR, repo_name="acme")
@@ -125,32 +94,7 @@ def main():
record_text(text_env)
prepare_repo(vhs_env)
-
- # Record both light and dark variants
- docs_assets = REPO_ROOT / "docs" / "static" / "assets"
- docs_assets.mkdir(parents=True, exist_ok=True)
-
- for theme_name, output_gif in OUTPUT_GIFS.items():
- theme = THEMES[theme_name]
- replacements = {
- "DEMO_REPO": vhs_env.repo,
- "DEMO_HOME": vhs_env.home,
- "REAL_HOME": REAL_HOME,
- "STARSHIP_CONFIG": STARSHIP_CONFIG,
- "OUTPUT_GIF": output_gif,
- "TARGET_DEBUG": REPO_ROOT / "target" / "debug",
- "THEME": format_theme_for_vhs(theme),
- }
- render_tape(TAPE_TEMPLATE, TAPE_RENDERED, replacements)
- print(f"\nRecording {theme_name} GIF...")
- record_vhs(TAPE_RENDERED)
- TAPE_RENDERED.unlink(missing_ok=True)
- print(f"GIF saved to {output_gif}")
-
- # Copy to docs for local preview
- asset_name = output_gif.name
- shutil.copy(output_gif, docs_assets / asset_name)
- print(f"Copied to {docs_assets / asset_name}")
+ record_all_themes(vhs_env, TAPE_TEMPLATE, OUTPUT_GIFS, REPO_ROOT)
print(f"\nText log saved to {OUT_DIR / 'run.txt'}")
diff --git a/docs/demos/wt-select/build b/docs/demos/wt-select/build
index 9306514af..52a45093d 100755
--- a/docs/demos/wt-select/build
+++ b/docs/demos/wt-select/build
@@ -22,38 +22,14 @@ Key demonstration points:
- **main↕ column**: Some branches ahead-only, some ahead-and-behind
- **main…± column**: Meaningful commit diffs ranging from small to 300+ lines
-SETUP STRATEGY
-==============
-We start from v0.1.11 (BASE_COMMIT) because:
-1. It's a stable release point
-2. We can cherry-pick real commits for realistic diffs
-3. Many newer commits conflict with v0.1.11 files, so we use manual changes
-
-The setup process:
-1. Clone repo at BASE_COMMIT
-2. Create feature branches with cherry-picked commits (for main…± diffs)
-3. Advance main with MAIN_ADVANCE_COMMIT (so branches are "behind")
-4. Soft-reset streaming to main (creates large staged HEAD± diff)
-5. Add manual code changes (for additional HEAD± variety)
-6. Inject fake CI status cache (with future timestamp to prevent expiration)
-
-CI CACHE TRICK
-==============
-The CI status is cached in `.git/wt-cache/ci-status/<branch>.json` files. To show CI
-status without actual GitHub/GitLab access, we:
-1. Write fake CI cache entries directly to the cache files
-2. Use a future timestamp (1 hour ahead) so the cache never expires during recording
-3. VHS recording runs `wt select` which reads the cached CI status
-
-Without the future timestamp, the cache would expire during VHS recording,
-causing `wt list` to try to fetch CI status (which fails without remote),
-and then clear the cache.
+See CLAUDE.md for full setup details.
"""
+import json
import os
import shutil
-import subprocess
import sys
+import time
from datetime import datetime, timedelta
from pathlib import Path
@@ -63,25 +39,20 @@ DEMOS_DIR = SCRIPT_DIR.parent
sys.path.insert(0, str(DEMOS_DIR))
from shared import (
- DemoEnv, run, git, render_tape, record_vhs, build_wt, REAL_HOME, FIXTURES_DIR,
- THEMES, format_theme_for_vhs,
+ DemoEnv, run, git, build_wt,
+ check_dependencies, setup_demo_output, record_all_themes,
)
REPO_ROOT = DEMOS_DIR.parent.parent
OUT_DIR = SCRIPT_DIR / "out"
TAPE_TEMPLATE = SCRIPT_DIR / "demo.tape"
-TAPE_RENDERED = OUT_DIR / ".rendered.tape"
-STARSHIP_CONFIG = OUT_DIR / "starship.toml"
-# Output GIF paths for light and dark variants
OUTPUT_GIFS = {
"light": OUT_DIR / "wt-select.gif",
"dark": OUT_DIR / "wt-select-dark.gif",
}
# Custom VHS binary with keystroke overlay
-# Clone and build from: https://github.com/max-sixty/vhs/tree/keypress-overlay
-# Set to "vhs" to use system VHS (no keystroke overlay), or path to custom build
VHS_BINARY = os.environ.get("VHS_KEYSTROKES", str(SCRIPT_DIR / "vhs-keystrokes" / "vhs-keystrokes"))
# Base point for demo - v0.1.11 release
@@ -91,17 +62,12 @@ BASE_COMMIT = "005db9ad"
MAIN_ADVANCE_COMMIT = "50ffe925" # feat(tests): test env vars (+19/-20)
# Branch configuration - real commits to cherry-pick onto branches
-# branch_name: (commit_hash, days_ago)
-# NOTE: Use simple branch names without / to avoid path mismatch issues
CHERRY_PICKS = {
"streaming": ("cf667917", 1), # Handle BrokenPipe when LLM ignores stdin
"doctor": ("e286e847", 2), # Add wt config show --doctor option
"llm-templates": ("74fe46ff", 3), # Enhance squash message generation
}
-# Working tree changes - applied manually to create material diffs in HEAD± column
-# (cherry-picking fails because many commits touch files that don't exist in v0.1.11)
-
def commit_dated(repo, days_ago):
"""Amend commit with a date offset in days."""
@@ -115,42 +81,7 @@ def commit_dated(repo, days_ago):
def prepare_repo(env: DemoEnv):
- """Set up the demo repository with variety in all columns.
-
- This is carefully orchestrated to produce the target output. The sequence matters!
-
- Step 1: Clone at BASE_COMMIT (v0.1.11)
- - Stable base point where cherry-picks work
- - Creates: main at BASE_COMMIT
-
- Step 2: Create feature branches with cherry-picks (CHERRY_PICKS)
- - Each branch gets one real commit cherry-picked
- - Creates main…± diffs (doctor: +320, llm-templates: +263)
- - Backdates commits for Age column variety
-
- Step 3: Advance main with MAIN_ADVANCE_COMMIT
- - Makes feature branches "behind" main (↓1 in main↕)
- - doctor and llm-templates now show ↑1 ↓1
-
- Step 4: Add MAIN_ADVANCE_COMMIT to streaming
- - Makes streaming only "ahead" (not behind)
- - Prepares for soft reset in next step
-
- Step 5: Soft reset streaming to main
- - Moves HEAD back to main, keeping cherry-picked changes as staged
- - Creates large HEAD± diff (+54 -5) from staged changes
-
- Step 6: Add manual uncommitted changes
- - streaming: Additional staged code (+46 lines of error_handling.rs)
- - llm-templates: Unstaged changes (+8 lines) for ! in Status column
- - doctor: Left clean for variety
-
- Step 7: Inject fake CI status cache
- - main: green hollow ○ (branch CI, passed)
- - streaming: green filled ● (PR CI, passed)
- - doctor: blue filled ● (PR CI, running)
- - Uses future timestamp to prevent expiration during VHS recording
- """
+ """Set up the demo repository with variety in all columns."""
# Clean previous
shutil.rmtree(env.root, ignore_errors=True)
env.root.mkdir(parents=True)
@@ -195,10 +126,9 @@ base-path = "~/w"
add_commit_to_branch(env, "streaming", MAIN_ADVANCE_COMMIT)
# Soft reset streaming to main - all committed work becomes uncommitted
- # This creates a large HEAD± diff showing real feature work
soft_reset_to_main(env, "streaming")
- # Add smaller uncommitted working tree changes to other branches
+ # Add uncommitted working tree changes
add_uncommitted_changes(env)
# Add fake CI status for demo
@@ -209,21 +139,14 @@ def create_branch_with_cherry_pick(env: DemoEnv, branch_name: str, commit_hash:
"""Create a branch with a cherry-picked commit and worktree."""
print(f"Creating branch {branch_name} (cherry-pick {commit_hash})...")
- # Create branch from main (at BASE_COMMIT)
git(["-C", str(env.repo), "checkout", "-q", "main"])
git(["-C", str(env.repo), "checkout", "-q", "-b", branch_name])
-
- # Cherry-pick the commit
git(["-C", str(env.repo), "cherry-pick", "--no-commit", commit_hash])
- # Get original commit message
msg = run(["git", "-C", str(env.repo), "log", "-1", "--format=%s", commit_hash], capture=True).strip()
git(["-C", str(env.repo), "commit", "-m", msg])
-
- # Adjust commit date for realistic history display
commit_dated(env.repo, days_ago)
- # Create worktree
worktree_path = env.work_base / f"worktrunk.{branch_name}"
git(["-C", str(env.repo), "checkout", "-q", "main"])
git(["-C", str(env.repo), "worktree", "add", "-q", str(worktree_path), branch_name])
@@ -248,28 +171,16 @@ def add_commit_to_branch(env: DemoEnv, branch_name: str, commit_hash: str):
def soft_reset_to_main(env: DemoEnv, branch_name: str):
- """Soft reset a branch to main, keeping all changes as uncommitted.
-
- This creates a large HEAD± diff showing the full feature work.
- """
+ """Soft reset a branch to main, keeping all changes as uncommitted."""
print(f"Soft resetting {branch_name} to main...")
worktree_path = env.work_base / f"worktrunk.{branch_name}"
git(["-C", str(worktree_path), "reset", "--soft", "main"])
def add_uncommitted_changes(env: DemoEnv):
- """Add uncommitted working tree changes manually.
-
- Creates realistic WIP changes that look like in-progress work.
- - streaming: Large staged diff (~+50 -30) from soft reset + manual additions
- - llm-templates: Working on template validation (adds new function)
- - doctor: Clean (no uncommitted changes) to show variety
- """
- # streaming: Add substantial changes to create ~+50 -30 diff
- # The soft reset gives us +8 -5, so we add more to reach target
+ """Add uncommitted working tree changes manually."""
+ # streaming: Add substantial staged changes
streaming_path = env.work_base / "worktrunk.streaming"
-
- # Add new error handling module (~40 lines)
error_file = streaming_path / "src" / "error_handling.rs"
print("Adding staged changes to streaming...")
error_file.write_text('''//! Error handling utilities for pipe operations.
@@ -319,10 +230,9 @@ pub fn is_broken_pipe(err: &io::Error) -> bool {
err.kind() == ErrorKind::BrokenPipe
}
''')
- # Stage the new file
git(["-C", str(streaming_path), "add", "src/error_handling.rs"])
- # llm-templates: Add template validation WIP (+12 lines)
+ # llm-templates: Add unstaged changes
templates_path = env.work_base / "worktrunk.llm-templates"
llm_file = templates_path / "src" / "llm.rs"
if llm_file.exists():
@@ -342,86 +252,48 @@ fn validate_template(template: &str) -> Result<(), String> {
)
llm_file.write_text(content)
- # doctor: No changes (leave clean to show variety in demo)
-
def add_ci_status(env: DemoEnv):
- """Add fake CI status to file-based cache for demo.
-
- CI status is cached in .git/wt-cache/ci-status/<branch>.json files.
- The cache uses a future timestamp to prevent expiration during VHS recording.
- """
- import json
- import time
-
- # Use future timestamp to prevent cache expiration (TTL is 30-60 seconds)
- # VHS recording can take several minutes, so we set checked_at to 1 hour ahead
+ """Add fake CI status to file-based cache for demo."""
+ # Use future timestamp to prevent cache expiration
future_time = int(time.time()) + 3600
- # Get HEAD commits for each branch
def get_head(branch):
if branch == "main":
- # main is in the repo directly, not a linked worktree
return run(["git", "-C", str(env.repo), "rev-parse", "HEAD"], capture=True).strip()
worktree = env.work_base / f"worktrunk.{branch}"
return run(["git", "-C", str(worktree), "rev-parse", "HEAD"], capture=True).strip()
- # CI statuses to set:
- # - main: passed (green ○ hollow - branch CI, not PR)
- # - streaming: passed (green ● filled - PR CI)
- # - doctor: running (blue ● filled - PR CI)
ci_configs = {
"main": {
- "status": {
- "ci_status": "passed",
- "source": "branch", # hollow circle ○
- "is_stale": False,
- "url": None
- },
+ "status": {"ci_status": "passed", "source": "branch", "is_stale": False, "url": None},
"checked_at": future_time,
"head": get_head("main"),
},
"streaming": {
- "status": {
- "ci_status": "passed",
- "source": "pullrequest", # filled circle ●
- "is_stale": False,
- "url": "https://github.com/example/worktrunk/pull/85"
- },
+ "status": {"ci_status": "passed", "source": "pullrequest", "is_stale": False,
+ "url": "https://github.com/example/worktrunk/pull/85"},
"checked_at": future_time,
"head": get_head("streaming"),
},
"doctor": {
- "status": {
- "ci_status": "running",
- "source": "pullrequest", # filled circle ●
- "is_stale": False,
- "url": "https://github.com/example/worktrunk/pull/92"
- },
+ "status": {"ci_status": "running", "source": "pullrequest", "is_stale": False,
+ "url": "https://github.com/example/worktrunk/pull/92"},
"checked_at": future_time,
"head": get_head("doctor"),
},
}
print("Adding CI status cache...")
- # Write to file-based cache at .git/wt-cache/ci-status/<branch>.json
cache_dir = env.repo / ".git" / "wt-cache" / "ci-status"
cache_dir.mkdir(parents=True, exist_ok=True)
for branch, config in ci_configs.items():
- cache_file = cache_dir / f"{branch}.json"
- cache_file.write_text(json.dumps(config))
+ (cache_dir / f"{branch}.json").write_text(json.dumps(config))
def main():
- if not shutil.which("git"):
- raise SystemExit("Missing dependency: git")
-
- OUT_DIR.mkdir(parents=True, exist_ok=True)
-
- # Copy starship config if exists
- starship_fixture = FIXTURES_DIR / "starship.toml"
- if starship_fixture.exists():
- shutil.copy(starship_fixture, STARSHIP_CONFIG)
+ check_dependencies(["git"])
+ setup_demo_output(OUT_DIR)
# Build wt binary
build_wt(REPO_ROOT)
@@ -433,34 +305,10 @@ def main():
print(f"\nDemo repo created at: {demo_env.repo}")
print(f"Worktrees at: {demo_env.work_base}")
- # Record if VHS is available and tape exists
+ # Record if VHS is available
vhs_available = Path(VHS_BINARY).exists() if "/" in VHS_BINARY else shutil.which(VHS_BINARY)
if vhs_available:
- # Record both light and dark variants
- docs_assets = REPO_ROOT / "docs" / "static" / "assets"
- docs_assets.mkdir(parents=True, exist_ok=True)
-
- for theme_name, output_gif in OUTPUT_GIFS.items():
- theme = THEMES[theme_name]
- replacements = {
- "DEMO_REPO": demo_env.repo,
- "DEMO_HOME": demo_env.home,
- "REAL_HOME": REAL_HOME,
- "STARSHIP_CONFIG": STARSHIP_CONFIG,
- "OUTPUT_GIF": output_gif,
- "TARGET_DEBUG": REPO_ROOT / "target" / "debug",
- "THEME": format_theme_for_vhs(theme),
- }
- if render_tape(TAPE_TEMPLATE, TAPE_RENDERED, replacements):
- print(f"\nRecording {theme_name} GIF with {VHS_BINARY}...")
- record_vhs(TAPE_RENDERED, VHS_BINARY)
- TAPE_RENDERED.unlink(missing_ok=True)
- print(f"GIF saved to {output_gif}")
-
- # Copy to docs for local preview
- asset_name = output_gif.name
- shutil.copy(output_gif, docs_assets / asset_name)
- print(f"Copied to {docs_assets / asset_name}")
+ record_all_themes(demo_env, TAPE_TEMPLATE, OUTPUT_GIFS, REPO_ROOT, vhs_binary=VHS_BINARY)
else:
print(f"\nSkipping GIF recording ({VHS_BINARY} not available)")
print("\nTo test manually:")