Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix: harden devcontainer worktree startup
JerrettDavisfdf7d1e1381c
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.jsonindex 5ef065973..f5986e910 100644--- a/.devcontainer/devcontainer.json+++ b/.devcontainer/devcontainer.json@@ -10,7 +10,7 @@},"ghcr.io/devcontainers/features/github-cli:1": {}},- "workspaceFolder": "/workspaces/headroom",+ "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}","remoteUser": "vscode","updateRemoteUserUID": true,"init": true,@@ -21,12 +21,13 @@"UV_PROJECT_ENVIRONMENT": "/home/vscode/.venvs/headroom"},"mounts": [- "source=headroom-venv,target=/home/vscode/.venvs,type=volume",+ "source=headroom-venv-${localWorkspaceFolderBasename},target=/home/vscode/.venvs,type=volume","source=headroom-uv-cache,target=/home/vscode/.cache/uv,type=volume",- "source=headroom-pip-cache,target=/home/vscode/.cache/pip,type=volume"+ "source=headroom-pip-cache,target=/home/vscode/.cache/pip,type=volume",+ "source=${localWorkspaceFolder}/../../../../../../../../,target=/workspaces-host,type=bind,consistency=cached"],"postCreateCommand": "bash .devcontainer/post-create.sh",- "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",+ "postStartCommand": "bash -lc 'git rev-parse --git-dir >/dev/null 2>&1 && git config --global --add safe.directory \"${containerWorkspaceFolder}\" || true'","forwardPorts": [8787],diff --git a/.devcontainer/docker-compose.memory.yml b/.devcontainer/docker-compose.memory.ymlindex ddccfab40..c15c828d0 100644--- a/.devcontainer/docker-compose.memory.yml+++ b/.devcontainer/docker-compose.memory.yml@@ -10,7 +10,8 @@ services:UV_LINK_MODE: copyUV_PROJECT_ENVIRONMENT: /home/vscode/.venvs/headroom-memoryvolumes:- - ..:/workspaces/headroom:cached+ - ..:/workspaces:cached+ - ../../../../../../../../:/workspaces-host:cached- headroom-venv-memory:/home/vscode/.venvs- headroom-uv-cache:/home/vscode/.cache/uv- headroom-pip-cache:/home/vscode/.cache/pipdiff --git a/.devcontainer/memory-stack/devcontainer.json b/.devcontainer/memory-stack/devcontainer.jsonindex fb2e12520..440824905 100644--- a/.devcontainer/memory-stack/devcontainer.json+++ b/.devcontainer/memory-stack/devcontainer.json@@ -8,7 +8,7 @@"qdrant","neo4j"],- "workspaceFolder": "/workspaces/headroom",+ "workspaceFolder": "/workspaces","remoteUser": "vscode","updateRemoteUserUID": true,"shutdownAction": "stopCompose",@@ -50,7 +50,7 @@}},"postCreateCommand": "bash .devcontainer/post-create.sh memory-stack",- "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",+ "postStartCommand": "bash -lc 'git rev-parse --git-dir >/dev/null 2>&1 && git config --global --add safe.directory \"${containerWorkspaceFolder}\" || true'","customizations": {"vscode": {"extensions": [diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.shindex 23e487db5..92089f704 100644--- a/.devcontainer/post-create.sh+++ b/.devcontainer/post-create.sh@@ -3,17 +3,74 @@ set -euo pipefailprofile="${1:-default}"project_env="${UV_PROJECT_ENVIRONMENT:-/home/vscode/.venvs/headroom}"+project_env_root="$(dirname "$project_env")"+cache_root="${HOME}/.cache"+script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"+workspace_root="$(cd "$script_dir/.." && pwd)"+git_profile_script="/etc/profile.d/headroom-worktree-git.sh"sync_extras=(--extra dev)if [[ "$profile" == "memory-stack" ]]; thensync_extras+=(--extra memory-stack)fi-cd /workspaces/headroom+cd "$workspace_root"++configure_worktree_git_env() {+ sudo rm -f "$git_profile_script"++ if git rev-parse --show-toplevel >/dev/null 2>&1; then+ return 0+ fi++ if [[ ! -f .git ]]; then+ return 1+ fi++ local gitdir_spec repo_root translated_git_dir translated_common_dir+ gitdir_spec="$(sed -n 's/^gitdir: //p' .git)"++ if [[ -z "$gitdir_spec" || "$gitdir_spec" != *"/.git/worktrees/"* ]]; then+ return 1+ fi++ repo_root="${gitdir_spec%/.git/worktrees/*}"++ if [[ "$gitdir_spec" =~ ^[A-Za-z]:/ ]]; then+ translated_git_dir="/workspaces-host/${gitdir_spec#?:/}"+ translated_common_dir="/workspaces-host/${repo_root#?:/}/.git"+ elif [[ "$gitdir_spec" == /* ]]; then+ translated_git_dir="/workspaces-host${gitdir_spec}"+ translated_common_dir="/workspaces-host${repo_root}/.git"+ else+ return 1+ fi++ if [[ ! -d "$translated_git_dir" || ! -d "$translated_common_dir" ]]; then+ return 1+ fi++ sudo tee "$git_profile_script" >/dev/null <<EOF+export GIT_DIR="$translated_git_dir"+export GIT_COMMON_DIR="$translated_common_dir"+export GIT_WORK_TREE="$workspace_root"+EOF++ # shellcheck disable=SC1091+ source "$git_profile_script"+ git rev-parse --show-toplevel >/dev/null 2>&1+}++sudo mkdir -p "$project_env_root" "$cache_root/uv" "$cache_root/pip" "$cache_root/pre-commit"+sudo chown -R "$(id -u):$(id -g)" "$project_env_root" "$cache_root"uv sync --frozen "${sync_extras[@]}" --link-mode copy-uv run pre-commit install+if configure_worktree_git_env; then+ uv run pre-commit install+else+ echo "Skipping pre-commit install because git metadata is not available inside this container."+fiecho "Headroom devcontainer is ready."if [[ "$profile" == "memory-stack" ]]; thendiff --git a/.github/workflows/devcontainers.yml b/.github/workflows/devcontainers.ymlindex 189eb54c8..1f9bb4e16 100644--- a/.github/workflows/devcontainers.yml+++ b/.github/workflows/devcontainers.yml@@ -50,7 +50,33 @@ jobs:shell: bashrun: |if [[ "${{ matrix.name }}" == "memory-stack" ]]; then- devcontainer exec --workspace-folder . bash -lc 'uv --version && node --version && gh --version >/dev/null && python -c "import socket; socket.create_connection((\"qdrant\", 6333), 5).close(); socket.create_connection((\"neo4j\", 7687), 5).close(); from mem0 import Memory; from qdrant_client import QdrantClient; import neo4j; import headroom; print(\"memory-stack smoke test passed\")"'+ devcontainer exec --workspace-folder . --config ${{ matrix.config }} bash -lc 'git rev-parse --show-toplevel >/dev/null && uv --version && node --version && gh --version >/dev/null && uv run python -c "import socket; socket.create_connection((\"qdrant\", 6333), 5).close(); socket.create_connection((\"neo4j\", 7687), 5).close(); from mem0 import Memory; from qdrant_client import QdrantClient; import neo4j; import headroom; print(\"memory-stack smoke test passed\")"'else- devcontainer exec --workspace-folder . bash -lc 'uv --version && node --version && gh --version >/dev/null && python -c "import headroom; print(\"default smoke test passed\")"'+ devcontainer exec --workspace-folder . --config ${{ matrix.config }} bash -lc 'git rev-parse --show-toplevel >/dev/null && uv --version && node --version && gh --version >/dev/null && uv run python -c "import headroom; print(\"default smoke test passed\")"'fi++ validate-worktree:+ runs-on: ubuntu-latest++ steps:+ - uses: actions/checkout@v4++ - name: Create linked worktree+ run: git worktree add "$RUNNER_TEMP/headroom-worktree" HEAD++ - name: Set up Node+ uses: actions/setup-node@v4+ with:+ node-version: "20"++ - name: Set up Docker Buildx+ uses: docker/setup-buildx-action@v3++ - name: Install Dev Container CLI+ run: npm install -g @devcontainers/[email protected]++ - name: Start linked worktree devcontainer+ run: devcontainer up --workspace-folder "$RUNNER_TEMP/headroom-worktree" --config "$RUNNER_TEMP/headroom-worktree/.devcontainer/devcontainer.json" --remove-existing-container++ - name: Smoke test linked worktree+ run: devcontainer exec --workspace-folder "$RUNNER_TEMP/headroom-worktree" --config "$RUNNER_TEMP/headroom-worktree/.devcontainer/devcontainer.json" bash -lc 'git rev-parse --show-toplevel && uv run python -c "import headroom; print(\"worktree smoke test passed\")"'