Logo Sync Upstream

Sync Upstream

Tổ chứcPhổ biến
nyaruka
sync-upstream

Sync this Go port with a new upstream google/libphonenumber release — regenerate the embedded metadata and reconcile the ported Java logic. Takes an optional argument — `data` (metadata regen only), `code` (code reconciliation only), or empty for both. Use when the user says "sync with upstream", "do an upstream sync", "reconcile against libphonenumber", "pull the latest libphonenumber", bump to a new libphonenumber version, or invokes /sync-upstream. SYNC.md holds the state (baseline version + deliberate divergences); this skill is the procedure.

Tổng quan

Nhà phát hànhnyaruka
Kho mãphonenumbers
Tên kỹ năngsync-upstream
Sao
1.6K
Bản fork
183
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Đầy đủ trong hướng dẫn

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được nyaruka công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Sync Upstream trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/nyaruka/phonenumbers/tree/main/.claude/skills/sync-upstream
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nyaruka/phonenumbers.git /tmp/phonenumbers
mkdir -p .claude/skills
cp -r /tmp/phonenumbers/.claude/skills/sync-upstream .claude/skills/sync-upstream
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Sync Upstream trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Sync Upstream ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Sync Upstream không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Sync with upstream libphonenumber

This package is a Go port of google/libphonenumber, tracking its Java reference implementation. A sync is two independent operations — do them in order, but understand they're different in kind:

  1. Metadata regen — mechanical. Rebuild the embedded data/ blobs from a new upstream release. Fully automated by cmd/buildmetadata.
  2. Code reconciliation — judgment. Port new Java logic changes into the Go files. Can't be automated; this is the real reason SYNC.md exists.

State lives in SYNC.md: the code baseline (Code reconciled against vX.Y.Z) and the deliberate divergences (what we intentionally do not port). Read it first. The embedded-metadata version is tracked separately in the generated metadata/version.go (metadata.Version) — never hand-edit that.

Run everything from the repo root (/Users/rowan/nyaruka/phonenumbers).

Argument

The skill takes one optional argument selecting which operation(s) to run:

  • /sync-upstream data — Phase 1 only (metadata regen). An automated metadata update can invoke this mode directly.
  • /sync-upstream code — Phase 2 only (code reconciliation, against the metadata version already built — see the note at the top of Phase 2).
  • /sync-upstream — both phases, in order.

Whichever mode runs, finish with Finalize below: commit the changes and stop. This skill never releases — no tag, no push, no CHANGELOG.md. The user cuts releases separately with /release.


Phase 1 — Metadata regen (mechanical)

sh
go run ./cmd/buildmetadata            # latest upstream release
# go run ./cmd/buildmetadata v9.0.32  # or pin a specific tag

This resolves the target tag, wipes and re-clones upstream into _build/ (a shallow --depth=1 checkout at the target tag — gitignored), rebuilds every embedded blob (data/, metadata/data/, carrier/data/, geocoding/data/, timezone/data/), and rewrites the generated metadata/version.go with the tag it built from.

Then:

sh
go test ./...

Review the diff. The only files that may change are the embedded blobs (data/, metadata/data/, carrier/data/, geocoding/data/, timezone/data/) and the generated metadata/version.go:

  • No changes at all → the metadata is already up to date; nothing to commit for Phase 1. In data mode report that and stop; in a full sync continue to Phase 2 (the code baseline may still lag the metadata version).
  • Changes outside that set → something is wrong; stop and report the unexpected changes without committing.

In data mode, that's the whole job — skip to Finalize. Phase 1 has already bumped metadata/version.go, and the Code reconciled against baseline in SYNC.md stays where it is (the two versions are tracked separately for exactly this case).

The target tag you built becomes the new code baseline once Phase 2 reconciles against it.


Phase 2 — Code reconciliation (judgment)

Goal: apply any upstream Java logic changes between the old baseline (SYNC.md) and the target to each Go port. The target is the tag Phase 1 built — in code-only mode, the version already in metadata/version.go (metadata.Version), i.e. reconcile the code up to where the embedded metadata already is.

Get both tags side by side for diffing

