Skip to content

Semantic branch names from available context (issue #350) #364

@mairin

Description

@mairin

Factory experiment 1. Hypothesis: Semantic branch names from available context — replace factory/run-$HEX with factory/<prefix>/<slug>-<hex4>.

Fixes #350

What to Build

  1. factory/worktree.py — core changes:

    • Add _slugify(text: str, max_length: int = 40) -> str — stdlib-only (re, unicodedata), converts arbitrary text to kebab-case slug
    • Add _classify_prefix(hint: str, mode: str) -> str — keyword-matches hint text against conventional types: fix (bug/crash/error/broken/fail keywords), docs (doc/readme/documentation), refactor (refactor/cleanup/rename/reorganize/restructure), test (test/coverage/spec), chore (chore/ci/infra/config/dependency/deps + discover/meta modes). Default: feat
    • Extend create_worktree signature: add hint: str | None = None and mode: str = "improve" keyword args
    • When hint provided: branch = factory/{prefix}/{slug}-{hex4}, dir = {prefix}-{slug}-{hex4}
    • When hint is None: preserve existing factory/run-{hex8} fallback
    • Write a .factory_branch file inside the worktree directory containing the branch name
    • Update prune_stale to read .factory_branch marker for branch name reconstruction, falling back to factory/run-{id} for legacy directories
  2. factory/cli.py — call site updates (2 places):

    • cmd_ceo (line ~1560): pass hint=focus or interactive_idea or research_ideation or context, mode=mode
    • _run_single_cycle (line ~2312): pass hint=focus or context, mode=mode
  3. tests/test_worktree.py — test updates:

    • Relax factory/run- prefix assertion to accept factory/ prefix
    • Add tests for _slugify with various inputs (normal, unicode, empty, long)
    • Add tests for _classify_prefix with various hint/mode combos
    • Add test for semantic naming with hint
    • Add test for fallback without hint
    • Add test for prune with .factory_branch marker
    • Update the prune orphan test for new naming

Acceptance Criteria

  • create_worktree(path, branch, hint="dashboard UI", mode="improve") produces branch like factory/feat/dashboard-ui-XXXX
  • create_worktree(path, branch, hint="fix login crash", mode="improve") produces branch like factory/fix/login-crash-XXXX
  • create_worktree(path, branch) (no hint) produces factory/run-XXXXXXXX (backward compatible)
  • .factory_branch marker file exists in worktree dir after creation
  • prune_stale reads .factory_branch for branch name, falls back to old pattern for legacy dirs
  • All existing tests pass
  • New tests cover _slugify, _classify_prefix, and the new naming paths

Constraints

  • Read CLAUDE.md before starting
  • Do NOT touch files outside declared scope
  • No new external dependencies — stdlib only
  • Do NOT modify eval/score.py or .factory/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions