Factory experiment 1. Hypothesis: Semantic branch names from available context — replace factory/run-$HEX with factory/<prefix>/<slug>-<hex4>.
Fixes #350
What to Build
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
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
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/
Factory experiment 1. Hypothesis: Semantic branch names from available context — replace
factory/run-$HEXwithfactory/<prefix>/<slug>-<hex4>.Fixes #350
What to Build
factory/worktree.py— core changes:_slugify(text: str, max_length: int = 40) -> str— stdlib-only (re,unicodedata), converts arbitrary text to kebab-case slug_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:featcreate_worktreesignature: addhint: str | None = Noneandmode: str = "improve"keyword argshintprovided: branch =factory/{prefix}/{slug}-{hex4}, dir ={prefix}-{slug}-{hex4}hintis None: preserve existingfactory/run-{hex8}fallback.factory_branchfile inside the worktree directory containing the branch nameprune_staleto read.factory_branchmarker for branch name reconstruction, falling back tofactory/run-{id}for legacy directoriesfactory/cli.py— call site updates (2 places):cmd_ceo(line ~1560): passhint=focus or interactive_idea or research_ideation or context, mode=mode_run_single_cycle(line ~2312): passhint=focus or context, mode=modetests/test_worktree.py— test updates:factory/run-prefix assertion to acceptfactory/prefix_slugifywith various inputs (normal, unicode, empty, long)_classify_prefixwith various hint/mode combos.factory_branchmarkerAcceptance Criteria
create_worktree(path, branch, hint="dashboard UI", mode="improve")produces branch likefactory/feat/dashboard-ui-XXXXcreate_worktree(path, branch, hint="fix login crash", mode="improve")produces branch likefactory/fix/login-crash-XXXXcreate_worktree(path, branch)(no hint) producesfactory/run-XXXXXXXX(backward compatible).factory_branchmarker file exists in worktree dir after creationprune_stalereads.factory_branchfor branch name, falls back to old pattern for legacy dirs_slugify,_classify_prefix, and the new naming pathsConstraints