Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Move branch sanitization from contracts to new shared package

Julius Marmingedde48e941413
diff --git a/apps/server/package.json b/apps/server/package.json
index 3e4d1a9fa..3eac1574b 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -30,6 +30,7 @@
"@effect/language-service": "0.75.1",
"@effect/vitest": "catalog:",
"@t3tools/contracts": "workspace:*",
+ "@t3tools/shared": "workspace:*",
"@t3tools/web": "workspace:*",
"@types/bun": "^1.3.9",
"@types/node": "^24.10.13",
diff --git a/apps/server/src/git/Layers/CodexTextGeneration.ts b/apps/server/src/git/Layers/CodexTextGeneration.ts
index 4436c81de..9b5bbbf35 100644
--- a/apps/server/src/git/Layers/CodexTextGeneration.ts
+++ b/apps/server/src/git/Layers/CodexTextGeneration.ts
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
import { Effect, FileSystem, Layer, Option, Path, Schema, Stream } from "effect";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
-import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/contracts";
+import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import { ServerConfig } from "../../config.ts";
diff --git a/apps/server/src/git/Layers/GitManager.ts b/apps/server/src/git/Layers/GitManager.ts
index b7282b405..643f276f9 100644
--- a/apps/server/src/git/Layers/GitManager.ts
+++ b/apps/server/src/git/Layers/GitManager.ts
@@ -1,7 +1,7 @@
import { randomUUID } from "node:crypto";
import { Effect, FileSystem, Layer, Path } from "effect";
-import { sanitizeFeatureBranchName } from "@t3tools/contracts";
+import { sanitizeFeatureBranchName } from "@t3tools/shared/git";
import { GitManagerError } from "../Errors.ts";
import { GitManager, type GitManagerShape } from "../Services/GitManager.ts";
diff --git a/apps/web/package.json b/apps/web/package.json
index e1088c73e..eb9960b8f 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -15,6 +15,7 @@
"@lexical/react": "^0.41.0",
"@pierre/diffs": "^1.1.0-beta.16",
"@t3tools/contracts": "workspace:*",
+ "@t3tools/shared": "workspace:*",
"@tanstack/react-pacer": "^0.19.4",
"@tanstack/react-query": "^5.90.0",
"@tanstack/react-router": "^1.160.2",
diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.ts
index bbea434f7..53dcf982f 100644
--- a/apps/web/src/components/GitActionsControl.logic.ts
+++ b/apps/web/src/components/GitActionsControl.logic.ts
@@ -1,9 +1,9 @@
-import {
- type GitRunStackedActionResult,
- type GitStackedAction,
- type GitStatusResult,
- sanitizeBranchFragment,
+import type {
+ GitRunStackedActionResult,
+ GitStackedAction,
+ GitStatusResult,
} from "@t3tools/contracts";
+import { sanitizeBranchFragment } from "@t3tools/shared/git";
export type GitActionIconName = "commit" | "push" | "pr";
diff --git a/bun.lock b/bun.lock
index 1271e31d9..84d11da83 100644
--- a/bun.lock
+++ b/bun.lock
@@ -50,6 +50,7 @@
"@effect/language-service": "0.75.1",
"@effect/vitest": "catalog:",
"@t3tools/contracts": "workspace:*",
+ "@t3tools/shared": "workspace:*",
"@t3tools/web": "workspace:*",
"@types/bun": "^1.3.9",
"@types/node": "^24.10.13",
@@ -67,6 +68,7 @@
"@lexical/react": "^0.41.0",
"@pierre/diffs": "^1.1.0-beta.16",
"@t3tools/contracts": "workspace:*",
+ "@t3tools/shared": "workspace:*",
"@tanstack/react-pacer": "^0.19.4",
"@tanstack/react-query": "^5.90.0",
"@tanstack/react-router": "^1.160.2",
@@ -110,6 +112,13 @@
"typescript": "^5.7.3",
},
},
+ "packages/shared": {
+ "name": "@t3tools/shared",
+ "version": "0.0.0-alpha.1",
+ "devDependencies": {
+ "typescript": "^5.7.3",
+ },
+ },
},
"catalog": {
"@effect/language-service": "0.75.1",
@@ -537,6 +546,8 @@
"@t3tools/desktop": ["@t3tools/desktop@workspace:apps/desktop"],
+ "@t3tools/shared": ["@t3tools/shared@workspace:packages/shared"],
+
"@t3tools/web": ["@t3tools/web@workspace:apps/web"],
"@tailwindcss/node": ["@tailwindcss/[email protected]", "", { "dependencies": { "@jridgewell/remapping": "^2.3.4", "enhanced-resolve": "^5.18.3", "jiti": "^2.6.1", "lightningcss": "1.30.2", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.1.18" } }, "sha512-DoR7U1P7iYhw16qJ49fgXUlry1t4CpXeErJHnQ44JgTSKMaZUdf17cfn5mHchfJ4KRBZRFA/Coo+MUF5+gOaCQ=="],
diff --git a/packages/contracts/src/git.ts b/packages/contracts/src/git.ts
index 7e7708b74..12bd739dc 100644
--- a/packages/contracts/src/git.ts
+++ b/packages/contracts/src/git.ts
@@ -179,39 +179,3 @@ export const GitPullResult = Schema.Struct({
upstreamBranch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
});
export type GitPullResult = typeof GitPullResult.Type;
-
-// Branch name utilities
-
-/**
- * Sanitize an arbitrary string into a valid, lowercase git branch fragment.
- * Strips quotes, collapses separators, limits to 64 chars.
- */
-export function sanitizeBranchFragment(raw: string): string {
- const normalized = raw
- .trim()
- .toLowerCase()
- .replace(/['"`]/g, "")
- .replace(/^[./\s_-]+|[./\s_-]+$/g, "");
-
- const branchFragment = normalized
- .replace(/[^a-z0-9/_-]+/g, "-")
- .replace(/\/+/g, "/")
- .replace(/-+/g, "-")
- .replace(/^[./_-]+|[./_-]+$/g, "")
- .slice(0, 64)
- .replace(/[./_-]+$/g, "");
-
- return branchFragment.length > 0 ? branchFragment : "update";
-}
-
-/**
- * Sanitize a string into a `feature/…` branch name.
- * Preserves an existing `feature/` prefix or slash-separated namespace.
- */
-export function sanitizeFeatureBranchName(raw: string): string {
- const sanitized = sanitizeBranchFragment(raw);
- if (sanitized.includes("/")) {
- return sanitized.startsWith("feature/") ? sanitized : `feature/${sanitized}`;
- }
- return `feature/${sanitized}`;
-}
diff --git a/packages/shared/package.json b/packages/shared/package.json
new file mode 100644
index 000000000..222d20e97
--- /dev/null
+++ b/packages/shared/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "@t3tools/shared",
+ "version": "0.0.0-alpha.1",
+ "private": true,
+ "type": "module",
+ "exports": {
+ "./git": {
+ "types": "./src/git.ts",
+ "import": "./src/git.ts"
+ }
+ },
+ "scripts": {
+ "typecheck": "tsc --noEmit"
+ },
+ "devDependencies": {
+ "typescript": "^5.7.3"
+ }
+}
diff --git a/packages/shared/src/git.ts b/packages/shared/src/git.ts
new file mode 100644
index 000000000..fea93d85e
--- /dev/null
+++ b/packages/shared/src/git.ts
@@ -0,0 +1,33 @@
+/**
+ * Sanitize an arbitrary string into a valid, lowercase git branch fragment.
+ * Strips quotes, collapses separators, limits to 64 chars.
+ */
+export function sanitizeBranchFragment(raw: string): string {
+ const normalized = raw
+ .trim()
+ .toLowerCase()
+ .replace(/['"`]/g, "")
+ .replace(/^[./\s_-]+|[./\s_-]+$/g, "");
+
+ const branchFragment = normalized
+ .replace(/[^a-z0-9/_-]+/g, "-")
+ .replace(/\/+/g, "/")
+ .replace(/-+/g, "-")
+ .replace(/^[./_-]+|[./_-]+$/g, "")
+ .slice(0, 64)
+ .replace(/[./_-]+$/g, "");
+
+ return branchFragment.length > 0 ? branchFragment : "update";
+}
+
+/**
+ * Sanitize a string into a `feature/…` branch name.
+ * Preserves an existing `feature/` prefix or slash-separated namespace.
+ */
+export function sanitizeFeatureBranchName(raw: string): string {
+ const sanitized = sanitizeBranchFragment(raw);
+ if (sanitized.includes("/")) {
+ return sanitized.startsWith("feature/") ? sanitized : `feature/${sanitized}`;
+ }
+ return `feature/${sanitized}`;
+}
diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json
new file mode 100644
index 000000000..564a59900
--- /dev/null
+++ b/packages/shared/tsconfig.json
@@ -0,0 +1,4 @@
+{
+ "extends": "../../tsconfig.base.json",
+ "include": ["src"]
+}