repo_root = parent directory of scripts/install-local.sh
install_dir = WTK_INSTALL_DIR or "$HOME/.local/bin"
commit = git -C repo_root rev-parse --short HEAD
build_time = date -u +%Y-%m-%dT%H:%M:%SZ
version = "dev commit=<commit> built=<build_time>"
mkdir -p install_dir
go build -trimpath -ldflags "-X github.com/nettee/worktree-kit/internal/cli.Version=<version>" -o install_dir/wtk repo_root/cmd/wtk
chmod 0755 install_dir/wtk
run install_dir/wtk --version
id: 20260511-local-dev-install
name: Local Dev Install
status: implemented
created: '2026-05-11'
Overview
Problem Statement
~/.local/bin,并通过wtk --version明确显示这是本地 build。Goals
wtk源码版本到~/.local/bin/wtk的路径。wtk --version显示开发版标识、commit hash 和 build 时间。Scope
ldflags -X注入版本信息的机制。Success Criteria
~/.local/bin/wtk存在且可执行。wtk --version输出类似wtk version dev commit=<hash> built=<time>。Research
Existing System
internal/cli.Version变量提供,默认值是0.0.1。Source:internal/cli/root.go:19Version字段,因此wtk --version会显示该变量内容。Source:internal/cli/root.go:48-52github.com/nettee/worktree-kit/internal/cli.Version=${version}。Source:.github/workflows/release.yml:23-30$HOME/.local/bin。Source:scripts/install.sh:20-23--version输出包含 release version。Source:scripts/install.sh:221-222wtk --version包含版本字符串。Source:scripts/test-install.sh:52-56Available Approaches
go build到本地 bin 目录,并注入开发版版本字符串。Source:.github/workflows/release.yml:29,scripts/install.sh:20-23scripts/install.sh:169-226Constraints & Dependencies
dev、commit hash、build time,避免 semver 形式。Source: conversation requirementgit读取 commit hash,并需要go build生成cmd/wtk。Source:go.mod:1-3,.github/workflows/release.yml:29Design
Architecture Overview
Change Scope
scripts/install-local.shas the development install entrypoint. Impact: local developer workflow only. Source:scripts/install.sh:20-23,.github/workflows/release.yml:29.github/workflows/release.yml:23-30Design Decisions
scripts/install-local.shfor source-based local builds. Source:scripts/install.sh:169-226./cmd/wtkdirectly withgo build -trimpathand-ldflags -X github.com/nettee/worktree-kit/internal/cli.Version=.... Source:.github/workflows/release.yml:29,internal/cli/root.go:19dev commit=<short-hash> built=<utc-time>. Source: conversation requirement,internal/cli/root.go:51$HOME/.local/bin, withWTK_INSTALL_DIRoverride for tests and custom installs. Source:scripts/install.sh:20-23wtk --versionafter installation. Source:scripts/install.sh:221-222,scripts/test-install.sh:52-56Why this design
devprefix with commit and build time makes local binaries traceable without looking like a tagged release.Test Strategy
scripts/install-local.shusing a temporaryWTK_INSTALL_DIR; assert the binary is executable and--versioncontainsdev commit=andbuilt=. Source:scripts/test-install.sh:18-56internal/cli/root_test.go:10-21Pseudocode
File Structure
scripts/install-local.sh- local source build and install script.scripts/test-install-local.sh- local install script smoke test.Plan
scripts/install-local.shdev commit=<hash> built=<time>through ldflagsWTK_INSTALL_DIRNotes
Implementation
scripts/install-local.sh- added source-based local installer that buildscmd/wtk, injectsdev commit=<hash> built=<utc-time>through Go ldflags, installs toWTK_INSTALL_DIRor$HOME/.local/bin, and verifies the installed binary version.scripts/test-install-local.sh- added smoke coverage for syntax, temp-dir install, version output, installer output, and missinggofail-fast behavior.Verification
sh scripts/test-install-local.sh- passed.sh scripts/test-install.sh- passed.go test ./...- passed.