Phase 1 leaves _build/ as a shallow clone at the target tag. In code-only mode _build/ may be missing (it's gitignored) — recreate it at the target first:

sh
TARGET=v9.0.32    # metadata.Version, from metadata/version.go
git clone --depth=1 --branch "$TARGET" https://github.com/google/libphonenumber _build

Then fetch the baseline tag into it so you can diff tree-to-tree (no merge base needed — git diff A B compares trees):

sh
BASE=v9.0.31      # from SYNC.md "Code reconciled against"
git -C _build fetch --depth=1 origin tag "$BASE"

Diff each ported source, baseline→target

The per-file headers are the source of truth for the Go→Java mapping — every reconcilable file carries a // Port of <upstream/path>. header. Enumerate them:

sh
grep -rn "Port of" --include='*.go' . | grep -v _test.go | grep -v _build/

For each upstream path P, diff it across the window and reconcile anything non-trivial:

sh
git -C _build diff "$BASE" "$TARGET" -- "$P"

The mapping (kept current; if files move, the headers win and this table is refreshed):

Goupstream Java path
phonenumberutil.go, enums.gojava/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
asyoutypeformatter.gojava/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
shortnumberinfo.gojava/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java
phonenumbermatcher.gojava/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java
phonenumbermatch.gojava/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatch.java
errors.gojava/libphonenumber/src/com/google/i18n/phonenumbers/NumberParseException.java
internal/regexcache/java/libphonenumber/src/com/google/i18n/phonenumbers/internal/RegexCache.java
internal/regexbasedmatcher/java/libphonenumber/src/com/google/i18n/phonenumbers/internal/RegexBasedMatcher.java, .../internal/MatcherApi.java
metadata/source.go, alternateformats.gojava/libphonenumber/src/com/google/i18n/phonenumbers/metadata/source/*, .../MetadataLoader.java
carrier/java/carrier/src/com/google/i18n/phonenumbers/PhoneNumberToCarrierMapper.java
geocoding/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java
timezone/java/geocoder/src/com/google/i18n/phonenumbers/PhoneNumberToTimeZonesMapper.java
internal/prefixmapper/java/internal/prefixmapper/src/com/google/i18n/phonenumbers/prefixmapper/*
internal/metadatabuilder/tools/java/common/src/com/google/i18n/phonenumbers/BuildMetadataFromXml.java

internal/serialize and internal/stringbuilder are Go-specific scaffolding (gzip/binary decode; a java.lang.StringBuilder stand-in) with no upstream logic to reconcile — skip them.

The corresponding upstream tests move in lockstep. The Go tests mirror the Java test classes (e.g. PhoneNumberUtilTest → phonenumberutil_test.go and friends); diff those too and port new cases:

sh
git -C _build diff "$BASE" "$TARGET" -- "$(echo "$P" | sed 's#/src/#/test/#')"

Reconcile

For each non-empty diff, translate the relevant change into the Go port. While doing so:

  • Preserve upstream source order. The core ports keep their functions/methods in the same order as the upstream Java so the next sync's diff lines up — maintain that as you reconcile. A few files are deliberately reorganized for Go idiom and don't follow upstream order (metadata/source.go, internal/regexcache, internal/regexbasedmatcher, internal/prefixmapper); that's expected.
  • Java-shaped over idiomatic — in ports. Inside a // Port of … file, keep constructs close to the Java so the next diff lines up, even when a linter (gopls modernize, staticcheck) suggests a more idiomatic Go form — e.g. don't rewrite an index for loop as for i := range n, or a manual scan as slices.Contains. Let those modernizations ride in with upstream when the Java itself changes. Non-ported code (cmd/, CI, build glue, and Go-specific scaffolding like internal/serialize / internal/stringbuilder) has no Java counterpart to track, so make it fully idiomatic.
  • Honor deliberate divergences. Check SYNC.md before porting something back; some upstream code is intentionally absent (e.g. Mockito-style metadata-source injection tests, Java iterator semantics with no Go equivalent). Don't re-introduce it. If you make a new intentional divergence, record it.
  • Keep it a port, not an enhancement. Match libphonenumber's behaviour; don't add API.
  • Mirror Java's visibility. A symbol that is public in Java is exported in Go; one that is private/package-private/@VisibleForTesting stays unexported (lower-case camelCase). Constants especially: REGION_CODE_FOR_NON_GEO_ENTITY is the only public static final upstream, so it is the lone exported constant — every other ported regex/char-class/length-limit/mapping is unexported. The deliberate exceptions are the Go-idiomatic Err* vars (standing in for Java's checked exceptions) and the public enum types. Don't export a new internal just because it's a package-level const/var.
  • Java overloads → distinct Go names. Go can't overload, so a set of Java methods sharing a name maps to several Go funcs: give one the bare PascalCase name and suffix the rest with the parameter(s) that distinguish them. Follow the established pattern — Parse/ParseToNumber, IsNumberMatch/IsNumberMatchWithNumbers/IsNumberMatchWithOneNumber, GetExampleNumberForType/GetExampleNumberForTypeInRegion, IsPossibleNumber/IsPossibleNumberFromRegion, IsNumberGeographical/IsNumberGeographicalForType. Porting an overload that already exists upstream is faithful porting, not the "don't add API" case above — fill the gap rather than skipping it. Which overload keeps the bare name (and the exact suffix) is a judgment call; flag new public names in the PR.
  • Don't hand-edit generated files (metadata/version.go, *.pb.go) or the data/ blobs — those come from Phase 1 / protoc.

Then make it green:

sh
go test ./...

Finalize

If code was reconciled (Phase 2 ran), update SYNC.md (state only):

  1. Bump the Code reconciled against version to the target tag.
  2. If anything new was intentionally left unported, add it under Deliberate divergences.

Then, with go test ./... green, commit the changes:

  • Metadata only (data mode): commit the blobs and metadata/version.go with the message Updated metadata to <tag>, where <tag> is the upstream tag it was built from (metadata.Version in metadata/version.go), e.g. Updated metadata to v9.0.33.
  • Code reconciliation: record what was reconciled (and the version) in the commit message — git history is the sync log, so SYNC.md doesn't keep one.

Stop there. Do not push, tag, or touch CHANGELOG.md — those belong to the release process. Finish by reporting that the changes are committed and a release can be cut with /release.

Leave public-facing text (commit messages, comments) describing the software in general terms.

Câu hỏi thường gặp

Kỹ năng AI Sync Upstream làm được gì?

Sync this Go port with a new upstream google/libphonenumber release — regenerate the embedded metadata and reconcile the ported Java logic. Takes an optional argument — `data` (metadata regen only), `code` (code reconciliation only), or empty for both. Use when the user says "sync with upstream", "do an upstream sync", "reconcile against libphonenumber", "pull the latest libphonenumber", bump to a new libphonenumber version, or invokes /sync-upstream. SYNC.md holds the state (baseline version + deliberate divergences); this skill is the procedure.

Vì sao nên dùng Sync Upstream trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Sync Upstream là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Sync Upstream trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/nyaruka/phonenumbers/tree/main/.claude/skills/sync-upstream. TypingMind đọc tệp SKILL.md và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Sync Upstream?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Sync Upstream với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Sync Upstream với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Sync Upstream có miễn phí không?

Có. Kỹ năng này được nyaruka phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