diff --git a/src/config/schema.ts b/src/config/schema.ts index 0d2c590ba..bcb36a175 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -10,6 +10,7 @@ export * from "./schema/commands" export * from "./schema/dynamic-context-pruning" export * from "./schema/experimental" export * from "./schema/fallback-models" +export * from "./schema/git-env-prefix" export * from "./schema/git-master" export * from "./schema/hooks" export * from "./schema/notification" diff --git a/src/config/schema/git-env-prefix.ts b/src/config/schema/git-env-prefix.ts new file mode 100644 index 000000000..65609c0b1 --- /dev/null +++ b/src/config/schema/git-env-prefix.ts @@ -0,0 +1,28 @@ +import { z } from "zod" + +const GIT_ENV_ASSIGNMENT_PATTERN = + /^(?:[A-Za-z_][A-Za-z0-9_]*=[A-Za-z0-9_-]*)(?: [A-Za-z_][A-Za-z0-9_]*=[A-Za-z0-9_-]*)*$/ + +export const GIT_ENV_PREFIX_VALIDATION_MESSAGE = + 'git_env_prefix must be empty or use shell-safe env assignments like "GIT_MASTER=1"' + +export function isValidGitEnvPrefix(value: string): boolean { + if (value === "") { + return true + } + + return GIT_ENV_ASSIGNMENT_PATTERN.test(value) +} + +export function assertValidGitEnvPrefix(value: string): string { + if (!isValidGitEnvPrefix(value)) { + throw new Error(GIT_ENV_PREFIX_VALIDATION_MESSAGE) + } + + return value +} + +export const GitEnvPrefixSchema = z + .string() + .refine(isValidGitEnvPrefix, { message: GIT_ENV_PREFIX_VALIDATION_MESSAGE }) + .default("GIT_MASTER=1") diff --git a/src/config/schema/git-master.ts b/src/config/schema/git-master.ts index e162b38c5..4c6f4bf65 100644 --- a/src/config/schema/git-master.ts +++ b/src/config/schema/git-master.ts @@ -1,12 +1,14 @@ import { z } from "zod" +import { GitEnvPrefixSchema } from "./git-env-prefix" + export const GitMasterConfigSchema = z.object({ /** Add "Ultraworked with Sisyphus" footer to commit messages (default: true). Can be boolean or custom string. */ commit_footer: z.union([z.boolean(), z.string()]).default(true), /** Add "Co-authored-by: Sisyphus" trailer to commit messages (default: true) */ include_co_authored_by: z.boolean().default(true), /** Environment variable prefix for all git commands (default: "GIT_MASTER=1"). Set to "" to disable. Allows custom git hooks to detect git-master skill usage. */ - git_env_prefix: z.string().default("GIT_MASTER=1"), + git_env_prefix: GitEnvPrefixSchema, }) export type GitMasterConfig = z.infer