@@ -5,6 +5,8 @@ const entrypointGitHooksTemplate = String
55HOOKS_DIR="/opt/docker-git/hooks"
66PRE_PUSH_HOOK="$HOOKS_DIR/pre-push"
77POST_PUSH_ACTION="$HOOKS_DIR/post-push"
8+ PLAN_TO_GIT_CODEX_HOOK="$HOOKS_DIR/plan-to-git-codex-hook"
9+ CODEX_REQUIREMENTS_FILE="/etc/codex/requirements.toml"
810mkdir -p "$HOOKS_DIR"
911
1012cat <<'EOF' > "$PRE_PUSH_HOOK"
@@ -136,13 +138,24 @@ cat <<'EOF' > "$POST_PUSH_ACTION"
136138#!/usr/bin/env bash
137139set -euo pipefail
138140
139- # 5) Run session backup after successful push
141+ # 5) Run plan sync and session backup after successful push
140142REPO_ROOT="${ "${" } DOCKER_GIT_POST_PUSH_REPO_ROOT:-}"
141143if [[ -z "$REPO_ROOT" || ! -d "$REPO_ROOT" ]]; then
142144 REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
143145fi
144146cd "$REPO_ROOT"
145147
148+ # CHANGE: sync captured Codex plans to the current branch PR after push.
149+ # WHY: issue #369 requires the agent plan to be uploaded to PR discussion.
150+ # REF: issue-369
151+ if [ "${ "${" } DOCKER_GIT_SKIP_PLAN_TO_GIT:-}" != "1" ]; then
152+ if ! command -v plan-to-git >/dev/null 2>&1; then
153+ echo "[plan-to-git] Error: plan-to-git not found" >&2
154+ exit 1
155+ fi
156+ plan-to-git sync
157+ fi
158+
146159# CHANGE: keep post-push backup logic in a reusable action script
147160# WHY: git has no client-side post-push hook, so the global git wrapper
148161# invokes this after a successful git push
161174EOF
162175chmod 0755 "$POST_PUSH_ACTION"
163176
177+ cat <<'EOF' > "$PLAN_TO_GIT_CODEX_HOOK"
178+ #!/usr/bin/env bash
179+ set -euo pipefail
180+
181+ if [ "${ "${" } DOCKER_GIT_SKIP_PLAN_TO_GIT:-}" = "1" ]; then
182+ exit 0
183+ fi
184+
185+ if ! command -v plan-to-git >/dev/null 2>&1; then
186+ echo "[plan-to-git] Error: plan-to-git not found" >&2
187+ exit 1
188+ fi
189+
190+ plan-to-git hook --source codex
191+ EOF
192+ chmod 0755 "$PLAN_TO_GIT_CODEX_HOOK"
193+
194+ mkdir -p "$(dirname "$CODEX_REQUIREMENTS_FILE")"
195+ cat <<'EOF' > "$CODEX_REQUIREMENTS_FILE"
196+ # docker-git managed Codex requirements
197+
198+ [features]
199+ hooks = true
200+
201+ [hooks]
202+ managed_dir = "/opt/docker-git/hooks"
203+
204+ [[hooks.UserPromptSubmit]]
205+ [[hooks.UserPromptSubmit.hooks]]
206+ type = "command"
207+ command = "/opt/docker-git/hooks/plan-to-git-codex-hook"
208+ statusMessage = "Capturing plan decision"
209+
210+ [[hooks.Stop]]
211+ [[hooks.Stop.hooks]]
212+ type = "command"
213+ command = "/opt/docker-git/hooks/plan-to-git-codex-hook"
214+ statusMessage = "Capturing agent plan"
215+ EOF
216+ chmod 0644 "$CODEX_REQUIREMENTS_FILE"
217+
164218${ renderEntrypointGitPostPushWrapperInstall ( ) }
165219
166220git config --system core.hooksPath "$HOOKS_DIR" || true
0 commit comments