Skip to content

Use public container IP in managed agent prompts - #203

Open
skulidropek wants to merge 1 commit into
ProverCoderAI:mainfrom
skulidropek:issue-78-public-container-ip
Open

Use public container IP in managed agent prompts#203
skulidropek wants to merge 1 commit into
ProverCoderAI:mainfrom
skulidropek:issue-78-public-container-ip

Conversation

@skulidropek

Copy link
Copy Markdown
Member

Summary

  • detect and export a non-loopback container IP in the generated entrypoint
  • inject public-access guidance into managed Codex, Claude, and Gemini prompt files
  • cover the new prompt text with entrypoint and prepare-files regression tests

Testing

  • pnpm install --frozen-lockfile
  • pnpm --filter ./packages/lib build
  • pnpm --filter ./packages/lib typecheck
  • pnpm --filter ./packages/app typecheck
  • pnpm --filter ./packages/app exec vitest run tests/docker-git/entrypoint-auth.test.ts
  • pnpm --filter ./packages/lib exec vitest run tests/usecases/prepare-files.test.ts

Closes#78.

@skulidropek

Copy link
Copy Markdown
MemberAuthor

@coderabbitai review

@coderabbitai

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitaiBot commented May 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features
    • Containers now automatically detect and expose their public IPv4 address, making it available as an environment variable for container-to-container communication.
    • Public IP information is injected into agent configuration and documentation, allowing users to reference the correct address when accessing services externally.
    • Public IP detection can be overridden via environment variable configuration.

Walkthrough

This PR detects the Docker-Git container's public IPv4 address at startup and injects public IP guidance into Claude, Codex, and Gemini agent prompts. The public IP is discovered via override, ip command, or hostname -I fallback, then exposed and persisted for user-facing shell sessions and agent configuration templates.

Changes

Docker-Git Public IP Detection and Agent Integration

Layer / File(s)Summary
Public IP Detection Mechanism
packages/lib/src/core/templates-entrypoint/base.ts
Implements renderEntrypointPublicIp() to detect non-local IPv4 via docker_git_detect_public_ip() using DOCKER_GIT_PUBLIC_IP override, ip command, or hostname -I fallback; exports and persists to /etc/profile.d/docker-git-public-ip.sh.
Entrypoint Pipeline Wiring
packages/lib/src/core/templates-entrypoint.ts
Imports renderEntrypointPublicIp and integrates it into the main render pipeline after package cache setup.
Claude Agent Public Access Guidance
packages/lib/src/core/templates-entrypoint/claude-extra-config.ts
Conditionally populates CLAUDE_PUBLIC_ACCESS_BLOCK with public IP/URL instructions when DOCKER_GIT_PUBLIC_IP is set and injects into global prompt.
Codex AGENTS.md Public Access Guidance
packages/lib/src/core/templates-entrypoint/codex.ts
Conditionally populates PUBLIC_ACCESS_BLOCK and injects into AGENTS.md managed sections for both new file creation and updates.
Gemini GEMINI.md Public Access Guidance
packages/lib/src/core/templates-entrypoint/gemini.ts
Conditionally populates GEMINI_PUBLIC_ACCESS_BLOCK with public IP/URL instructions and injects into generated GEMINI.md content.
Test Coverage for Public IP Detection
packages/app/tests/docker-git/entrypoint-auth.test.ts
Asserts DOCKER_GIT_PUBLIC_IP setup, docker_git_detect_public_ip() invocation, profile configuration, and Russian prompt text references appear with expected frequency.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through clouds so high,
Finding public IPs in the sky!
No more localhost in the prompt today,
The container's true face comes out to play.
Hoppy coding! 🌍✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check nameStatusExplanationResolution
Description check❓ InconclusiveThe description lacks required template sections like 'Source TZ / Issues' and 'Requirements Alignment', though it provides testing steps and mentions closing issue #78.Add 'Fixes #78' under 'Source TZ / Issues' section and populate 'Requirements Alignment' to clarify scope and security implications.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly summarizes the main change: detecting container public IP and using it in managed agent prompts.
Linked Issues check✅ PassedChanges successfully implement public IP detection in entrypoint and inject guidance into Codex, Claude, and Gemini prompts, addressing issue #78's requirement.
Out of Scope Changes check✅ PassedAll changes are directly related to detecting and exposing container public IP in agent prompts per issue #78, with no unrelated modifications.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch issue-78-public-container-ip

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/lib/src/core/templates-entrypoint/base.ts`:
- Around line 95-99: The candidate IP selection and serialization logic should
validate IPv4 addresses and safely escape before persisting: restrict the
hostname -I awk filter to only emit IPv4 tokens (e.g., match
/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) so candidate only becomes an IPv4, then
after detection add an explicit IPv4 format check on the candidate variable
before accepting it; finally, when printing/serializing DOCKER_GIT_PUBLIC_IP for
writing into shell startup files, use a shell-escaping safe formatter (replace
printf "%s" "$candidate" with a quoted/escaped form, e.g., using printf "%q" or
equivalent) so the value is safely escaped when sourced. Ensure changes
reference the candidate variable, the hostname -I | awk filter, and the printf
serialization call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 15f28693-b092-4816-bb34-688354955c62

📥 Commits

Reviewing files that changed from the base of the PR and between f964400 and 5294195.

📒 Files selected for processing (6)
  • packages/app/tests/docker-git/entrypoint-auth.test.ts
  • packages/lib/src/core/templates-entrypoint.ts
  • packages/lib/src/core/templates-entrypoint/base.ts
  • packages/lib/src/core/templates-entrypoint/claude-extra-config.ts
  • packages/lib/src/core/templates-entrypoint/codex.ts
  • packages/lib/src/core/templates-entrypoint/gemini.ts

Comment on lines +95 to +99
if [[ -z "$candidate" ]] && command -v hostname >/dev/null 2>&1; then
candidate="$(hostname -I 2>/dev/null | awk '{for (i = 1; i <= NF; i += 1) if ($i != "127.0.0.1") { print $i; exit }}')"
fi

printf "%s" "$candidate"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Verify current unsafe serialization and weak fallback filtering in the reviewed file.
rg -n 'hostname -I' packages/lib/src/core/templates-entrypoint/base.ts
rg -n 'export DOCKER_GIT_PUBLIC_IP="\$DOCKER_GIT_PUBLIC_IP"' packages/lib/src/core/templates-entrypoint/base.ts
rg -n '^[[:space:]]*local ipv4_regex=|~ /\\^\\[0-9\\]\\+' packages/lib/src/core/templates-entrypoint/base.ts

Repository: ProverCoderAI/docker-git

Length of output: 251


🏁 Script executed:

cat -n packages/lib/src/core/templates-entrypoint/base.ts | head -130 | tail -60

Repository: ProverCoderAI/docker-git

Length of output: 2786


Validate and safely serialize DOCKER_GIT_PUBLIC_IP before persisting it to shell startup files.

Line 96 can accept non-IPv4 tokens from hostname -I, and line 107 interpolates the value directly into a sourced shell script without format validation. A non-IPv4 address (IPv6 or other token) violates expected IP format and can break downstream service URL construction.

The fix adds IPv4 format validation in the awk filter and post-detection check, then uses printf %q for safe escaping during serialization.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/lib/src/core/templates-entrypoint/base.ts` around lines 95 - 99, The
candidate IP selection and serialization logic should validate IPv4 addresses
and safely escape before persisting: restrict the hostname -I awk filter to only
emit IPv4 tokens (e.g., match /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) so candidate
only becomes an IPv4, then after detection add an explicit IPv4 format check on
the candidate variable before accepting it; finally, when printing/serializing
DOCKER_GIT_PUBLIC_IP for writing into shell startup files, use a shell-escaping
safe formatter (replace printf "%s" "$candidate" with a quoted/escaped form,
e.g., using printf "%q" or equivalent) so the value is safely escaped when
sourced. Ensure changes reference the candidate variable, the hostname -I | awk
filter, and the printf serialization call.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant

@skulidropek