Skip to content

Add session information environment variable for easy AI context access #42

@GordonBeeming

Description

@GordonBeeming

Summary

Users and AI assistants need quick access to session information (mounts, image, mode, etc.) without scrolling through startup logs. This feature adds a COPILOT_HERE_SESSION_INFO environment variable containing structured JSON data about the current session, along with a helper command session-info for easy viewing.

Problem

  • Startup logs scroll off screen in long sessions
  • AI assistants can't easily reference environment details (mounts, image variant, mode)
  • No programmatic way to query session configuration
  • Users have to manually remember what directories are mounted

Expected Usage / Use Cases

Use Case 1: Quick Session Info Display

User wants to see their current session configuration formatted nicely:

# Inside copilot_here container
!session-info

Expected Output:

{
    "copilot_here_version": "2025.12.19",
    "image": {
        "tag": "dotnet-rust",
        "full_name": "ghcr.io/gordonbeeming/copilot_here:dotnet-rust"
    },
    "mode": "yolo",
    "working_directory": "/home/appuser/Developer/github/gordonbeeming/copilot_here",
    "mounts": [
        {
            "host_path": "/Users/gordonbeeming/Developer/github/gordonbeeming/copilot_here/default-airlock-rules.json",
            "container_path": "/home/appuser/Developer/github/gordonbeeming/copilot_here/default-airlock-rules.json",
            "mode": "ro",
            "source": "local"
        },
        {
            "host_path": "/Users/gordonbeeming/Developer/github/gordonbeeming/xylem/data/blog",
            "container_path": "/home/appuser/Developer/github/gordonbeeming/xylem/data/blog",
            "mode": "rw",
            "source": "global"
        }
    ],
    "airlock": {
        "enabled": false,
        "rules_path": "",
        "source": "local"
    }
}

Use Case 2: Manual Python Formatting (Workaround)

User on older image or preferring manual approach:

!echo $COPILOT_HERE_SESSION_INFO | python3 -m json.tool

Expected Output: Same formatted JSON as above

Use Case 3: AI Assistant Context

AI assistant needs to understand the environment without scrolling:

User: "Can you access my blog files?"
AI: Let me check... *runs session-info*
    Yes! I can see you have /Users/gordonbeeming/xylem/data/blog mounted as read-write.

Use Case 4: Querying Specific Info with jq

User wants to extract specific information:

# Get current image tag
!echo $COPILOT_HERE_SESSION_INFO | jq -r .image.tag

# List all mounted paths
!echo $COPILOT_HERE_SESSION_INFO | jq -r '.mounts[].container_path'

# Check if airlock is enabled
!echo $COPILOT_HERE_SESSION_INFO | jq .airlock.enabled

Acceptance Criteria

  • Environment variable COPILOT_HERE_SESSION_INFO is set in all containers
  • Variable contains JSON with: version, image, mode, working directory, mounts, airlock status
  • Mounts show resolved absolute paths (not ~/ shortcuts)
  • session-info command installed in Docker images for formatted output
  • Fallback to Python json.tool if jq not available
  • Works in both standard and Airlock modes
  • Airlock mode includes network config details (rules count, sample domains)
  • AOT-compatible implementation (no reflection/dynamic code)
  • Documentation updated in README
  • Task documentation created

Solution Implemented

Components Added

  1. SessionInfo.cs - AOT-compatible JSON builder

    • Manual string building (no reflection)
    • Resolves paths to absolute
    • Standard and Airlock modes
  2. session-info.sh - Helper script

    • Tries jq first
    • Falls back to Python json.tool
    • Installed in all Docker images
  3. Environment Variable Integration

    • RunCommand passes to Docker
    • AirlockRunner includes in compose file
    • Available immediately in container

Files Changed

  • app/Infrastructure/SessionInfo.cs (new)
  • app/Commands/Run/RunCommand.cs
  • app/Infrastructure/AirlockRunner.cs
  • app/Resources/docker-compose.airlock.yml.template
  • docker/Dockerfile.base
  • docker/session-info.sh (new)
  • README.md
  • docs/tasks/20251229-01-session-info-env-var.md

Testing Performed

  • Native binary builds without warnings
  • Standard mode shows session info
  • YOLO mode shows session info
  • session-info command works
  • Python fallback works
  • Paths are fully resolved (absolute)
  • Tested with dotnet-rust variant

Benefits

  • AI assistants can instantly reference environment
  • No filesystem pollution (env var only)
  • Ephemeral (cleaned when container stops)
  • Queryable with jq/Python
  • Works in all modes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions