Skip to content

Phase 1.5: Documentation extraction - #3

Merged
jwbron merged 11 commits into
jib/phase-1-setupfrom
jib/phase-1.5-docs
Feb 2, 2026
Merged

jwbron merged 11 commits into
jib/phase-1-setupfrom
jib/phase-1.5-docs

Conversation

@james-in-a-box

@james-in-a-box james-in-a-box Bot commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase 1.5 of the egg extraction: extract and create documentation.

Changes

  • docs/security.md: Core security model and threat mitigations
  • docs/architecture.md: System architecture overview
  • docs/adr/git-isolation-architecture.md: Git worktree isolation ADR
  • docs/adr/credential-injection.md: Credential injection ADR
  • docs/configuration.md: Configuration reference
  • docs/setup.md: Setup guide
  • docs/api.md: Gateway API reference
  • docs/troubleshooting.md: Common issues and solutions

All documentation extracted from james-in-a-box and adapted for egg.

Validation Plan

# 1. Checkout the branch (after merging PR #2)
cd /tmp/egg-test  # or wherever you cloned
git fetch origin
git checkout jib/phase-1.5-docs

# 2. Verify all doc files exist
ls -la docs/*.md docs/adr/*.md
# Expected: security.md, architecture.md, configuration.md, 
#           setup.md, api.md, troubleshooting.md, testing.md
#           adr/git-isolation-architecture.md, adr/credential-injection.md

# 3. Check for james-in-a-box references that should be egg
grep -r "james-in-a-box" docs/ || echo "No james-in-a-box references (good)"
grep -r "jib-gateway" docs/ || echo "No jib-gateway references (good)"
# Expected: No matches (all should be egg-*)

# 4. Verify docs render (spot check)
head -50 docs/security.md
head -50 docs/api.md
# Expected: Well-formatted markdown with egg-specific content

# 5. Verify links in README point to docs
grep -E "\[.*\]\(docs/" README.md
# Expected: Links to architecture.md, configuration.md, security.md, etc.

# 6. Run tests (should still pass)
./dev native test
# Expected: 4 tests pass

Authored-by: jib

jwbron and others added 11 commits February 2, 2026 21:31
Extract and create documentation for the egg repository:

- docs/security.md: Core security model and threat mitigations
- docs/adr/git-isolation-architecture.md: Git worktree isolation ADR
- docs/adr/credential-injection.md: Credential injection ADR
- docs/configuration.md: Configuration reference
- docs/setup.md: Setup guide
- docs/api.md: Gateway API reference
- docs/troubleshooting.md: Common issues and solutions

Security documentation extracted from james-in-a-box ADRs:
- ADR-Gateway-Credential-Injection.md
- ADR-Git-Isolation-Architecture.md
- ADR-Anthropic-API-Credential-Injection.md

All docs regenerated for egg (no james-specific references).

Authored-by: jib
Extract ADR-Internet-Tool-Access-Lockdown from james-in-a-box as
docs/adr/network-isolation.md. This documents the private mode
network lockdown feature including:

- Public vs private network modes
- Docker network topology for isolation
- Domain allowlist (Anthropic + GitHub only)
- Squid proxy configuration
- WebSearch/WebFetch blocking in private mode
- Breakout prevention mechanisms

Also adds ADR section to README and updates security.md references.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add Related ADRs sections to credential-injection.md and
git-isolation-architecture.md for bidirectional navigation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add name explanation (inspired by Andy Weir's "The Egg")
- Add threat/mitigation table showing security guarantees
- Rewrite architecture diagram for cleaner rendering
- Expand Key Features with detailed sections:
  - Zero Credential Exposure
  - Git Isolation via Gateway-Managed Worktrees
  - Granular Access Control
  - Public and Private Network Modes
  - Comprehensive Audit Trail
- Improve Quick Start with credential setup steps

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace the brief security overview with a full security model document
covering:

1. Threat Model - adversary capabilities, protected assets, security boundaries
2. Architecture Overview - component diagrams, security properties summary
3. Network Isolation - public/private modes, domain allowlist, Squid config,
   DNS tunneling prevention, ECH/ESNI handling
4. Credential Isolation - zero-credential sandbox, token lifecycle,
   gateway authentication
5. Git/GitHub Lockdown - metadata isolation, gateway policies, blocked
   operations and flags
6. Private Repository Mode - visibility enforcement, caching strategy
7. Audit Logging - structured JSON format, alerting
8. Residual Risks - honest assessment of remaining attack vectors
9. OWASP Alignment - maps to OWASP Top 10 for Agentic Applications

Adapted from james-in-a-box Sandbox-Security-Proposal.md (PR #659).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update README threat table, private mode description, and CLI flags
- Update security.md and network-isolation.md for consistency
- Keep original architecture diagram (to be fixed separately)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@jwbron jwbron left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Validation Complete ✓

All checks pass:

  • All documentation files present (10 files including 3 ADRs)
  • No inappropriate james-in-a-box/jib-gateway references (only provenance in ADR headers)
  • README links to all documentation
  • Tests pass (4/4)

Documentation quality:

  • Comprehensive security whitepaper with OWASP alignment
  • Clear architecture diagrams in ADRs
  • Practical configuration and troubleshooting guides
  • Good cross-references between ADRs

Additions during review:

  • Added network-isolation.md ADR (extracted from james-in-a-box)
  • Expanded security.md into comprehensive security whitepaper
  • Enhanced README with threat table and feature highlights
  • Clarified "private GitHub repos only" in private mode descriptions
  • Added Related ADRs sections for bidirectional cross-references

Ready to merge.

@jwbron
jwbron merged commit f234bc6 into jib/phase-1-setup Feb 2, 2026
jwbron added a commit that referenced this pull request Feb 2, 2026
* Phase 1: Repository setup and CI infrastructure

Implement Phase 1 of the egg extraction plan:

- Create repository structure with gateway/, sandbox/, cli/, shared/, tests/
- Add pyproject.toml with uv for dependency management
- Add GitHub Actions workflows (lint.yml, test.yml)
- Add ./dev wrapper script for CI parity (runs act locally)
- Add pre-commit configuration
- Add Dependabot configuration
- Write README.md with architecture overview
- Write CONTRIBUTING.md with development guidelines
- Add egg.yaml.example and secrets.yaml.example
- Create module structure with __init__.py files
- Add initial unit tests for module imports
- Add docs/testing.md and docs/architecture.md

This establishes the infrastructure before extracting gateway code in Phase 2.

Authored-by: jib

* Fix dev script and pyproject.toml for broader compatibility

- Remove sudo requirement from act installation by installing to
  $HOME/.local/bin instead of system-wide
- Add hatchling build config specifying packages to include
- Add uv.lock for reproducible builds

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Phase 1.5: Documentation extraction (#3)

* Phase 1.5: Documentation extraction

Extract and create documentation for the egg repository:

- docs/security.md: Core security model and threat mitigations
- docs/adr/git-isolation-architecture.md: Git worktree isolation ADR
- docs/adr/credential-injection.md: Credential injection ADR
- docs/configuration.md: Configuration reference
- docs/setup.md: Setup guide
- docs/api.md: Gateway API reference
- docs/troubleshooting.md: Common issues and solutions

Security documentation extracted from james-in-a-box ADRs:
- ADR-Gateway-Credential-Injection.md
- ADR-Git-Isolation-Architecture.md
- ADR-Anthropic-API-Credential-Injection.md

All docs regenerated for egg (no james-specific references).

Authored-by: jib

* Add network isolation ADR

Extract ADR-Internet-Tool-Access-Lockdown from james-in-a-box as
docs/adr/network-isolation.md. This documents the private mode
network lockdown feature including:

- Public vs private network modes
- Docker network topology for isolation
- Domain allowlist (Anthropic + GitHub only)
- Squid proxy configuration
- WebSearch/WebFetch blocking in private mode
- Breakout prevention mechanisms

Also adds ADR section to README and updates security.md references.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add cross-references between ADRs

Add Related ADRs sections to credential-injection.md and
git-isolation-architecture.md for bidirectional navigation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Improve README to better showcase egg's robustness

- Add name explanation (inspired by Andy Weir's "The Egg")
- Add threat/mitigation table showing security guarantees
- Rewrite architecture diagram for cleaner rendering
- Expand Key Features with detailed sections:
  - Zero Credential Exposure
  - Git Isolation via Gateway-Managed Worktrees
  - Granular Access Control
  - Public and Private Network Modes
  - Comprehensive Audit Trail
- Improve Quick Start with credential setup steps

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Expand security.md into comprehensive security whitepaper

Replace the brief security overview with a full security model document
covering:

1. Threat Model - adversary capabilities, protected assets, security boundaries
2. Architecture Overview - component diagrams, security properties summary
3. Network Isolation - public/private modes, domain allowlist, Squid config,
   DNS tunneling prevention, ECH/ESNI handling
4. Credential Isolation - zero-credential sandbox, token lifecycle,
   gateway authentication
5. Git/GitHub Lockdown - metadata isolation, gateway policies, blocked
   operations and flags
6. Private Repository Mode - visibility enforcement, caching strategy
7. Audit Logging - structured JSON format, alerting
8. Residual Risks - honest assessment of remaining attack vectors
9. OWASP Alignment - maps to OWASP Top 10 for Agentic Applications

Adapted from james-in-a-box Sandbox-Security-Proposal.md (PR #659).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Clarify private mode restricts to private GitHub repos only

- Update README threat table, private mode description, and CLI flags
- Update security.md and network-isolation.md for consistency
- Keep original architecture diagram (to be fixed separately)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update credential-injection.md

* Update git-isolation-architecture.md

* Update network-isolation.md

* Update security.md

* Update README.md

---------

Co-authored-by: James Wiesebron <jameswiesebron@khanacademy.org>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: James <8340608+jwbron@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: james-in-a-box[bot] <246424927+james-in-a-box[bot]@users.noreply.github.com>
james-in-a-box Bot pushed a commit that referenced this pull request Feb 6, 2026
Gap #4 (cmd[2:2] fragility): Add LIFECYCLE_FLAGS_INDEX constant to make
the implicit contract explicit. Callers now reference the module constant
instead of hardcoding the magic number. Added a test that verifies the
constant value, so changes to the builder's structure will fail tests.

Gap #5 (container_ip): run_claude_structured() now allocates a static IP
for test containers via _allocate_test_container_ip(). This matches
production where sessions are bound to specific container IPs for request
verification.

Gap #3 (public mode E2E): Created issue #168 to track adding E2E test
coverage for public mode container launches.

Authored-by: egg
jwbron added a commit that referenced this pull request Feb 6, 2026
* Extract shared build_sandbox_docker_cmd() for container launches

Container-launch command construction was duplicated across three call
sites (run_claude, exec_in_new_container, E2E conftest), causing
divergence bugs like missing --add-host and wrong env var names.
The test harness was also missing PRIVATE_MODE, DNS lockdown, proxy
config, RUNTIME_UID/GID, CONTAINER_ID, and --security-opt.

This extracts a single build_sandbox_docker_cmd() into a new
shared/egg_container module that all three sites now call, with 26
unit tests covering private/public mode, optional params, and the
caller insertion conventions.

* Fix ruff format issues

* Address review feedback: add ANTHROPIC_AUTH_METHOD and document coupling

Addresses two gaps from the audit review:

1. Tests now set ANTHROPIC_AUTH_METHOD=oauth to match production behavior.
   Production callers always set this env var (api_key or oauth), but the
   test was only passing ANTHROPIC_OAUTH_TOKEN. This ensures sandbox
   startup code branches the same way in tests as in production.

2. Added docstring to run_claude_structured() documenting the network
   config coupling. The test constructs ContainerNetworkConfig manually
   from EggStack values rather than calling _get_container_network_config().
   If that function changes, the test must be updated to match.

Authored-by: egg

* Address review gaps #4 and #5, create issue for #3

Gap #4 (cmd[2:2] fragility): Add LIFECYCLE_FLAGS_INDEX constant to make
the implicit contract explicit. Callers now reference the module constant
instead of hardcoding the magic number. Added a test that verifies the
constant value, so changes to the builder's structure will fail tests.

Gap #5 (container_ip): run_claude_structured() now allocates a static IP
for test containers via _allocate_test_container_ip(). This matches
production where sessions are bound to specific container IPs for request
verification.

Gap #3 (public mode E2E): Created issue #168 to track adding E2E test
coverage for public mode container launches.

Authored-by: egg

---------

Co-authored-by: egg <egg@example.com>
Co-authored-by: jwbron <8340608+jwbron@users.noreply.github.com>
james-in-a-box Bot pushed a commit that referenced this pull request Feb 7, 2026
Fix critical issues from review:
- Task ID convention mismatch: Parser now generates task-{phase}-{number}
  format matching CLI expectations (Issue #3)
- Integer parsing vulnerability: Added parse_task_id() and parse_phase_id()
  helpers with proper validation and error handling (Issue #1)
- URL parameter injection: Use urllib.parse.urlencode for query params (Issue #2)
- Placeholder task numbering: Use task_number=1 instead of 0 (Issue #5)
- Silent failure in shell script: gh_api_safe now sets GH_API_FAILED flag
  and returns empty JSON for graceful fallback (Issue #6)

Additional improvements:
- Updated Task model pattern to accept task-P-N format
- Added comprehensive test coverage for error paths
- Added edge case tests for plan parser
- All 73 tests pass, ruff linter clean

Authored-by: egg
jwbron added a commit that referenced this pull request Feb 7, 2026
* Implement Phase 3: Agent CLI and prompt integration

Add the agent-facing components for the SDLC pipeline:

- Contract CLI (egg-contract) for agents to interact with contract state:
  - show: Display current contract state
  - add-commit: Link commits to tasks
  - update-notes: Add implementation notes
  - mark-task/mark-phase: Update status (reviewer role)
  - add-decision: Create HITL decision points

- Agent rules file (contract.md) with CLI usage guidance

- Document templates for refine and plan phases:
  - analysis.md: Problem analysis template
  - plan.md: Implementation plan template with task ID format

- SDLC prompt builder that provides phase-specific context and
  instructions to the agent

- Plan parser for extracting tasks from plan documents:
  - Parses [TASK-X-Y] patterns from markdown
  - Supports YAML front matter for structured task definitions
  - Generates placeholder tasks for empty phases
  - Produces warnings for parse issues

- Unit tests for plan parser and contract CLI

Issue: #133

Authored-by: egg

* Fix bash syntax error in build-sdlc-prompt.sh

Change the inner heredoc delimiter in the PR format example from 'EOF'
to 'BODY' to avoid conflicting with the outer heredoc delimiter. The
'EOF' on line 363 was being interpreted as the end of the outer heredoc
(starting at line 322), causing a syntax error on the closing ')'.

Authored-by: egg

* Fix lint and type errors in Phase 3 contracts code

- Fix import sorting in shared/egg_contracts/__init__.py (I001)
- Fix import sorting in tests/sandbox/test_contract_cli.py (I001)
- Fix unused variable in tests/sandbox/test_contract_cli.py (F841)
- Fix import sorting and remove unused import in tests/shared/egg_contracts/test_plan_parser.py (I001, F401)
- Fix mypy type annotation in shared/egg_contracts/plan_parser.py
- Fix mypy no-any-return errors in sandbox/egg_lib/contract_cli.py
- Apply ruff formatting fixes

Authored-by: egg

* Address code review feedback for Phase 3 implementation

Fix critical issues from review:
- Task ID convention mismatch: Parser now generates task-{phase}-{number}
  format matching CLI expectations (Issue #3)
- Integer parsing vulnerability: Added parse_task_id() and parse_phase_id()
  helpers with proper validation and error handling (Issue #1)
- URL parameter injection: Use urllib.parse.urlencode for query params (Issue #2)
- Placeholder task numbering: Use task_number=1 instead of 0 (Issue #5)
- Silent failure in shell script: gh_api_safe now sets GH_API_FAILED flag
  and returns empty JSON for graceful fallback (Issue #6)

Additional improvements:
- Updated Task model pattern to accept task-P-N format
- Added comprehensive test coverage for error paths
- Added edge case tests for plan parser
- All 73 tests pass, ruff linter clean

Authored-by: egg

* Remove unused GH_API_FAILED variable from build-sdlc-prompt.sh

The GH_API_FAILED variable was declared and set but never read,
triggering shellcheck SC2034 warning. The variable has been removed
as the functionality was never implemented.

Authored-by: egg

* Address remaining PR review feedback

- Fix add-decision RBAC: Add decisions.* to FIELD_OWNERSHIP with
  IMPLEMENTER role, allowing implementers to create decisions while
  only humans can resolve them.

- Fix array append in validator: Handle appending to arrays when
  idx == len(array) by appending instead of raising IndexError.
  Also handle the case in apply_mutation where old_value doesn't
  exist yet for append operations.

- Document race condition in add-decision: Added comments explaining
  the TOCTOU race condition between reading decision count and
  submitting mutation. Gateway should handle conflicts.

- Fix mark-task/mark-phase role documentation: Updated docstrings
  and help text to clarify these operations require REVIEWER role.

- Add commit SHA validation: New validate_commit_sha() function
  validates 7-40 character hex strings for git SHAs.

- Fix short question ellipsis: Only append "..." if question is
  longer than 50 characters.

- Add comprehensive tests for new functionality including commit
  SHA validation and array append operations.

Authored-by: egg

* Fix ruff format issue in contract_cli.py

Collapse multi-line ValueError string to single line to satisfy
ruff format requirements.

Authored-by: egg

* Address low-severity review feedback

- Add integration tests verifying plan parser task IDs are compatible
  with the CLI's parse_task_id() function
- Add RETURN trap in gh_api_safe() to clean up temp files on interruption
- Refactor MockGatewayHandler to use a factory function that creates
  handler classes with isolated responses, ensuring thread safety when
  running tests in parallel
- Generate unique HEREDOC delimiter using random suffix to prevent
  injection if issue body contains the delimiter string

Authored-by: egg

---------

Co-authored-by: jwbron <8340608+jwbron@users.noreply.github.com>
Co-authored-by: james-in-a-box[bot] <246424927+james-in-a-box[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant