fix(gbrain-sync): cut source-id slugs on hyphen boundaries#1481
Open
Drummerms wants to merge 1 commit into
Open
fix(gbrain-sync): cut source-id slugs on hyphen boundaries#1481Drummerms wants to merge 1 commit into
Drummerms wants to merge 1 commit into
Conversation
`constrainSourceId` truncated the slug with `slug.slice(-tailBudget)`, which
cut mid-word when the boundary fell inside a token. For a repo where the
combined `prefix-org-repo-pathhash` exceeded 32 chars, this produced
embarrassing artifacts like `gstack-code-kill-270c0001-c32152` (from
`drummerms-av-sow-wiz-skill-270c0001`).
Two changes:
1. `constrainSourceId` now walks hyphen-separated tokens from the right,
accumulating whole tokens until adding the next would exceed `tailBudget`.
When no token fits, falls through to the existing `${prefix}-${hash}`
form.
2. `deriveCodeSourceId` now retries with `repo-only-pathhash` (dropping the
org segment) when the full `org-repo-pathhash` triggers truncation. Keeps
the repo name readable when it fits at all.
Before: `gstack-code-kill-270c0001-c32152`
After: `gstack-code-270c0001-050d83` (repo+pathhash doesn't fit at 32 chars
even after dropping org; pathhash + collision-hash is the clean
deterministic fallback)
Note that gbrain's 32-char source-id cap is the actual root constraint for
mid-length org+repo names. Raising the cap on the gbrain side would let
this resolve to `gstack-code-av-sow-wiz-skill-270c0001` (37 chars) or
`gstack-code-drummerms-av-sow-wiz-skill-270c0001` (47 chars). That's a
gbrain-side change not bundled here.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
constrainSourceIdinbin/gstack-gbrain-sync.tstruncates long slugs withslug.slice(-tailBudget), which cuts mid-word when the budget boundary lands inside a hyphen-separated token. For a repo whereprefix-org-repo-pathhashexceeds the 32-char source-id cap, this produces visible artifacts like:drummerms-av-sow-wiz-skill-270c0001(fromgithub.com/Drummerms/av-sow-wiz-skill)gstack-code-kill-270c0001-c32152gstack-code-270c0001-050d83The
killsubstring isskillchopped at the 13-char tail boundary. Beyond the cosmetic problem, it surfaces in user-visible citations and source listings.What changes
Two small edits, both in
bin/gstack-gbrain-sync.ts:constrainSourceId— walk hyphen-separated tokens from the right, accumulating whole tokens until adding the next would exceedtailBudget. When no token fits, falls through to the existing${prefix}-${hash}form. Pure refactor of the truncation step; no API change.deriveCodeSourceId— when the fullprefix-org-repo-pathhashtriggers truncation (suffix no longer ends with-${pathHash}), retry withprefix-repo-pathhash(drop the org). Keeps the repo name readable in cases where dropping the org alone is enough to fit. Falls through toconstrainSourceIdeither way.What's out of scope
The deeper constraint is gbrain's 32-char source-id cap. For mid-length org+repo combinations, even
repo-pathhashdoesn't fit — this PR's fallback producesgstack-code-270c0001-050d83for the example above, which is deterministic + clean but loses the repo name in the ID. Raising the gbrain cap (e.g. to 64) would letgstack-code-av-sow-wiz-skill-270c0001(37 chars) resolve fully. That's a gbrain-side change not bundled here.Test plan
bun run bin/gstack-gbrain-sync.ts --dry-runagainstav-sow-wiz-skillproducesgstack-code-270c0001-050d83instead ofgstack-code-kill-270c0001-c32152constrainSourceIdif the maintainer wants them — happy to add in a follow-up🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.