singularity-forge/src/worktree-name-gen.ts
TÂCHES 35cee7b05f feat: add -w/--worktree CLI flag for isolated worktree sessions (#1247)
* feat: add -w/--worktree CLI flag to start in an isolated worktree

Enables `gsd -w` to auto-create a randomly-named worktree (adjective-verbing-noun
pattern) and `gsd -w my-feature` for named worktrees. Reuses existing worktree
infrastructure under .gsd/worktrees/ with worktree/<name> branches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: full worktree lifecycle — subcommands, auto-commit on exit, status banners

Major improvements to the -w/--worktree system:

- `gsd worktree list` — show worktrees with status (files changed, commits, dirty)
- `gsd worktree merge [name]` — squash-merge into main and clean up
- `gsd worktree clean` — remove all merged/empty worktrees
- `gsd worktree remove <name>` — remove with --force safety gate
- `gsd -w` (no name) resumes the only active worktree instead of creating a new one
- `gsd -w` with multiple active worktrees shows a picker
- Auto-commit dirty work on session exit (session_shutdown hook)
- Status banner on normal `gsd` launch when unmerged worktrees exist
- Full help text with lifecycle documentation (`gsd worktree --help`)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 14:57:25 -06:00

49 lines
2.2 KiB
TypeScript

/**
* Random worktree name generator.
*
* Produces names in the pattern: adjective-verbing-noun
* e.g. "noble-roaming-karp", "swift-whistling-matsumoto"
*/
const ADJECTIVES = [
'agile', 'bold', 'brave', 'bright', 'calm', 'clear', 'cool', 'crisp',
'dapper', 'eager', 'fair', 'fast', 'fierce', 'fine', 'fleet', 'fond',
'gentle', 'glad', 'grand', 'happy', 'keen', 'kind', 'lively', 'lucid',
'mellow', 'merry', 'mighty', 'neat', 'nimble', 'noble', 'plucky', 'polite',
'proud', 'quiet', 'rapid', 'ready', 'serene', 'sharp', 'sleek', 'sleepy',
'smooth', 'snappy', 'steady', 'sturdy', 'sunny', 'sure', 'swift', 'tidy',
'tough', 'tranquil', 'vivid', 'warm', 'wise', 'witty', 'zesty',
]
const VERBS = [
'baking', 'bouncing', 'building', 'carving', 'chasing', 'climbing',
'coding', 'crafting', 'dancing', 'dashing', 'diving', 'drawing',
'dreaming', 'drifting', 'drumming', 'exploring', 'fishing', 'floating',
'flying', 'forging', 'gliding', 'growing', 'hiking', 'humming',
'jumping', 'juggling', 'knitting', 'laughing', 'leaping', 'mapping',
'mixing', 'painting', 'planting', 'playing', 'racing', 'reading',
'riding', 'roaming', 'rowing', 'running', 'sailing', 'singing',
'skating', 'sketching', 'spinning', 'squishing', 'surfing', 'swimming',
'thinking', 'threading', 'tracing', 'walking', 'weaving', 'whistling',
'writing',
]
const NOUNS = [
'atlas', 'aurora', 'balloon', 'beacon', 'bolt', 'brook', 'canyon',
'cedar', 'comet', 'cook', 'coral', 'cosmos', 'crest', 'dawn', 'delta',
'echo', 'ember', 'falcon', 'fern', 'flare', 'frost', 'gale', 'glacier',
'grove', 'harbor', 'hawk', 'horizon', 'iris', 'jade', 'karp', 'lantern',
'lark', 'luna', 'maple', 'marsh', 'matsumoto', 'mesa', 'nebula', 'oasis',
'orbit', 'otter', 'pebble', 'phoenix', 'pine', 'prism', 'puppy', 'quartz',
'raven', 'reef', 'ridge', 'river', 'sage', 'shore', 'sierra', 'spark',
'sprout', 'stone', 'summit', 'thorn', 'tide', 'topaz', 'trail', 'vale',
'violet', 'wave', 'willow', 'zenith',
]
function pick<T>(arr: T[]): T {
return arr[Math.floor(Math.random() * arr.length)]!
}
export function generateWorktreeName(): string {
return `${pick(ADJECTIVES)}-${pick(VERBS)}-${pick(NOUNS)}`
}