Skip to content

feat(settings): configurable branch prefix for PRs#2865

Open
MattPua wants to merge 6 commits into
mainfrom
posthog-code/configurable-branch-prefix
Open

feat(settings): configurable branch prefix for PRs#2865
MattPua wants to merge 6 commits into
mainfrom
posthog-code/configurable-branch-prefix

Conversation

@MattPua

@MattPua MattPua commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a Branch prefix setting (Settings → General → Version control) so the hardcoded posthog-code/ can be customized.
  • Default stays posthog-code/; the value is normalized (normalizeBranchPrefix in @posthog/shared) and persisted.
CleanShot.2026-06-23.at.13.23.21.mp4

What it affects

  • UI suggestions — pre-filled branch names use the configured prefix.
  • Local agent runs — prefix threaded through sessionServiceagent.start/reconnect → workspace-server system prompt + Claude adapter branch-naming guidance.
  • Cloud runsAgentServerConfig.branchPrefix + --branchPrefix CLI flag; cloud system prompt uses it; desktop sends branch_prefix in the create-run payload (only when non-default).

Notes

  • Cloud delivery needs a backend change: the Django API must accept branch_prefix and pass it to the sandbox as --branchPrefix. Until then cloud defaults to posthog-code/ (no regression — the field is only sent when customized).
  • Tests added for the normalizer and custom-prefix branch derivation.
  • pnpm typecheck passes across all packages; biome clean.

Add a "Branch prefix" setting (Settings → General → Version control) so the
posthog-code/ default can be customized.

- New branchPrefix setting (default "posthog-code/"), persisted, with a
  normalizeBranchPrefix() helper in @posthog/shared
- UI branch-name suggestions use the configured prefix
- Local agent runs: prefix threaded through sessionService → agent.start /
  reconnect → workspace-server system prompt + Claude adapter branch-naming
- Cloud runs: AgentServerConfig.branchPrefix + --branchPrefix CLI flag; cloud
  system prompt uses it; desktop sends branch_prefix in the create-run payload
- Tests for the normalizer and custom-prefix branch derivation

Generated-By: PostHog Code
Task-Id: f55fc9d7-90a0-4dd8-adb9-5763d04cea62
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

React Doctor found 1 issue in 1 file · 1 warning.

1 warning

src/features/settings/sections/GeneralSettings.tsx

Reviewed by React Doctor for commit 717d8cc.

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(settings): configurable branch pref..." | Re-trigger Greptile

Comment thread packages/shared/src/git-naming.ts
Comment thread packages/ui/src/features/settings/settingsStore.ts Outdated
MattPua added 2 commits June 23, 2026 13:15
Address review feedback on the branch-prefix setting:

- Validate the prefix as it is actually used (in front of a slug) with
  validateBranchName, show an inline error, and never persist a value that
  would yield an invalid git ref. This guards the agent prompt and
  git_signed_commit paths, which have no downstream sanitization.
- Add maxLength=100 to the input to match the workspace-server schema cap,
  so a long prefix can no longer break session start/reconnect with a
  ZodError.

Generated-By: PostHog Code
Task-Id: f55fc9d7-90a0-4dd8-adb9-5763d04cea62
normalizeBranchPrefix now guarantees exactly one trailing slash so the prefix
is always a slash-terminated namespace (e.g. "team" -> "team/"), avoiding a
run-together branch name like "teamfix-login-bug".

Generated-By: PostHog Code
Task-Id: f55fc9d7-90a0-4dd8-adb9-5763d04cea62
Comment thread packages/shared/src/git-naming.ts Fixed
MattPua added 3 commits June 23, 2026 13:44
100 was an arbitrary guard, not a considered limit. A prefix is just a
namespace (a GitHub username maxes at 39 chars, so `username/` fits in 40),
while the descriptive slug is capped separately at 60 — so 40 keeps the full
ref well under git's ~250-byte limit.

Introduce a single MAX_BRANCH_PREFIX_LENGTH constant in @posthog/shared and
use it for both the UI input maxLength and the workspace-server start/reconnect
schemas, so they can no longer drift apart.

Generated-By: PostHog Code
Task-Id: f55fc9d7-90a0-4dd8-adb9-5763d04cea62
Replace the slash-trimming regexes (/\/+$/ etc., flagged by CodeQL as a
polynomial regular expression on uncontrolled input) with a linear
split("/")/filter(Boolean)/join — identical behavior, no backtracking.

Generated-By: PostHog Code
Task-Id: f55fc9d7-90a0-4dd8-adb9-5763d04cea62
- setBranchPrefix now normalizes and rejects any prefix that would yield an
  invalid git ref, so the stored value is always valid regardless of caller
  (the agent and cloud paths read it verbatim). validateBranchName owns the
  rules; @posthog/shared's normalizeBranchPrefix stays format-only because
  shared cannot depend on core.
- Commit the prefix on blur instead of via a debounced effect, dropping the
  useDebounce dependency. The remaining effect only mirrors async
  persisted-state hydration back into the editable draft.

Generated-By: PostHog Code
Task-Id: f55fc9d7-90a0-4dd8-adb9-5763d04cea62
@MattPua MattPua marked this pull request as ready for review June 23, 2026 18:08
@MattPua MattPua requested a review from a team June 23, 2026 18:08
@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "fix(settings): enforce valid branch pref..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants