UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

49 lines • 2.1 kB
/** * The receive-pack every LOCAL push runs (V3). Its `-c` settings reach the local receive-pack and its children: no target * or global hook runs, a checked-out branch is refused, and no auto gc or maintenance can prune through the target. */ const HARDENED_RECEIVE_PACK = [ "git", "-c core.hooksPath=/dev/null", "-c receive.denyCurrentBranch=refuse", "-c core.fsmonitor=false", "-c receive.autogc=false", "-c gc.auto=0", "-c maintenance.auto=false", "receive-pack", ].join(" "); /** A LOCAL run runs no client hook either (pre-push, reference-transaction): the hand, not the repo, decides what executes. */ const CLIENT_LOCAL_GUARDS = ["-c", "core.hooksPath=/dev/null"]; /** A REMOTE run may not fall back to a local transport through insteadOf, pushInsteadOf or a remote name (V6). */ const REMOTE_GUARDS = [ "-c", "protocol.file.allow=never", "-c", "protocol.ext.allow=never", "-c", "protocol.fd.allow=never", ]; function subcommandAt(argv) { let index = 0; while (index < argv.length && (argv[index] ?? "").startsWith("-")) index += argv[index] === "-c" ? 2 : 1; return index; } /** The final argv and environment for a planned git call: local and remote transports each get their own guards. */ export function transportFor(argv, env, paths) { const at = subcommandAt(argv); const sub = argv[at]; const local = paths.some((path) => path.kind === "source" || path.kind === "target"); if (local) { const pushed = sub === "push" ? [`--receive-pack=${HARDENED_RECEIVE_PACK}`] : []; return { argv: [...argv.slice(0, at), ...CLIENT_LOCAL_GUARDS, argv[at] ?? "", ...pushed, ...argv.slice(at + 1)], env: { ...env, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null" }, local: true, }; } if (sub === "ls-remote" || sub === "push") return { argv: [...argv.slice(0, at), ...REMOTE_GUARDS, ...argv.slice(at)], env, local: false }; return { argv: [...argv], env, local: false }; } //# sourceMappingURL=hand-run-transport.js.map