governance: keep repository root clean; remove marker file; implement repo detection via structure heuristic; update tests and system prompts/templates
This commit is contained in:
99
CodexHelper
Executable file
99
CodexHelper
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
die() { echo "error: $*" >&2; exit 1; }
|
||||
note() { echo "$*" >&2; }
|
||||
|
||||
find_helper_repo_root() {
|
||||
# Walk upwards to find a dir that looks like the helper repo
|
||||
local d="$(pwd)"
|
||||
while [ "$d" != "/" ]; do
|
||||
if [ -d "$d/collab" ] && [ -f "$d/prompts/global/system.md" ]; then
|
||||
printf '%s' "$d"
|
||||
return 0
|
||||
fi
|
||||
d="$(dirname "$d")"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
print_help() {
|
||||
cat <<EOF
|
||||
CodexHelper — wrapper for codex-cli with modes and scaffolding
|
||||
|
||||
Usage:
|
||||
CodexHelper new-mode --name <ModeName>
|
||||
CodexHelper new-project --mode <ModeName> --name <project-name> --path <dir> [--force]
|
||||
CodexHelper run [--mode <ModeName>] [--prompt-file <file>] [--config <file>] [--sandbox <mode>] [--full-auto]
|
||||
CodexHelper --help
|
||||
|
||||
Notes:
|
||||
- Inside the CodexHelper repo, only 'new-mode' is allowed.
|
||||
- Outside the repo, 'new-project' and 'run' are allowed.
|
||||
EOF
|
||||
}
|
||||
|
||||
require_outside_repo_for() {
|
||||
local subcmd="$1"
|
||||
if find_helper_repo_root >/dev/null 2>&1; then
|
||||
if [ "$subcmd" != "new-mode" ]; then
|
||||
die "Only 'new-mode' is allowed when running inside the CodexHelper repository"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
detect_codex() {
|
||||
if [ -n "${CODEX_BIN:-}" ]; then echo "$CODEX_BIN"; return 0; fi
|
||||
if command -v codex >/dev/null 2>&1; then echo codex; return 0; fi
|
||||
if command -v codex-cli >/dev/null 2>&1; then echo codex-cli; return 0; fi
|
||||
die "No codex binary found. Set CODEX_BIN or install 'codex'/'codex-cli' in PATH."
|
||||
}
|
||||
|
||||
cmd_new_mode() {
|
||||
local name=""
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--name) name="$2"; shift 2;;
|
||||
--force) FORCE=1; shift;;
|
||||
--help|-h) print_help; exit 0;;
|
||||
*) die "Unknown option for new-mode: $1";;
|
||||
esac
|
||||
done
|
||||
[ -n "$name" ] || die "--name is required"
|
||||
local dir="modes/$name"
|
||||
if [ -e "$dir" ] && [ -z "${FORCE:-}" ]; then
|
||||
die "Mode '$name' already exists. Use --force to overwrite."
|
||||
fi
|
||||
mkdir -p "$dir"
|
||||
: >"$dir/mode.md"
|
||||
: >"$dir/defaults.yaml"
|
||||
note "Created $dir/mode.md and $dir/defaults.yaml"
|
||||
}
|
||||
|
||||
cmd_new_project() {
|
||||
require_outside_repo_for new-project
|
||||
# Implementation follows in later milestones
|
||||
die "Not yet implemented: new-project (per plan)."
|
||||
}
|
||||
|
||||
cmd_run() {
|
||||
require_outside_repo_for run
|
||||
# Implementation follows in later milestones
|
||||
die "Not yet implemented: run (per plan)."
|
||||
}
|
||||
|
||||
main() {
|
||||
local subcmd="${1:-}"; if [ -z "$subcmd" ] || [ "$subcmd" = "--help" ] || [ "$subcmd" = "-h" ]; then
|
||||
print_help; exit 0
|
||||
fi
|
||||
case "$subcmd" in
|
||||
new-mode) shift; cmd_new_mode "$@";;
|
||||
new-project) shift; cmd_new_project "$@";;
|
||||
run) shift; cmd_run "$@";;
|
||||
*) die "Unknown subcommand: $subcmd";;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
Reference in New Issue
Block a user