g1t/packages/contracts/src/names.ts

38 lines1,579 bytesCodeBlame
1// Namespaces follow GitHub's rules (no leading, trailing or doubled hyphens),
2// so "--" can never appear inside one.
3const NAMESPACE = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/;
4const REPO_NAME = /^[a-z0-9._-]{1,100}$/;
5
6/** Routes and reserved words that may not be registered as usernames. */
7const RESERVED = new Set([
8 "api", "mcp", "login", "logout", "register", "new", "settings", "search",
9 "admin", "auth", "integrations", "pulls", "issues", "verify", "forgot", "reset", "device", "workspaces", "u", "oauth", "assets", "avatars", "docs", "explore", "about", "pricing",
10 // g1t itself, and the name its agent once went by: everything g1t does is
11 // shown as `g1t`, so nobody else may be called either.
12 "g1t", "g1t-agent",
13 // Trust pages on g1t.sh, and names kept for them.
14 "policies", "security", "support", "status", "terms", "privacy", "help", "blog",
15 // Invite links, and the waitlist.
16 "invite", "invites", "waitlist",
17 // The container registry, at g1t.sh/v2/.
18 "v2",
19]);
20
21/** Whether `value`, whatever its case, is a name nobody can register: a route, or g1t's own. */
22export function isReservedName(value: string): boolean {
23 return RESERVED.has(value.trim().toLowerCase());
24}
25
26export function isValidNamespace(value: string): boolean {
27 return NAMESPACE.test(value) && !isReservedName(value);
28}
29
30export function isValidRepoName(value: string): boolean {
31 return (
32 REPO_NAME.test(value) &&
33 !value.startsWith(".") &&
34 !value.endsWith(".git") &&
35 // `/<workspace>/-/…` holds the workspace's own pages.
36 value !== "-"
37 );
38}