extract-module
Extract a self-contained Go package out of fir into its own repo at github.com/kfet/<name>. Use when carving a subtree out of pkg/ for reuse — e.g. firpty, skipstone, pinoauth precedent. While using this skill, update it in place when a genuinely new, non-obvious high-level pattern emerges that the current instructions wouldn't have produced — skip anything an AI would already do by default.
- License 许可
- MIT
- 所属仓库
- kfet/fir
- 最近更新
- 2026-11-15
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- extract-module
- override
- true
- description
- Extract a self-contained Go package out of fir into its own repo at github.com/kfet/<name>. Use when carving a subtree out of pkg/ for reuse — e.g. firpty, skipstone, pinoauth precedent. While using this skill, update it in place when a genuinely new, non-obvious high-level pattern emerges that the current instructions wouldn't have produced — skip anything an AI would already do by default.
02 资源文件 1
- 参考文档evals/triggers.json3.3 KB
03 SKILL.md 正文
Extract a Go module out of fir into its own repo
Use when the user wants to carve a self-contained subtree (typically under pkg/) into a standalone module published at github.com/kfet/<name>.
One candidate at a time — not a competition
When deliberating with the user about which subtree to extract, evaluate each candidate on its own merits, not against the others. Extraction isn't a winner-take-one process — multiple candidates can ship, in any order, independently. A package either clears the bar (self-contained, valuable on its own, niche has room) or it doesn't.
Avoid producing ranked tables that invite "pick the top one." Instead, for each candidate the user is considering, give a self-contained verdict — extract / park / replace internally / not a library at all — with the reasoning visible. The user decides which (possibly several) to act on.
Discover the precedent — don't reinvent
There are already extracted siblings under ~/dev/ai/ (wherever this machine keeps its repo checkouts). Find them, study them, adopt what applies.
grep -rh "github.com/kfet" go.mod go.sum \
| grep -oE "github.com/kfet/[A-Za-z0-9_.-]+" \
| grep -v "^github.com/kfet/fir$" \
| sort -u
For each sibling repo found, inspect it on disk at ~/dev/ai/<name>/:
- Top-level layout (
ls) Makefile— coverage gate, test/fmt/vet targets, release flow.covignore— what's excluded from the coverage gate and why.github/— CI workflows, issue templates, anything elseREADME.md,LICENSE,CHANGELOG.md,AGENTS.md,doc.go,VERSION,.gitignorego.mod— minimum Go version, dependency policy
Adopt every applicable convention. Where siblings differ (e.g. firpty has cmd/ + publish, skipstone has e2e/ + stricter fmt/vet gates), pick the union of what fits the new repo's shape, not the lowest common denominator. Strict-by-default — match the strictest sibling unless the user opts out.
Coverage gate is mandatory — do not ship a Makefile without it
A bare go test -race ./... Makefile is not acceptable for an extracted module. Every sibling repo enforces a coverage threshold (typically 100%) and fails the build below it. The new module must do the same from the first commit.
Concretely, the Makefile must have a cover target invoked by all that:
- Runs
go test -coverprofile=coverage.out ./... - Filters
.covignorepatterns out of the profile viagrep -v -E -f .covignore. - Computes the total coverage percentage.
- Exits non-zero if the percentage is below the threshold.
Copy the exact recipe from the strictest sibling (~/dev/ai/skipstone/Makefile or ~/dev/ai/firpty/Makefile) — do not roll your own. If a .covignore is needed for files that genuinely cannot be covered (e.g. real PTY syscalls, real network exec), copy the sibling's .covignore shape too and document each exemption inline.
If you write the Makefile and make all passes without a coverage check having run, you have skipped this step. Re-check before declaring the extraction done.
Idiomatic-Go pass — extraction is a fresh start, not a copy
The in-fir code was shaped by fir's surrounding code, conventions, and constraints. Extraction is a one-time opportunity to make the package idiomatic Go on its own terms. Treat the copy-paste as the starting state, not the finished state. After the files compile in the new repo and tests pass, do an explicit idiomatic-Go review pass before the first commit (or as a separate cleanup commit).
Lens to apply:
- Package name & symbol stutter —
pinoauth.PinoauthProvideris wrong; rename until callers read cleanly. The package qualifier is the noun prefix. - Doc comments on every exported symbol, starting with the symbol name. The package needs a
doc.goopening with a one-paragraph package overview. - Testable examples (
Example_xxxfuncs) — they show up onpkg.go.devand double as compile-checked usage docs. At least one for the headline API. - Errors — sentinel errors (
var ErrFoo = errors.New(...)) or typed errors withIs/Assupport; wrap with%w; don't return barefmt.Errorf("...: %v", err). - Accept interfaces, return concrete types. Interfaces belong near the consumer, not the producer. If the in-fir version has a
FooProviderinterface that only describes one struct, consider whether the interface needs to exist at all in the new repo. - Functional options for constructors with more than ~3 optional knobs. Avoid sprawling config structs unless the option count is small and stable.
- Zero values usable where reasonable — a
var x Fooshould either work or panic clearly, not silently misbehave. - Context propagation — every blocking/IO method takes
ctx context.Contextas the first arg. Background goroutines must respect cancellation. - No globals, no
init()beyond what the AGENTS.md explicitly allows. Test-swappable singletons (e.g. an HTTP client variable) are tolerated only with a comment justifying why. - File layout — group by topic, not by visibility. One concept per file (
pkce.go,callback_server.go), tests next to source. - Naming — short receiver names, consistent across methods of the same type. No
this/self. No Hungarian. No unnecessary getters. - Pre-Go-1.18 idioms — replace
interface{}withany. If the floor is Go 1.21+, preferslices/maps/cmpstdlib packages over hand-rolled equivalents. - Concurrency safety — document it (
// Foo is safe for concurrent use.or// Foo is not safe for concurrent use; …). Don't make callers guess. - Static checks — beyond
go vet, rungofmt -l,staticcheck,go vet -vettool=fieldalignment. Add the relevant ones to the Makefile so they gate every build.
Don't change behaviour during this pass — semantics stay identical. This is shape, naming, and ergonomics only. If a behavioural improvement surfaces, file it as a separate post-extraction issue.
Pre-flight checks
-
Self-containment — the candidate subtree must not import fir:
grep -rn "kfet/fir" <subtree>/Empty → proceed. Non-empty → refactor inside fir first.
-
make allgreen on the source branch. -
Name availability:
github.com/kfet/<name>repo slot is 404, no module published onpkg.go.dev/github.com/kfet/<name>. -
Incumbent check — does this niche already have a winner? Before extracting, survey the Go ecosystem for what already exists. Stars are a poor signal; pkg.go.dev "imported by" count is the real one. Many candidate niches have a long tail of low-star repos that no one actually depends on — landing as the Nth such entry is not worth a publish.
# Stars + activity for a candidate competitor curl -sL "https://api.github.com/repos/<owner>/<repo>" \ | jq -r '"stars=\(.stargazers_count) pushed=\(.pushed_at) archived=\(.archived) desc=\(.description)"' # Real adoption — pkg.go.dev importers (the number that matters) curl -sL "https://pkg.go.dev/<module-path>?tab=importedby" \ | grep -oE 'Known importer[s]?:</strong>[^<]*[0-9,]+'Three outcomes, three different decisions:
- Niche has a clear winner (high stars and high importers, e.g. >50): don't extract — replace fir's internal use with the incumbent and delete the in-fir copy.
- Niche is empty (no comparable libs, or all <10 importers): extraction is greenfield — proceed.
- Stars ≫ importers across the field (the diagnostic pattern): the idea is popular but adoption is nil. This usually means the use case is narrow enough that everyone rolls their own ~300 LOC port. Extracting fir's port lands you in the same tier — neither winning nor useful. Park the extraction; revisit only if you're willing to invest in the canonical version (different shape of work — a research project, not a copy-paste).
Three signals stack to confirm the "stars ≫ importers" diagnosis. Look for all three before parking:
- Low importer counts (≤1 each on pkg.go.dev) — no real adoption.
- Stars ≫ importers across the field — people upvote the idea, don't use the code.
- Long maintenance silence in a fast-moving niche (>12 months stale where the surrounding ecosystem turns over in weeks) — the authors themselves don't depend on what they shipped.
When all three line up, nobody — including the authors — runs these libraries in production. That's a strictly stronger conclusion than any one signal alone, and it's what makes "park the extraction" the right call rather than "ship and hope."
Bring this finding to the user before committing to the extraction. The "stars ≫ importers" outcome in particular is non-obvious and changes the decision.
Decisions to confirm with the user before writing files
- New repo name and module path (
github.com/kfet/<name>). - Package name — flat at module root is the precedent (
firpty.NewManager,skipstone.Client); rename from the in-fir package name. - License + copyright year (mirror sibling LICENSEs).
- Initial
VERSION(typical:0.0.1). - Symbol renames — usually keep, flag any that read awkwardly under the new package qualifier.
Execution
Fir-side switch — separate change, after the new repo is published
Hand-back
04 同仓库更多 Skills
wt
Spawn a fresh fir agent in its own tmux session on its own git worktree. Use whenever the user wants the work — or the conversation about the work — to happen over there, not here. If the user points at this skill, or has directly loaded it in the context, that alone is the cue — spawn, don't inline.
wrap-up
Wrap up work on a project branch — review, fix, and simplify in a loop until clean, then ff-merge to main.
tmux-observer
Attach a tmux window to an already-running fir session — observe its transcript and drive its input via tmux send-keys. Use when you need to watch or steer another fir agent.
tmux-driver
Drive interactive CLIs (python, gdb, etc.) via named tmux sessions with multi-window support. Falls back to fir's built-in PTY driver when tmux is unavailable.
telegram-bot-setup
Set up a new Telegram bot channel for a fir project — install the telegram MCP, create a per-project state dir, drop in the bot token, wire .fir/mcp.json with TELEGRAM_STATE_DIR, pair the user, and verify. Use when the user asks to add, configure, or onboard a Telegram bot for a fir worktree/project.
sync
Sync with an upstream source repo — detect changed files, apply equivalent downstream edits, update the baseline, and report any new features or non-trivial changes picked up.