mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
Merge remote-tracking branch 'upstream/main' into claude/4302-fix
This commit is contained in:
@@ -5,14 +5,14 @@
|
||||
},
|
||||
"metadata": {
|
||||
"description": "Headroom marketplace for Claude Code and GitHub Copilot CLI plugins.",
|
||||
"version": "0.41.0"
|
||||
"version": "0.42.0"
|
||||
},
|
||||
"plugins": [
|
||||
{
|
||||
"name": "headroom",
|
||||
"source": "./plugins/headroom-agent-hooks",
|
||||
"description": "Headroom startup hooks for Claude Code and GitHub Copilot CLI.",
|
||||
"version": "0.41.0",
|
||||
"version": "0.42.0",
|
||||
"author": {
|
||||
"name": "Headroom Contributors",
|
||||
"url": "https://github.com/headroomlabs-ai/headroom"
|
||||
@@ -30,7 +30,7 @@
|
||||
"name": "headroom-snip",
|
||||
"source": "./plugins/headroom-snip",
|
||||
"description": "Claude Code mod: watch Headroom snip tokens off every request, with an animated band, a /headroom log and a running total.",
|
||||
"version": "0.41.0",
|
||||
"version": "0.42.0",
|
||||
"author": {
|
||||
"name": "Headroom Contributors",
|
||||
"url": "https://github.com/headroomlabs-ai/headroom"
|
||||
|
||||
@@ -7,7 +7,7 @@ jobs:
|
||||
smoke:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
||||
- name: Exercise production notification component
|
||||
uses: ./.github/actions/release-slack-notification
|
||||
with:
|
||||
|
||||
@@ -1,96 +1,25 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 880 240" width="880" height="240" role="img"
|
||||
aria-label="Headroom Enterprise for teams: 3 months free with a 12-month plan. Adds tool search, model routing, attack removal and org-wide savings. Claim the perk.">
|
||||
<title>Headroom Enterprise — 3 months free with a 12-month plan</title>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 880 200" width="880" height="200" role="img"
|
||||
aria-label="Headroom for teams and enterprises. Want more savings? Headroom OSS shows what is possible; Enterprise saves more. More cost savings, tokens secured, on premise, deep attribution and many more features. Talk to us: hello@headroomlabs.ai.">
|
||||
<title>Headroom for teams and enterprises — talk to us</title>
|
||||
|
||||
<defs>
|
||||
<!-- Brand palette as in hero.svg: Mint #00F0B5, Obsidian #070A0F,
|
||||
Midnight #0C1118, Cyan #65D8FF, White, Slate #98A4B3.
|
||||
Dark in both GitHub themes, matching the hero. -->
|
||||
<pattern id="pgrid" width="44" height="44" patternUnits="userSpaceOnUse">
|
||||
<path d="M44 0H0V44" fill="none" stroke="#00F0B5" stroke-opacity="0.05" stroke-width="1"/>
|
||||
</pattern>
|
||||
|
||||
<radialGradient id="pglow" cx="12%" cy="0%" r="80%">
|
||||
<stop offset="0%" stop-color="#00F0B5" stop-opacity="0.16"/>
|
||||
<stop offset="100%" stop-color="#00F0B5" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
|
||||
<linearGradient id="pedge" x1="0" y1="0" x2="1" y2="0">
|
||||
<stop offset="0%" stop-color="#00F0B5" stop-opacity="0.65"/>
|
||||
<stop offset="55%" stop-color="#65D8FF" stop-opacity="0.35"/>
|
||||
<stop offset="100%" stop-color="#65D8FF" stop-opacity="0.10"/>
|
||||
</linearGradient>
|
||||
|
||||
<linearGradient id="pbtn" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#00F0B5"/>
|
||||
<stop offset="100%" stop-color="#0FD9AE"/>
|
||||
</linearGradient>
|
||||
|
||||
<linearGradient id="pshine" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="70" y2="0">
|
||||
<stop offset="0%" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
<stop offset="50%" stop-color="#FFFFFF" stop-opacity="0.45"/>
|
||||
<stop offset="100%" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
|
||||
<clipPath id="pbtnclip"><rect x="646" y="94" width="208" height="58" rx="29"/></clipPath>
|
||||
|
||||
<!-- Brand palette and type scale as in hero.svg: Mint #00F0B5, Obsidian #070A0F,
|
||||
Slate #98A4B3, White; title 42/700, lead 14.5, eyebrow 10.5 tracked. -->
|
||||
<style>
|
||||
.s { font-family: "Segoe UI", Inter, -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif; }
|
||||
|
||||
/* One light pass over the button per cycle draws the eye to the action. */
|
||||
.shine { animation: shine 5s ease-in-out infinite; }
|
||||
@keyframes shine { 0%, 55% { transform: translateX(-80px) } 85%, 100% { transform: translateX(240px) } }
|
||||
|
||||
.dot { animation: beat 2.4s ease-in-out infinite; }
|
||||
@keyframes beat { 0%, 100% { opacity: 1 } 50% { opacity: .3 } }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.shine, .dot { animation: none; }
|
||||
.shine { opacity: 0; }
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
|
||||
<!-- Card. One font family, three sizes: 52 headline, 20 lead and button, 16 everything else. -->
|
||||
<rect x="1" y="1" width="878" height="238" rx="18" fill="#070A0F"/>
|
||||
<rect x="1" y="1" width="878" height="238" rx="18" fill="url(#pgrid)"/>
|
||||
<rect x="1" y="1" width="878" height="238" rx="18" fill="url(#pglow)"/>
|
||||
<rect x="1" y="1" width="878" height="238" rx="18" fill="none" stroke="url(#pedge)" stroke-width="1.5"/>
|
||||
<rect x="1" y="1" width="878" height="198" rx="18" fill="#070A0F" stroke="#00F0B5" stroke-opacity="0.35" stroke-width="1.5"/>
|
||||
|
||||
<g class="s">
|
||||
<!-- Eyebrow -->
|
||||
<circle class="dot" cx="46" cy="47" r="5" fill="#00F0B5"/>
|
||||
<text x="60" y="53" font-size="16" font-weight="600" letter-spacing="1.5" fill="#00F0B5">HEADROOM ENTERPRISE · FOR TEAMS</text>
|
||||
<text x="40" y="48" font-size="10.5" letter-spacing="1.6" fill="#00F0B5">HEADROOM FOR TEAMS & ENTERPRISES</text>
|
||||
<text x="40" y="96" font-size="42" font-weight="700" letter-spacing="-0.8" fill="#FFFFFF">Want more savings?</text>
|
||||
<text x="40" y="128" font-size="14.5" fill="#98A4B3">Headroom OSS shows what is possible. Enterprise saves more, and adds:</text>
|
||||
<text x="40" y="160" font-size="14.5" fill="#FFFFFF">More cost savings · Tokens secured · On premise · Deep attribution · and more</text>
|
||||
|
||||
<!-- Headline -->
|
||||
<text x="40" y="116" font-size="52" font-weight="700" fill="#FFFFFF">3 months free</text>
|
||||
<text x="40" y="152" font-size="20" fill="#98A4B3">with a 12-month plan · one perk per company</text>
|
||||
|
||||
<!-- What Enterprise adds -->
|
||||
<g font-size="16" fill="#E6EDF3">
|
||||
<rect x="40" y="178" width="118" height="36" rx="18" fill="#0C1118" stroke="#00F0B5" stroke-opacity="0.30"/>
|
||||
<text x="99" y="202" text-anchor="middle">Tool search</text>
|
||||
|
||||
<rect x="168" y="178" width="134" height="36" rx="18" fill="#0C1118" stroke="#00F0B5" stroke-opacity="0.30"/>
|
||||
<text x="235" y="202" text-anchor="middle">Model routing</text>
|
||||
|
||||
<rect x="312" y="178" width="140" height="36" rx="18" fill="#0C1118" stroke="#00F0B5" stroke-opacity="0.30"/>
|
||||
<text x="382" y="202" text-anchor="middle">Attack removal</text>
|
||||
|
||||
<rect x="462" y="178" width="156" height="36" rx="18" fill="#0C1118" stroke="#65D8FF" stroke-opacity="0.30"/>
|
||||
<text x="540" y="202" text-anchor="middle">Org-wide savings</text>
|
||||
</g>
|
||||
|
||||
<!-- Divider -->
|
||||
<line x1="634" y1="36" x2="634" y2="204" stroke="#98A4B3" stroke-opacity="0.18"/>
|
||||
|
||||
<!-- Call to action -->
|
||||
<text x="750" y="72" font-size="16" text-anchor="middle" fill="#98A4B3">SSO · VPC or managed</text>
|
||||
<g clip-path="url(#pbtnclip)">
|
||||
<rect x="646" y="94" width="208" height="58" rx="29" fill="url(#pbtn)"/>
|
||||
<rect class="shine" x="646" y="94" width="70" height="58" fill="url(#pshine)"/>
|
||||
</g>
|
||||
<text x="750" y="130" font-size="20" font-weight="700" text-anchor="middle" fill="#070A0F">Claim the perk →</text>
|
||||
<text x="750" y="190" font-size="16" text-anchor="middle" fill="#98A4B3">headroom-perks.vercel.app</text>
|
||||
<rect x="676" y="72" width="164" height="44" rx="22" fill="#00F0B5"/>
|
||||
<text x="758" y="99" font-size="14.5" font-weight="700" text-anchor="middle" fill="#070A0F">Talk to us →</text>
|
||||
<text x="758" y="140" font-size="13" text-anchor="middle" fill="#98A4B3">hello@headroomlabs.ai</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 1.7 KiB |
@@ -5,14 +5,14 @@
|
||||
},
|
||||
"metadata": {
|
||||
"description": "Headroom marketplace for Claude Code and GitHub Copilot CLI plugins.",
|
||||
"version": "0.41.0"
|
||||
"version": "0.42.0"
|
||||
},
|
||||
"plugins": [
|
||||
{
|
||||
"name": "headroom",
|
||||
"source": "./plugins/headroom-agent-hooks",
|
||||
"description": "Headroom startup hooks for Claude Code and GitHub Copilot CLI.",
|
||||
"version": "0.41.0",
|
||||
"version": "0.42.0",
|
||||
"author": {
|
||||
"name": "Headroom Contributors",
|
||||
"url": "https://github.com/headroomlabs-ai/headroom"
|
||||
|
||||
@@ -268,11 +268,11 @@ jobs:
|
||||
run: |
|
||||
python -m pip install --upgrade pip maturin
|
||||
maturin build --profile ci --out dist --interpreter python3.14
|
||||
- name: Install headroom-ai[sandbox] from prebuilt wheels only
|
||||
- name: Install headroom-ai[lean] from prebuilt wheels only
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
WHEEL="$(ls dist/*.whl)"
|
||||
python -m pip install --only-binary=:all: "${WHEEL}[sandbox]"
|
||||
python -m pip install --only-binary=:all: "${WHEEL}[lean]"
|
||||
- name: Proxy dependencies and LiteLLM pricing are available
|
||||
working-directory: ${{ runner.temp }}
|
||||
run: |
|
||||
@@ -747,6 +747,30 @@ jobs:
|
||||
tests/test_cli/test_wrap_opencode.py \
|
||||
tests/test_proxy_workspace_registration_middleware.py -q
|
||||
|
||||
windows-file-permissions:
|
||||
# Verifies the Windows NTFS-ACL path in headroom._fileperms_windows for
|
||||
# real: those tests were previously skipped everywhere, so the module
|
||||
# was asserted correct but never run (#4058). The mode-bits (POSIX)
|
||||
# assertions in the same file stay skipped here deliberately.
|
||||
needs: changes
|
||||
if: needs.changes.outputs.code == 'true'
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: ${{ env.PY_VERSION }}
|
||||
- name: Install headroom-ai[dev] (published wheel; local source shadows it)
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
||||
pip install "headroom-ai[dev]"
|
||||
- name: Run the owner-only file-permission tests
|
||||
shell: bash
|
||||
run: |
|
||||
pytest tests/test_cache_breakpoint_diagnostics.py tests/test_private_state_files.py -v
|
||||
|
||||
macos-native-wrapper:
|
||||
needs: changes
|
||||
if: needs.changes.outputs.native == 'true'
|
||||
|
||||
@@ -813,6 +813,11 @@ jobs:
|
||||
node-version: ">=24.16.0 <25"
|
||||
registry-url: ${{ env.NPM_REGISTRY_URL }}
|
||||
|
||||
- name: Verify npm publishing authentication
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: npm whoami --registry "${NPM_REGISTRY_URL}"
|
||||
|
||||
# No artifact download required: the publish steps below pack and
|
||||
# publish directly from the checked-out source tree (sdk/typescript
|
||||
# and plugins/openclaw) via `npm pack` + `npm publish`. The
|
||||
@@ -828,12 +833,15 @@ jobs:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
version="${{ needs.detect-version.outputs.npm_version }}"
|
||||
if npm view "${NPM_SDK_PACKAGE}@${version}" version --registry "${NPM_REGISTRY_URL}" >/dev/null 2>&1; then
|
||||
echo "${NPM_SDK_PACKAGE}@${version} is already published; continuing."
|
||||
exit 0
|
||||
fi
|
||||
cd sdk/typescript
|
||||
npm ci
|
||||
npm run build
|
||||
npm version "$version" --no-git-tag-version --allow-same-version
|
||||
npm publish --access public
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish ${{ env.NPM_OPENCLAW_PACKAGE }} to npmjs.org
|
||||
id: npm-openclaw-publish
|
||||
@@ -841,6 +849,10 @@ jobs:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
version="${{ needs.detect-version.outputs.npm_version }}"
|
||||
if npm view "${NPM_OPENCLAW_PACKAGE}@${version}" version --registry "${NPM_REGISTRY_URL}" >/dev/null 2>&1; then
|
||||
echo "${NPM_OPENCLAW_PACKAGE}@${version} is already published; continuing."
|
||||
exit 0
|
||||
fi
|
||||
cd plugins/openclaw
|
||||
npm ci
|
||||
npm run build
|
||||
@@ -854,7 +866,6 @@ jobs:
|
||||
EOF
|
||||
node prepare-dist.mjs
|
||||
npm publish --access public
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish ${{ env.NPM_OPENCODE_PACKAGE }} to npmjs.org
|
||||
id: npm-opencode-publish
|
||||
@@ -862,6 +873,10 @@ jobs:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
version="${{ needs.detect-version.outputs.npm_version }}"
|
||||
if npm view "${NPM_OPENCODE_PACKAGE}@${version}" version --registry "${NPM_REGISTRY_URL}" >/dev/null 2>&1; then
|
||||
echo "${NPM_OPENCODE_PACKAGE}@${version} is already published; continuing."
|
||||
exit 0
|
||||
fi
|
||||
cd plugins/opencode
|
||||
npm ci
|
||||
npm run build
|
||||
@@ -874,12 +889,6 @@ jobs:
|
||||
fs.writeFileSync("package.json", `${JSON.stringify(pkg, null, 2)}\n`);
|
||||
EOF
|
||||
npm publish --access public
|
||||
continue-on-error: true
|
||||
|
||||
- name: npm publish notice
|
||||
if: steps.npm-sdk-publish.outcome == 'failure' || steps.npm-openclaw-publish.outcome == 'failure' || steps.npm-opencode-publish.outcome == 'failure'
|
||||
run: |
|
||||
echo "::notice::One or more npm publishes failed. Set NPM_SKIP=true in repo Variables to skip npm publishes if tokens are not configured."
|
||||
|
||||
publish-github-packages:
|
||||
needs: [detect-version, build]
|
||||
@@ -1067,7 +1076,7 @@ jobs:
|
||||
|
||||
# Appends once: a re-run finds this step's own marker and leaves the notes
|
||||
# alone. Keyed on the marker, not the link, so a changelog entry that
|
||||
# happens to mention the perks page does not suppress the footer.
|
||||
# happens to mention the contact link does not suppress the footer.
|
||||
# Release notes stay the changelog; this is one line under it.
|
||||
- name: Add Headroom for Teams footer to release notes
|
||||
env:
|
||||
@@ -1079,8 +1088,8 @@ jobs:
|
||||
if ! grep -qF "$MARKER" release-notes.md; then
|
||||
{
|
||||
printf '\n%s\n\n---\n\n' "$MARKER"
|
||||
printf '**Headroom for Teams:** 3 months of Headroom Enterprise free with a 12-month plan. '
|
||||
printf '[Claim the perk →](https://headroom-perks.vercel.app/?source=github&utm_source=github&utm_medium=release-notes&utm_content=%s)\n' "$TAG"
|
||||
printf '**Want more savings?** Headroom Enterprise saves more for teams and enterprises. Talk to us at '
|
||||
printf '[hello@headroomlabs.ai](mailto:hello@headroomlabs.ai) or [headroomlabs.ai](https://headroomlabs.ai).\n'
|
||||
} >> release-notes.md
|
||||
gh release edit "$TAG" --notes-file release-notes.md
|
||||
fi
|
||||
|
||||
@@ -51,9 +51,105 @@ jobs:
|
||||
wc -l requirements-prod.txt
|
||||
|
||||
- name: Audit dependencies (pip-audit)
|
||||
uses: pypa/gh-action-pip-audit@v1.1.0
|
||||
# The export is uv.lock's fully pinned set, overrides applied: audit it
|
||||
# as is. pip must not re-resolve it (fastembed's pillow<13 cap would
|
||||
# fail; see [tool.uv] override-dependencies), and the pip-audit action
|
||||
# has no --disable-pip input, so pip-audit runs directly.
|
||||
run: uvx pip-audit==2.10.1 -r requirements-prod.txt --no-deps --disable-pip
|
||||
|
||||
# ---- SCA: what `pip install headroom-ai[all]` gets ---------------------
|
||||
# The job above audits uv.lock, which the release image also installs
|
||||
# (overrides applied). pip ignores [tool.uv] and resolves the package
|
||||
# metadata, where fastembed caps pillow <13: audit that set too. Its Pillow
|
||||
# advisories fixed in 13 are accepted only because headroom/image/
|
||||
# decoder_guard.py never decodes an image on Pillow <13, which the guard step
|
||||
# proves on that same Pillow first. Any other finding fails the job.
|
||||
# `uv pip compile` stands in for pip's resolver on Linux/Python 3.12, so it
|
||||
# approximates, not reproduces, every user's install; on Python 3.10 pip
|
||||
# also gets Pillow 12 (guarded) and filelock <4.2.1 (no fixed release there).
|
||||
# It resolves live from PyPI, so a new upstream advisory would fail PRs that
|
||||
# did not cause it: on pull requests it runs only when pyproject.toml changes;
|
||||
# pushes to main and the weekly schedule always run it.
|
||||
published-install-audit:
|
||||
name: Dependency audit (pip install from package metadata)
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
inputs: requirements-prod.txt
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run on this event?
|
||||
id: gate
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" != "pull_request" ] || \
|
||||
git diff --name-only "${{ github.event.pull_request.base.sha }}" HEAD | grep -qx pyproject.toml; then
|
||||
echo "run=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "pyproject.toml unchanged in this PR; main and the weekly run cover it."
|
||||
fi
|
||||
|
||||
- name: Set up Python
|
||||
if: steps.gate.outputs.run == 'true'
|
||||
uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install uv
|
||||
if: steps.gate.outputs.run == 'true'
|
||||
uses: astral-sh/setup-uv@v10.3.0
|
||||
|
||||
- name: Resolve what pip installs from the package metadata
|
||||
if: steps.gate.outputs.run == 'true'
|
||||
run: |
|
||||
uv --no-config pip compile pyproject.toml --extra all --python-version 3.12 \
|
||||
--no-header --no-annotate -o published.txt
|
||||
uv --no-config pip compile pyproject.toml --python-version 3.12 \
|
||||
--no-header --no-annotate -o core.txt
|
||||
grep -iE '^(pillow|fastembed)==' published.txt
|
||||
|
||||
- name: The decoder guard holds on that Pillow
|
||||
if: steps.gate.outputs.run == 'true'
|
||||
run: |
|
||||
uv venv -p 3.12 .published
|
||||
uv --no-config pip install -p .published -r core.txt \
|
||||
"$(grep -i '^pillow==' published.txt)" pytest pytest-asyncio
|
||||
.published/bin/python -m pytest -p no:cacheprovider tests/test_image_decoder_guard.py
|
||||
PINNED="$(grep -i '^pillow==' published.txt | cut -d= -f3)" .published/bin/python - <<'PY'
|
||||
import os
|
||||
|
||||
import PIL
|
||||
from headroom.image.decoder_guard import FIXED_PILLOW_MAJOR, pillow_is_safe
|
||||
|
||||
# The guard reads the Pillow that is imported; it must be pip's pick.
|
||||
assert PIL.__version__ == os.environ["PINNED"], (PIL.__version__, os.environ["PINNED"])
|
||||
fixed = int(PIL.__version__.split(".")[0]) >= FIXED_PILLOW_MAJOR
|
||||
assert pillow_is_safe() is fixed, (PIL.__version__, pillow_is_safe())
|
||||
print("Pillow", PIL.__version__, "decodes images:", fixed)
|
||||
PY
|
||||
|
||||
- name: Audit it (pip-audit)
|
||||
if: steps.gate.outputs.run == 'true'
|
||||
run: |
|
||||
uvx pip-audit==2.10.1 -r published.txt --no-deps --disable-pip \
|
||||
--format json -o audit.json || true
|
||||
python - <<'PY'
|
||||
import json
|
||||
|
||||
deps = json.load(open("audit.json"))["dependencies"]
|
||||
findings = [(d["name"], d["version"], v) for d in deps for v in d.get("vulns", [])]
|
||||
guarded = [
|
||||
f for f in findings
|
||||
# The guard turns off all decoding below Pillow 13, whatever the fix.
|
||||
if f[0].lower() == "pillow" and int(f[1].split(".")[0]) < 13
|
||||
]
|
||||
for name, ver, v in findings:
|
||||
note = " (guarded: decoder_guard)" if (name, ver, v) in guarded else ""
|
||||
print(f"{name} {ver} {v['id']} fix {v['fix_versions']}{note}")
|
||||
assert len(deps) > 50, "pip-audit produced no dependency list"
|
||||
if len(findings) > len(guarded):
|
||||
raise SystemExit("Unguarded advisories in the pip-installed set; see above.")
|
||||
PY
|
||||
|
||||
# ---- SCA: Rust dependency advisories -----------------------------------
|
||||
# `cargo audit` reads Cargo.lock only (no build, about a minute), so it runs
|
||||
@@ -104,9 +200,58 @@ jobs:
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: ">=24.16.0 <25"
|
||||
# A directory may hold npm-audit-exceptions.json for advisories in copies
|
||||
# bundled inside a package, which overrides cannot replace. A listed
|
||||
# advisory is accepted only at its listed path, only while the lock has
|
||||
# that exact version there as a bundled copy, and only until `expires`.
|
||||
# Any other finding fails, and so does an entry that no longer matches.
|
||||
- name: Audit locked dependencies at every severity
|
||||
working-directory: ${{ matrix.directory }}
|
||||
run: npm audit --package-lock-only --audit-level=low
|
||||
run: |
|
||||
if [ ! -f npm-audit-exceptions.json ]; then
|
||||
npm audit --package-lock-only --audit-level=low
|
||||
exit
|
||||
fi
|
||||
npm audit --package-lock-only --audit-level=low || true
|
||||
npm audit --package-lock-only --json > "$RUNNER_TEMP/audit.json" || true
|
||||
python3 - "$RUNNER_TEMP/audit.json" <<'PY'
|
||||
import datetime
|
||||
import json
|
||||
import sys
|
||||
|
||||
exceptions = json.load(open("npm-audit-exceptions.json"))
|
||||
if datetime.date.today().isoformat() > exceptions["expires"]:
|
||||
sys.exit(f"npm-audit-exceptions.json expired on {exceptions['expires']}: recheck upstream.")
|
||||
allowed = exceptions["advisories"] # {advisory: {lock path: bundled version}}
|
||||
locked = json.load(open("package-lock.json"))["packages"]
|
||||
vulns = json.load(open(sys.argv[1])).get("vulnerabilities", {})
|
||||
seen, unexpected = set(), []
|
||||
for name, vuln in vulns.items():
|
||||
for via in vuln["via"]:
|
||||
if isinstance(via, str):
|
||||
# Inherited: its advisories are checked on that package's
|
||||
# own entry, which therefore has to be in the report.
|
||||
if via not in vulns:
|
||||
unexpected.append(f"{name} via {via} (no entry for {via})")
|
||||
continue
|
||||
advisory = via["url"].rsplit("/", 1)[-1]
|
||||
for node in vuln["nodes"]:
|
||||
entry = locked.get(node, {})
|
||||
pinned = allowed.get(advisory, {}).get(node)
|
||||
if pinned and entry.get("version") == pinned and entry.get("inBundle"):
|
||||
seen.add((advisory, node))
|
||||
else:
|
||||
found = f"{entry.get('version')}{' bundled' if entry.get('inBundle') else ''}"
|
||||
unexpected.append(f"{advisory} {node} {found} ({via['severity']})")
|
||||
stale = [f"{a} {n}" for a, nodes in allowed.items() for n in nodes if (a, n) not in seen]
|
||||
for line in unexpected:
|
||||
print("NOT EXCEPTED:", line)
|
||||
for line in stale:
|
||||
print("STALE EXCEPTION (fixed? remove it):", line)
|
||||
if unexpected or stale:
|
||||
sys.exit(1)
|
||||
print(f"Only excepted bundled advisories remain ({len(seen)}), until {exceptions['expires']}.")
|
||||
PY
|
||||
|
||||
# ---- SAST: CodeQL static analysis ------------------------------------
|
||||
codeql:
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "0.41.0"
|
||||
".": "0.42.0"
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"version": "0.41.0",
|
||||
"version": "0.42.0",
|
||||
"packages": {
|
||||
"pypi": "0.41.0",
|
||||
"npm-sdk": "0.41.0",
|
||||
"npm-openclaw": "0.41.0",
|
||||
"npm-opencode": "0.41.0",
|
||||
"agent-hooks-plugin": "0.41.0"
|
||||
"pypi": "0.42.0",
|
||||
"npm-sdk": "0.42.0",
|
||||
"npm-openclaw": "0.42.0",
|
||||
"npm-opencode": "0.42.0",
|
||||
"agent-hooks-plugin": "0.42.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +284,104 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **code:** fix two `CodeAwareCompressor` AST-reassembly bugs: an exported JS/TS function or class (`export function foo() {`) produced a duplicated `export export` keyword and invalid syntax, because line-based node slicing (used to preserve indentation) pulled in the preceding `export` sibling's text on top of the `export_statement` handler's own prefix reconstruction. Separately, in every supported language, a doc comment immediately above a top-level function, class, or type was detached from its declaration during extraction and re-emitted in a cluster at the end of the compressed output instead of staying attached to what it documents.
|
||||
- * **proxy:** Buffered upstream responses containing a `server_tool_use` (or any other unrecognized Anthropic content block) no longer turn a fully-generated response into an HTTP 502. `StreamingMixin._response_to_sse` raised `ValueError` on unknown block types after the entire upstream generation had already been buffered, so a slow-but-successful response failed and the client retried the whole multi-minute request. Unknown blocks are now emitted verbatim in `content_block_start` (following the existing redacted_thinking` pattern), so `server_tool_use`, `server_tool_result`, `mcp_tool_use`, and future block types round-trip ([#1806](https://github.com/headroomlabs-ai/headroom/issues/1806)).
|
||||
|
||||
## [0.42.0](https://github.com/headroomlabs-ai/headroom/compare/v0.41.0...v0.42.0) (2026-10-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **pipeline:** put per-request saved tokens on OutcomeSnapshot ([#4231](https://github.com/headroomlabs-ai/headroom/issues/4231)) ([8cedf7b](https://github.com/headroomlabs-ai/headroom/commit/8cedf7be4decfb3a0da42e4e955b6a3301a66dc9))
|
||||
* **proxy:** let turn hooks rewrite OpenAI Responses requests on HTTP and WebSocket ([#4232](https://github.com/headroomlabs-ai/headroom/issues/4232)) ([fbf7bc3](https://github.com/headroomlabs-ai/headroom/commit/fbf7bc3278c11975299b9bd0a2ecf200dfd25a05))
|
||||
* **proxy:** report the same tool savings on gateway /v1/compress as the proxy path ([#4467](https://github.com/headroomlabs-ai/headroom/issues/4467)) ([a904210](https://github.com/headroomlabs-ai/headroom/commit/a90421083a781990b877d34fdaba0bc1b6cf6c4d))
|
||||
* **savings:** add the per-request counterfactual savings record ([#4236](https://github.com/headroomlabs-ai/headroom/issues/4236)) ([2912b7b](https://github.com/headroomlabs-ai/headroom/commit/2912b7b620d7abd39828db73e4f326b9a041d309))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **batch:** preserve live contexts during capacity cleanup ([#4210](https://github.com/headroomlabs-ai/headroom/issues/4210)) ([2cbdd22](https://github.com/headroomlabs-ai/headroom/commit/2cbdd22a65789676d9ebbd9e2b6a908e7f8fad95))
|
||||
* **batch:** preserve native Gemini continuation tools ([#4211](https://github.com/headroomlabs-ai/headroom/issues/4211)) ([8757458](https://github.com/headroomlabs-ai/headroom/commit/875745889ff065208d3a32aa583881468ae7c41d))
|
||||
* **cache:** bound the router's compression cache, keep the rest in SQLite ([#4357](https://github.com/headroomlabs-ai/headroom/issues/4357)) ([b196424](https://github.com/headroomlabs-ai/headroom/commit/b196424e35df0afc0c8576aea1950ed16b00e027))
|
||||
* **cache:** keep indented lines intact in OpenAI whitespace normalization ([#4343](https://github.com/headroomlabs-ai/headroom/issues/4343)) ([2480100](https://github.com/headroomlabs-ai/headroom/commit/248010091578e1f05ebcf65c8146bb57f9fb4e00))
|
||||
* **cache:** keep prefix-tracker state across a graceful proxy restart ([#4299](https://github.com/headroomlabs-ai/headroom/issues/4299)) ([62b3bed](https://github.com/headroomlabs-ai/headroom/commit/62b3bedaba988de87e38b1a58c11d28baaba7dbf))
|
||||
* **ccr:** recognize client-owned MCP retrieval aliases ([#4165](https://github.com/headroomlabs-ai/headroom/issues/4165)) ([89545fb](https://github.com/headroomlabs-ai/headroom/commit/89545fbdf3873f75461f71a03c89b1f9c64d650d))
|
||||
* **ccr:** stream the buffered CCR upstream request so idle-killing networks cannot cut it ([#4206](https://github.com/headroomlabs-ai/headroom/issues/4206)) ([ca6ba34](https://github.com/headroomlabs-ai/headroom/commit/ca6ba3486c09badecb1bfe99ddabf562c9f01c77))
|
||||
* **ci:** pin checkout in release notification smoke workflow ([#4399](https://github.com/headroomlabs-ai/headroom/issues/4399)) ([70273db](https://github.com/headroomlabs-ai/headroom/commit/70273db0af392e8f971d42e21484656676255d0b))
|
||||
* **copilot:** detect COPILOT_API_URL in cli-main.js for Copilot CLI >= 1.0.93 ([#4450](https://github.com/headroomlabs-ai/headroom/issues/4450)) ([043fe09](https://github.com/headroomlabs-ai/headroom/commit/043fe09d8c620201045619bcbcd88e26e2c6e71f))
|
||||
* **copilot:** preserve native inline OAuth identity ([#4144](https://github.com/headroomlabs-ai/headroom/issues/4144)) ([ad62166](https://github.com/headroomlabs-ai/headroom/commit/ad62166ba3056e5b98fc5bfee19f0c9b6c316e8d))
|
||||
* **deps:** bump rustls to 0.23.46 for RUSTSEC-2026-0346..0349 ([#4222](https://github.com/headroomlabs-ai/headroom/issues/4222)) ([132dbc7](https://github.com/headroomlabs-ai/headroom/commit/132dbc76995cdbecc25b4f647dbf919351cd5f7f))
|
||||
* **deps:** patch OpenClaw Undici and narrow E2E audit exceptions ([#4453](https://github.com/headroomlabs-ai/headroom/issues/4453)) ([1be699f](https://github.com/headroomlabs-ai/headroom/commit/1be699f68ee884c5c319cee9841ca304e448873c))
|
||||
* **deps:** require hf-xet>=1.6.0 so a Hub download can't crash Python at exit ([#4192](https://github.com/headroomlabs-ai/headroom/issues/4192)) ([9e5dac7](https://github.com/headroomlabs-ai/headroom/commit/9e5dac7c74979abd8d1b9ad9615443b76e42b530))
|
||||
* **deps:** require mcp>=1.30.0 for CVE-2026-59951 ([#4239](https://github.com/headroomlabs-ai/headroom/issues/4239)) ([2f7a83a](https://github.com/headroomlabs-ai/headroom/commit/2f7a83a91d3ca33a79b5c41b8095f6454b5bfb43))
|
||||
* **gateway:** keep input_includes_cache when re-drive usage is merged ([#4423](https://github.com/headroomlabs-ai/headroom/issues/4423)) ([3f94144](https://github.com/headroomlabs-ai/headroom/commit/3f941446bfbeb0b66cf6eb4a1ddf254e17d0c2a4))
|
||||
* **gemini:** keep snake_case inline_data and function parts when compressing ([#4290](https://github.com/headroomlabs-ai/headroom/issues/4290)) ([4bf1bf5](https://github.com/headroomlabs-ai/headroom/commit/4bf1bf55d175ad047c32cc3049aeff51126424c8))
|
||||
* **image:** clear last_result before each compress() call ([#4341](https://github.com/headroomlabs-ai/headroom/issues/4341)) ([19c91a8](https://github.com/headroomlabs-ai/headroom/commit/19c91a870fac09f824001197e72c8929698ea0b8))
|
||||
* **image:** flatten transparent images onto white before re-encoding as JPEG ([#4296](https://github.com/headroomlabs-ai/headroom/issues/4296)) ([9f5cfcf](https://github.com/headroomlabs-ai/headroom/commit/9f5cfcfd2bb90097f79144ff3821fc7db9fe36d5))
|
||||
* **install:** keep the HuggingFace cache on a writable mount in Docker presets ([#4207](https://github.com/headroomlabs-ai/headroom/issues/4207)) ([#4209](https://github.com/headroomlabs-ai/headroom/issues/4209)) ([7b6cb77](https://github.com/headroomlabs-ai/headroom/commit/7b6cb7790552ac10f0135013337ea4a09a9e951e))
|
||||
* **kompress:** skip the local model download when a remote endpoint is set ([#4234](https://github.com/headroomlabs-ai/headroom/issues/4234)) ([ff36931](https://github.com/headroomlabs-ai/headroom/commit/ff3693165344410eaf2882209648e504f9d3eaf0))
|
||||
* **kompress:** time each model-load stage and stop false not-ready warnings during warm-up ([#4195](https://github.com/headroomlabs-ai/headroom/issues/4195)) ([89b229c](https://github.com/headroomlabs-ai/headroom/commit/89b229ce5feaeb8710f4e226a47697426231ca55))
|
||||
* **learn:** anchor the managed block on its last start marker, append when no end marker ([#4342](https://github.com/headroomlabs-ai/headroom/issues/4342)) ([45dacc1](https://github.com/headroomlabs-ai/headroom/commit/45dacc1f94a4343c76a6e257143d22d67dc713f0))
|
||||
* **learn:** keep the digest's loop section inside its budget ([#4269](https://github.com/headroomlabs-ai/headroom/issues/4269)) ([506ba16](https://github.com/headroomlabs-ai/headroom/commit/506ba16c4a7f231b177d28066bcda389133a5e91))
|
||||
* **logs:** count omitted levels from dropped lines ([#4141](https://github.com/headroomlabs-ai/headroom/issues/4141)) ([023dd1b](https://github.com/headroomlabs-ai/headroom/commit/023dd1bc5402dcebf52a5ed3cf6a2a2878a524d9))
|
||||
* **mcp:** accept the JSONC opencode config that wrap and install already accept ([#4297](https://github.com/headroomlabs-ai/headroom/issues/4297)) ([9202948](https://github.com/headroomlabs-ai/headroom/commit/9202948c1e57a4ab8daa7c00c400605844c19f4f))
|
||||
* **memory:** bound retrieval queries before embedding ([#4244](https://github.com/headroomlabs-ai/headroom/issues/4244)) ([8c07cf4](https://github.com/headroomlabs-ai/headroom/commit/8c07cf4a0fff1b67da1b542dc746b0b4a0e952e6))
|
||||
* **memory:** ignore incidental cwd prose ([#4166](https://github.com/headroomlabs-ai/headroom/issues/4166)) ([3765439](https://github.com/headroomlabs-ai/headroom/commit/37654390b60ccb7658bb96a2f177b8666c7b7273))
|
||||
* **memory:** log storage and SQLite failures that currently make retrieval miss silently ([#4111](https://github.com/headroomlabs-ai/headroom/issues/4111)) ([4e6e955](https://github.com/headroomlabs-ai/headroom/commit/4e6e955cad0bff318e30bd4f24e934a23f57e9c6))
|
||||
* **memory:** resolve partial IDs beyond the first 1000 records ([#4389](https://github.com/headroomlabs-ai/headroom/issues/4389)) ([c4ea31b](https://github.com/headroomlabs-ai/headroom/commit/c4ea31b156478adde015833074ad7278230b4512))
|
||||
* **memory:** treat a cwd with no UTF-8 form as unresolved instead of raising ([#4167](https://github.com/headroomlabs-ai/headroom/issues/4167)) ([760c05e](https://github.com/headroomlabs-ai/headroom/commit/760c05e1b0ff8c34443f5d6eba0c4ff36f171eb2))
|
||||
* **openai:** read Responses cache_write_tokens instead of inferring writes ([#4237](https://github.com/headroomlabs-ai/headroom/issues/4237)) ([4630602](https://github.com/headroomlabs-ai/headroom/commit/46306024e74b3a44aca17fb70c1416f96b2a0b53))
|
||||
* **openai:** recompress cached Responses units whose CCR entries expired ([#4146](https://github.com/headroomlabs-ai/headroom/issues/4146)) ([8f7b419](https://github.com/headroomlabs-ai/headroom/commit/8f7b41998076727d08e5db4ee57c8bd579988c30))
|
||||
* **opencode:** do not rewrite an OpenCode config that fails to parse ([#4424](https://github.com/headroomlabs-ai/headroom/issues/4424)) ([0fe0a59](https://github.com/headroomlabs-ai/headroom/commit/0fe0a597c1929bcb4a7372e6689fd62410bad9d2))
|
||||
* **opencode:** restore process env keys on transport dispose ([#4430](https://github.com/headroomlabs-ai/headroom/issues/4430)) ([d17bac8](https://github.com/headroomlabs-ai/headroom/commit/d17bac8d64dd74ade81638ac7170715851c9704b))
|
||||
* **pricing:** suppress litellm's Provider List banner that corrupts perf JSON ([#4197](https://github.com/headroomlabs-ai/headroom/issues/4197)) ([e01ad35](https://github.com/headroomlabs-ai/headroom/commit/e01ad350dc71d44f1a4e07df5ea4e45fa39a4773))
|
||||
* **proxy:** accept HEADROOM_MEMORY_INJECTION_MODE=tool ([#4395](https://github.com/headroomlabs-ai/headroom/issues/4395)) ([f89c928](https://github.com/headroomlabs-ai/headroom/commit/f89c9282a8216b8e168c29d85c6f13c5ce7d6301))
|
||||
* **proxy:** bound per-model state keyed by the client model string ([#4407](https://github.com/headroomlabs-ai/headroom/issues/4407)) ([33e5f67](https://github.com/headroomlabs-ai/headroom/commit/33e5f67464286961f37d09298d31c5022d275a32))
|
||||
* **proxy:** copy cached tool compaction results (hardening) ([#4410](https://github.com/headroomlabs-ai/headroom/issues/4410)) ([a256231](https://github.com/headroomlabs-ai/headroom/commit/a25623109d5075276af057e79c3ed3e309906563))
|
||||
* **proxy:** count output tokens from CRLF-framed SSE streams too ([#4298](https://github.com/headroomlabs-ai/headroom/issues/4298)) ([755293d](https://github.com/headroomlabs-ai/headroom/commit/755293dd68d495b6fcec15fd47d324c3ce5eeefa))
|
||||
* **proxy:** do not rebuild a failed turn-hook re-drive as HTTP 200 ([#4398](https://github.com/headroomlabs-ai/headroom/issues/4398)) ([f59c8ff](https://github.com/headroomlabs-ai/headroom/commit/f59c8ffcd80f19564cf041d1fa4eb6247f2e1d01))
|
||||
* **proxy:** drop web_search_call history from a Responses request with no web_search tool ([#4202](https://github.com/headroomlabs-ai/headroom/issues/4202)) ([2a70d12](https://github.com/headroomlabs-ai/headroom/commit/2a70d128195575cbc52129a5287a9a3ccc097744))
|
||||
* **proxy:** honor bypass header and license gate in Anthropic batch create ([#4411](https://github.com/headroomlabs-ai/headroom/issues/4411)) ([4fd9cdd](https://github.com/headroomlabs-ai/headroom/commit/4fd9cddfd2e9cbbe38ab0b9d3acc6bc6f934a6e2))
|
||||
* **proxy:** import Response at runtime in the Bedrock handler ([#4397](https://github.com/headroomlabs-ai/headroom/issues/4397)) ([51e4ae3](https://github.com/headroomlabs-ai/headroom/commit/51e4ae36a5751fc494c0b583d37e62213e5a08a9))
|
||||
* **proxy:** judge NAT64 upstream addresses by their embedded IPv4 ([#4179](https://github.com/headroomlabs-ai/headroom/issues/4179)) ([486afaa](https://github.com/headroomlabs-ai/headroom/commit/486afaac7426fa1d6735fe2ce6ae37630d9d11ae))
|
||||
* **proxy:** keep in-period costs in the budget ledger when the entry cap is reached ([#4448](https://github.com/headroomlabs-ai/headroom/issues/4448)) ([41c15b3](https://github.com/headroomlabs-ai/headroom/commit/41c15b311cd5ab34d5108569eef4249a60973f96))
|
||||
* **proxy:** keep negative compression savings across restart ([#4406](https://github.com/headroomlabs-ai/headroom/issues/4406)) ([bebe24c](https://github.com/headroomlabs-ai/headroom/commit/bebe24c5ff0e815ac87937d9ecb1633a5091ab64))
|
||||
* **proxy:** keep tool deferral for GitHub Copilot upstream ([#4356](https://github.com/headroomlabs-ai/headroom/issues/4356)) ([217b658](https://github.com/headroomlabs-ai/headroom/commit/217b658845389e32a02760d75886de20d60e2ba3))
|
||||
* **proxy:** let HEADROOM_LOG_LEVEL=debug turn on Headroom's own debug logs ([#4137](https://github.com/headroomlabs-ai/headroom/issues/4137)) ([00093ce](https://github.com/headroomlabs-ai/headroom/commit/00093ceddcf42c3936a96ea5f280af2d0e1b2e47))
|
||||
* **proxy:** make handler failures debuggable from the logs ([#4127](https://github.com/headroomlabs-ai/headroom/issues/4127)) ([7dc20b6](https://github.com/headroomlabs-ai/headroom/commit/7dc20b6fe027cf262c5e2d0415f0dbb2032ac73b))
|
||||
* **proxy:** net tools a turn hook adds against the saving it books ([#4057](https://github.com/headroomlabs-ai/headroom/issues/4057)) ([85520c2](https://github.com/headroomlabs-ai/headroom/commit/85520c2941ed6b2c4cd4bfd9f747b24227a256aa))
|
||||
* **proxy:** record a stream the client closes after its terminal event as completed ([#4286](https://github.com/headroomlabs-ai/headroom/issues/4286)) ([762a337](https://github.com/headroomlabs-ai/headroom/commit/762a337bbeba268ae1e172c7a7de1e374231e32c))
|
||||
* **proxy:** record outcome when a passthrough stream ends mid-character ([#4429](https://github.com/headroomlabs-ai/headroom/issues/4429)) ([75cfbba](https://github.com/headroomlabs-ai/headroom/commit/75cfbba91d9bb2ff55df3949eddd4452dd9fb661))
|
||||
* **proxy:** report disabled Kompress at startup ([#4217](https://github.com/headroomlabs-ai/headroom/issues/4217)) ([430ea4f](https://github.com/headroomlabs-ai/headroom/commit/430ea4f4ebaeb0b217e237084963b64775bef24a))
|
||||
* **proxy:** report read maturation as inert in cache mode ([#4198](https://github.com/headroomlabs-ai/headroom/issues/4198)) ([ba82453](https://github.com/headroomlabs-ai/headroom/commit/ba824539d6f80c3e056f299789c1cf079a4693fe))
|
||||
* **proxy:** show turn-hook savings in /stats extension_savings, incl. Codex WS ([#4233](https://github.com/headroomlabs-ai/headroom/issues/4233)) ([1d112cd](https://github.com/headroomlabs-ai/headroom/commit/1d112cd36c9aee765ec3b550773de0c93c6d79be))
|
||||
* **proxy:** snapshot the original messages when a turn hook can edit them ([#4241](https://github.com/headroomlabs-ai/headroom/issues/4241)) ([df11f27](https://github.com/headroomlabs-ai/headroom/commit/df11f2749862a0090db11f7fca3e7dc42a75b612))
|
||||
* **relevance:** load the default embedder from one pinned snapshot ([#4152](https://github.com/headroomlabs-ai/headroom/issues/4152)) ([f380692](https://github.com/headroomlabs-ai/headroom/commit/f380692b463637e90de84f1b5cc29c7ae9f7b969))
|
||||
* **savings:** key a Responses conversation on its thread, not the shared session ([#4440](https://github.com/headroomlabs-ai/headroom/issues/4440)) ([11f743d](https://github.com/headroomlabs-ai/headroom/commit/11f743dd90e9f60cf01805a23514bd06440dd2d2))
|
||||
* **sdk:** preserve Vercel AI SDK file and image parts through compression ([#4048](https://github.com/headroomlabs-ai/headroom/issues/4048)) ([1668a6c](https://github.com/headroomlabs-ai/headroom/commit/1668a6c0dd73cd8a1b9d7fc5eae297149e8f7d93))
|
||||
* **security:** restrict the Windows runtime log via NTFS ACL, not just warn ([#4135](https://github.com/headroomlabs-ai/headroom/issues/4135)) ([125a703](https://github.com/headroomlabs-ai/headroom/commit/125a703a65c574e9db809f95eefdc70407e0250e))
|
||||
* **smart-crusher:** match audit-safe protected_patterns against unescaped text ([#4294](https://github.com/headroomlabs-ai/headroom/issues/4294)) ([e11afdb](https://github.com/headroomlabs-ai/headroom/commit/e11afdbdf8a729e50553681143d0f925b71fcd83))
|
||||
* **storage:** normalize timezone-aware JSONL time filters ([#4063](https://github.com/headroomlabs-ai/headroom/issues/4063)) ([bf34ccf](https://github.com/headroomlabs-ai/headroom/commit/bf34ccf58861a687e814abf1a158885987add9ae))
|
||||
* **tabular:** pass tables with repeated header names through verbatim ([#4278](https://github.com/headroomlabs-ai/headroom/issues/4278)) ([ed3195b](https://github.com/headroomlabs-ai/headroom/commit/ed3195beef1dcfbb0219c2da9b59984167c81c01))
|
||||
* **telemetry:** give empty-item compressions a stable tool signature ([#4396](https://github.com/headroomlabs-ai/headroom/issues/4396)) ([a79def4](https://github.com/headroomlabs-ai/headroom/commit/a79def4dd1b7217a75ce6c4eebd0b06ea3a70c1d))
|
||||
* **telemetry:** let HEADROOM_TELEMETRY=off stop the anonymous beacon ([#4235](https://github.com/headroomlabs-ai/headroom/issues/4235)) ([1a40b3c](https://github.com/headroomlabs-ai/headroom/commit/1a40b3ce67ad9e155ba768e8d05cec4c872c7f99))
|
||||
* **transforms:** keep the fences of a code block passed through for a protected tag ([#4292](https://github.com/headroomlabs-ai/headroom/issues/4292)) ([02958c6](https://github.com/headroomlabs-ai/headroom/commit/02958c6ffe41a1d3466c21558670875df87384ae))
|
||||
* **transforms:** log the compression failures that silently become "no savings" ([#4092](https://github.com/headroomlabs-ai/headroom/issues/4092)) ([580cc83](https://github.com/headroomlabs-ai/headroom/commit/580cc83a9a412123040978447a2c9b77c08670b0))
|
||||
* **zcode:** skip providers that point at the Headroom proxy itself ([#4413](https://github.com/headroomlabs-ai/headroom/issues/4413)) ([9ac1b52](https://github.com/headroomlabs-ai/headroom/commit/9ac1b52c2762bbc40d3e459e5f87cd4bbfbde8aa))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* Bump base64 from 0.22.1 to 0.23.1 ([#4029](https://github.com/headroomlabs-ai/headroom/issues/4029)) ([8d468d4](https://github.com/headroomlabs-ai/headroom/commit/8d468d455c2e3c195cc2975bbc13e63d6b85ef59))
|
||||
* Bump ruff from 0.16.8 to 0.17.0 in the pip-minor-patch group across 1 directory ([#4026](https://github.com/headroomlabs-ai/headroom/issues/4026)) ([de3f639](https://github.com/headroomlabs-ai/headroom/commit/de3f639803f1f172f65c05c165bfab92c0bec9e8))
|
||||
* Bump the cargo-minor-patch group across 1 directory with 12 updates ([#4186](https://github.com/headroomlabs-ai/headroom/issues/4186)) ([683c9a6](https://github.com/headroomlabs-ai/headroom/commit/683c9a6120c309e84e4848378dbe3891d064f82e))
|
||||
* Bump the npm-minor-patch group across 2 directories with 16 updates ([#4218](https://github.com/headroomlabs-ai/headroom/issues/4218)) ([07c8bbf](https://github.com/headroomlabs-ai/headroom/commit/07c8bbf1edcc143a7fe97b9e29214355cc371a19))
|
||||
* Bump the npm-minor-patch group across 3 directories with 12 updates ([#4219](https://github.com/headroomlabs-ai/headroom/issues/4219)) ([1f71cb3](https://github.com/headroomlabs-ai/headroom/commit/1f71cb3d64e1586c97331a3482aae84558741102))
|
||||
* Update huggingface-hub requirement from <2.0,>=1.5.0 to >=1.5.0,<3.0 ([#4027](https://github.com/headroomlabs-ai/headroom/issues/4027)) ([fcf3db8](https://github.com/headroomlabs-ai/headroom/commit/fcf3db8e70d15aef0d80a561cf5d0e45e918a338))
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* **integrations:** share the local/cloud compress backend of asgi and litellm_callback ([#4124](https://github.com/headroomlabs-ai/headroom/issues/4124)) ([58caafb](https://github.com/headroomlabs-ai/headroom/commit/58caafb59b40c00b35ceee6237ef2289df71f25d))
|
||||
* **transforms:** share one CCR persist helper for the Rust-backed compressors ([#4094](https://github.com/headroomlabs-ai/headroom/issues/4094)) ([ea947ca](https://github.com/headroomlabs-ai/headroom/commit/ea947ca421ee6d6b8f15a9ed522c3a3bea5a3225))
|
||||
|
||||
## [0.41.0](https://github.com/headroomlabs-ai/headroom/compare/v0.40.0...v0.41.0) (2026-10-13)
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ Enable or disable automatic Copilot review in **Settings → Rules → Rulesets
|
||||
- [Ruff](https://github.com/astral-sh/ruff) for lint + format, line length 100, PEP 8.
|
||||
- Type hints on public functions; Google-style docstrings.
|
||||
- Cover new behavior + edge cases; aim >80% coverage on new code.
|
||||
- Python 3.10+. Optional features go behind extras.
|
||||
- Python 3.11+. Optional features go behind extras.
|
||||
- **Headroom writes LF and normalizes on read, on every platform.** Pass
|
||||
`newline="\n"` to every `write_text`/`open` that writes a context, memory,
|
||||
or state file, and normalize `\r\n`/`\r` when you read one back. Without
|
||||
|
||||
Generated
+10
-20
@@ -1351,9 +1351,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ctutils"
|
||||
version = "0.4.2"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e"
|
||||
checksum = "38d28fb6aa7dd680b3ffd1a3e64e115c177bdba63c0ae7f9cd48129ff05c4fa0"
|
||||
dependencies = [
|
||||
"cmov",
|
||||
]
|
||||
@@ -2098,7 +2098,7 @@ dependencies = [
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
"uuid",
|
||||
"webpki-roots 1.0.9",
|
||||
"webpki-roots",
|
||||
"wiremock",
|
||||
]
|
||||
|
||||
@@ -2298,7 +2298,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
"webpki-roots 1.0.9",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3835,7 +3835,7 @@ dependencies = [
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-streams",
|
||||
"web-sys",
|
||||
"webpki-roots 1.0.9",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3960,9 +3960,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.103.15"
|
||||
version = "0.103.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
|
||||
checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"ring",
|
||||
@@ -4642,7 +4642,6 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tungstenite 0.30.0",
|
||||
"webpki-roots 0.26.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5084,7 +5083,7 @@ dependencies = [
|
||||
"socks",
|
||||
"ureq-proto",
|
||||
"utf8-zero",
|
||||
"webpki-roots 1.0.9",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5314,18 +5313,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.26.11"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
|
||||
dependencies = [
|
||||
"webpki-roots 1.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
|
||||
checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
+8
-2
@@ -50,12 +50,18 @@ COPY headroom/ headroom/
|
||||
# The standalone Dockerfile must support every backend advertised by
|
||||
# `headroom proxy --backend`, including Bedrock temporary/SSO credentials.
|
||||
# Those credentials require botocore (GH #1551), supplied by [bedrock].
|
||||
ARG HEADROOM_EXTRAS=proxy,code,bedrock
|
||||
# [redis] backs the replica-shared stores: without it HEADROOM_COMPRESS_SESSION_STORE
|
||||
# stops startup and HEADROOM_CCR_BACKEND=redis falls back to a per-process store.
|
||||
ARG HEADROOM_EXTRAS=proxy,code,bedrock,redis
|
||||
# `uv pip install` ignores [tool.uv] override-dependencies (uv.lock only), so
|
||||
# pass them explicitly: the image gets the security overrides the lock has
|
||||
# (pillow 13 over fastembed's <13 cap).
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||
--mount=type=cache,target=/usr/local/cargo/git \
|
||||
--mount=type=cache,target=/build/target \
|
||||
uv pip install --system ".[${HEADROOM_EXTRAS}]"
|
||||
python -c "exec('try: import tomllib\\nexcept ImportError: from pip._vendor import tomli as tomllib'); print('\\n'.join(tomllib.load(open('pyproject.toml', 'rb'))['tool']['uv']['override-dependencies']))" > /tmp/overrides.txt && \
|
||||
uv pip install --system --overrides /tmp/overrides.txt ".[${HEADROOM_EXTRAS}]"
|
||||
|
||||
RUN --mount=type=bind,source=.,target=/context,readonly \
|
||||
HEADROOM_BUILD_VERSION="${HEADROOM_BUILD_VERSION}" PYTHON_SITE_PACKAGES="${PYTHON_SITE_PACKAGES}" python - <<'PY'
|
||||
|
||||
@@ -39,7 +39,7 @@ answers, fraction of the tokens. Compression runs on your machine; no prompt or
|
||||
file content is sent anywhere to be compressed.
|
||||
|
||||
<p align="center">
|
||||
<a href="https://headroom-perks.vercel.app/?source=github&utm_source=github&utm_medium=readme&utm_content=banner"><img src=".github/assets/enterprise-perk.svg" alt="Headroom Enterprise for teams: 3 months free with a 12-month plan. Claim the perk." width="880"></a>
|
||||
<a href="https://headroomlabs.ai"><img src=".github/assets/enterprise-perk.svg" alt="Headroom Enterprise for teams. Talk to us: hello@headroomlabs.ai." width="880"></a>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
@@ -183,13 +183,10 @@ back at you, and deep reasoning spent on routine steps like reading a file.
|
||||
Headroom trims it from the proxy, with no change to your code:
|
||||
|
||||
- **Verbosity steering** appends a short "be terse, don't restate context" note to the *end* of the system prompt, so your prompt cache still hits.
|
||||
- **Effort routing** dials thinking effort down when a turn is only the model resuming after a tool result — a file read, a passing test. New questions and errors keep full effort.
|
||||
|
||||
Both apply to Anthropic `/v1/messages` and to OpenAI-compatible
|
||||
`/v1/chat/completions` and `/v1/responses`. Effort routing uses
|
||||
`reasoning_effort` on OpenAI and `thinking.budget_tokens` / `output_config.effort`
|
||||
on Anthropic, with the same clamp-only invariant and the same `output_shaper:*`
|
||||
labels on both paths.
|
||||
It applies to Anthropic `/v1/messages` and to OpenAI-compatible
|
||||
`/v1/chat/completions` and `/v1/responses`, with the same `output_shaper:*`
|
||||
labels on all paths.
|
||||
|
||||
```bash
|
||||
export HEADROOM_OUTPUT_SHAPER=1 # off by default
|
||||
@@ -446,7 +443,7 @@ Granular extras: `[proxy]`, `[mcp]`, `[ml]` (Kompress-v2-base), `[code]`,
|
||||
`[memory]`, `[vector]` (optional HNSW backend — needs a C++ toolchain, not in
|
||||
`[all]`), `[relevance]`, `[image]`, `[agno]`, `[langchain]`, `[evals]`,
|
||||
`[pytorch-mps]` (Apple-GPU memory-embedder offload — set
|
||||
`HEADROOM_EMBEDDER_RUNTIME=pytorch_mps`). Requires **Python 3.10+**.
|
||||
`HEADROOM_EMBEDDER_RUNTIME=pytorch_mps`). Requires **Python 3.11+**.
|
||||
|
||||
> `[all]` covers the core stack but not the framework adapters. Install those
|
||||
> separately: `pip install "headroom-ai[langchain]"`, and likewise `[agno]`,
|
||||
@@ -630,23 +627,18 @@ Turn it off with `HEADROOM_BEACON=off`, `HEADROOM_TELEMETRY=off`, the
|
||||
|
||||
## Headroom for teams
|
||||
|
||||
Headroom OSS is built for one developer on one laptop. Headroom Enterprise is built
|
||||
for the whole team.
|
||||
**Not seeing the savings you want?** Headroom OSS is a framework. It was built to show
|
||||
what's possible on one developer's laptop, so it saves less than it could. We are
|
||||
building bigger savings for teams and enterprises in Headroom Enterprise, which adds:
|
||||
|
||||
| | Open source | Enterprise |
|
||||
|---|---|---|
|
||||
| Savings | Compression, plus tool search on Anthropic requests (on by default) | Also: tool search for every model, harness tuning, extra compressors |
|
||||
| Model routing | Rule-based and opt-in: turn it on with `HEADROOM_MODEL_ROUTER_ENABLED=1` and write the rules in `HEADROOM_MODEL_ROUTES` | Automatic: a cheaper model per request when quality allows, with a shadow mode that shows the savings before you turn it on |
|
||||
| Security | — | Detect and strip prompt injection and risky tool calls |
|
||||
| Rollout | Per laptop | Managed or in your VPC, SSO, central config, org-wide savings |
|
||||
| Support | GitHub, Discord | Dedicated engineers, onboarding, priority response |
|
||||
- More cost savings
|
||||
- Tokens secured
|
||||
- On premise deployment
|
||||
- Deep attribution
|
||||
- And many more features
|
||||
|
||||
**3 months of Enterprise free.** Companies that sign a 12-month Enterprise plan get
|
||||
their first 3 months free. One perk per company.
|
||||
|
||||
**[Claim 3 months free →](https://headroom-perks.vercel.app/?source=github&utm_source=github&utm_medium=readme&utm_content=teams)**
|
||||
· or email [hello@headroomlabs.ai](mailto:hello@headroomlabs.ai) with your stack and
|
||||
monthly LLM spend.
|
||||
If you're a team or an enterprise, **talk to us**:
|
||||
[hello@headroomlabs.ai](mailto:hello@headroomlabs.ai) · [headroomlabs.ai](https://headroomlabs.ai)
|
||||
|
||||
Everything in this repo stays open source under Apache 2.0.
|
||||
|
||||
|
||||
+25
-2
@@ -74,9 +74,9 @@ it necessarily handles both your traffic and your credentials. The
|
||||
full — what is written to disk, with what permissions and retention, what leaves the
|
||||
host, and what the local admin surface does and does not allow. The summary:
|
||||
|
||||
- **Provider API keys are forwarded, not persisted.** Keys supplied via environment
|
||||
- **Interactive provider API keys are forwarded.** Keys supplied via environment
|
||||
variables or request headers are used to authenticate the upstream call and are not
|
||||
written to disk or emitted to logs. The one exception is deliberate: the
|
||||
written to disk or emitted to logs. Settings can also persist keys: the
|
||||
`ANTHROPIC_TARGET_API_HEADERS` / `OPENAI_TARGET_API_HEADERS` header maps, if you set
|
||||
them through the dashboard settings GUI, are persisted to `~/.headroom/settings.json`
|
||||
in plaintext — and a header map is where a gateway key typically goes.
|
||||
@@ -84,6 +84,29 @@ host, and what the local admin surface does and does not allow. The summary:
|
||||
GitHub Copilot OAuth refresh token to `~/.headroom/copilot_auth.json` (relocatable via
|
||||
`$HEADROOM_COPILOT_AUTH_FILE`). It is plaintext JSON, written with `0600` permissions
|
||||
on a best-effort basis.
|
||||
- **Persistent installs store supplied environment values.** Every value passed
|
||||
to `headroom install --env KEY=VALUE` is stored verbatim and in cleartext. Supervisors (launchd, systemd, Task
|
||||
Scheduler, cron) start the proxy from a bare environment, so `--env` is the
|
||||
only channel by which a provider API key reaches a supervised proxy — and
|
||||
if you pass one, it is written to
|
||||
`~/.headroom/deploy/<profile>/manifest.json` (mode `0600`) and `export`ed in
|
||||
cleartext by the generated runner scripts `run-headroom.sh` /
|
||||
`ensure-headroom.sh` (mode `0700`) in the same directory (mode `0700`).
|
||||
The installer sets those modes and then reads them back: where the
|
||||
platform enforces POSIX permission bits it refuses to leave behind a runner
|
||||
script it could not restrict, and warns if the profile directory could not
|
||||
be narrowed. On Windows the bits are advisory — access is governed by ACLs —
|
||||
so the modes above are requested but not enforced there, and protection
|
||||
comes from the account's own profile directory instead. Where they do hold,
|
||||
the files are owner-only, not encrypted: anything that can read the account
|
||||
— the user themself, root, a home-directory backup or sync — can read the
|
||||
key, and rotating it requires re-running `headroom install apply`.
|
||||
With the Docker runtime the same values are additionally passed as `docker
|
||||
run --env NAME=VALUE`, which places them in the container process's command
|
||||
line and so in `ps` output for other users on the host. Prefer a
|
||||
supervisor-native secret facility (systemd `LoadCredential=` /
|
||||
`EnvironmentFile=` on an owner-only file, a macOS keychain helper) over
|
||||
`--env` for long-lived provider keys.
|
||||
- **Cached request content is written to disk.** CCR stores pre-compression originals —
|
||||
tool outputs, file contents, retrieved chunks — in a local SQLite database
|
||||
(`~/.headroom/ccr_store.db`, `0600`) so they can be retrieved after compression. Entries
|
||||
|
||||
@@ -30,10 +30,23 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[cfg(feature = "ml")]
|
||||
use fastembed::{EmbeddingModel, InitOptions, TextEmbedding};
|
||||
use fastembed::{EmbeddingModel, InitOptions, QuantizationMode, TextEmbedding};
|
||||
|
||||
use super::base::{RelevanceScore, RelevanceScorer};
|
||||
|
||||
/// Texts per ONNX Runtime run, matching Python's `EMBED_BATCH_SIZE`: fastembed's
|
||||
/// default of 256 grows ORT's never-shrinking CPU arena to the biggest batch scored.
|
||||
#[cfg(feature = "ml")]
|
||||
const EMBED_BATCH_SIZE: usize = 16;
|
||||
|
||||
/// fastembed refuses to split a dynamic-quantized model's input across runs (each
|
||||
/// run calibrates its own int8 range, so the embeddings would not compare): one batch.
|
||||
#[cfg(feature = "ml")]
|
||||
fn embed_batch_size(model_kind: &EmbeddingModel) -> Option<usize> {
|
||||
(TextEmbedding::get_quantization_mode(model_kind) != QuantizationMode::Dynamic)
|
||||
.then_some(EMBED_BATCH_SIZE)
|
||||
}
|
||||
|
||||
/// fastembed-backed semantic relevance scorer.
|
||||
///
|
||||
/// Construct via `EmbeddingScorer::try_new()` to handle the model-load
|
||||
@@ -56,6 +69,8 @@ pub struct EmbeddingScorer {
|
||||
/// dominant cost so contention is bounded by inference latency,
|
||||
/// not lock latency.
|
||||
model: Option<Mutex<TextEmbedding>>,
|
||||
/// `embed` batch size for this model, from `embed_batch_size`.
|
||||
batch_size: Option<usize>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "ml")]
|
||||
@@ -75,6 +90,7 @@ impl Default for EmbeddingScorer {
|
||||
EmbeddingScorer {
|
||||
model_name: "BAAI/bge-small-en-v1.5".to_string(),
|
||||
model: None,
|
||||
batch_size: Some(EMBED_BATCH_SIZE),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,11 +145,13 @@ impl EmbeddingScorer {
|
||||
// `dynamic_ort_loader_ready`).
|
||||
crate::transforms::magika_detector::dynamic_ort_loader_ready()
|
||||
.map_err(|e| format!("EmbeddingScorer: ONNX Runtime unavailable: {e}"))?;
|
||||
let batch_size = embed_batch_size(&model_kind);
|
||||
let model = TextEmbedding::try_new(InitOptions::new(model_kind))
|
||||
.map_err(|e| format!("EmbeddingScorer model load failed: {}", e))?;
|
||||
Ok(EmbeddingScorer {
|
||||
model_name: name,
|
||||
model: Some(Mutex::new(model)),
|
||||
batch_size,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -192,11 +210,11 @@ impl RelevanceScorer for EmbeddingScorer {
|
||||
}
|
||||
};
|
||||
|
||||
// Encode items + context in one batch — saves model dispatch
|
||||
// overhead. Mirrors Python fastembed batch encoding.
|
||||
// Encode items + context in one `embed` call, which runs them in
|
||||
// `self.batch_size` chunks. Mirrors Python fastembed batch encoding.
|
||||
let mut all_texts: Vec<String> = items.iter().map(|s| s.to_string()).collect();
|
||||
all_texts.push(context.to_string());
|
||||
let embeddings = match guard.embed(all_texts, None) {
|
||||
let embeddings = match guard.embed(all_texts, self.batch_size) {
|
||||
Ok(e) => e,
|
||||
Err(e) => {
|
||||
return items
|
||||
@@ -352,6 +370,7 @@ mod tests {
|
||||
EmbeddingScorer {
|
||||
model_name: "test".to_string(),
|
||||
model: None,
|
||||
batch_size: Some(EMBED_BATCH_SIZE),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +481,15 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ml")]
|
||||
#[test]
|
||||
fn dynamic_quantized_models_embed_in_one_batch() {
|
||||
let capped = Some(EMBED_BATCH_SIZE);
|
||||
assert_eq!(embed_batch_size(&EmbeddingModel::BGESmallENV15), capped);
|
||||
assert_eq!(embed_batch_size(&EmbeddingModel::BGESmallENV15Q), capped);
|
||||
assert_eq!(embed_batch_size(&EmbeddingModel::AllMiniLML6V2Q), None);
|
||||
}
|
||||
|
||||
// ---------- model-backed tests (gated on RUN_FASTEMBED_TESTS) ----------
|
||||
|
||||
#[cfg(feature = "ml")]
|
||||
@@ -506,4 +534,71 @@ mod tests {
|
||||
assert!((0.0..=1.0).contains(&sc.score));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ml")]
|
||||
#[test]
|
||||
fn fastembed_batches_past_the_cap_keep_each_score_with_its_item() {
|
||||
if !fastembed_enabled() {
|
||||
return;
|
||||
}
|
||||
// Three EMBED_BATCH_SIZE batches of mixed lengths, the one related item
|
||||
// in the last: a misaligned batch boundary would hand its score away.
|
||||
let s = EmbeddingScorer::try_new().expect("model loads");
|
||||
let mut items: Vec<String> = (0..40)
|
||||
.map(|i| {
|
||||
format!(
|
||||
"inventory row {i}: {}",
|
||||
"pallets of garden furniture ".repeat(i % 5 + 1)
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
items[37] = "authentication failed for user admin: invalid password".to_string();
|
||||
let refs: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let batch = s.score_batch(&refs, "login error");
|
||||
assert_eq!(batch.len(), 40);
|
||||
let top = (0..40)
|
||||
.max_by(|&a, &b| batch[a].score.total_cmp(&batch[b].score))
|
||||
.unwrap();
|
||||
assert_eq!(top, 37);
|
||||
for (item, sc) in refs.iter().zip(&batch) {
|
||||
let single = s.score(item, "login error").score;
|
||||
assert!(
|
||||
(sc.score - single).abs() < 1e-3,
|
||||
"{item}: batched {} vs single {single}",
|
||||
sc.score
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ml")]
|
||||
#[test]
|
||||
fn fastembed_dynamic_quantized_model_scores_on_both_sides_of_the_cap() {
|
||||
if !fastembed_enabled() {
|
||||
return;
|
||||
}
|
||||
// 15 items plus the context fill exactly one EMBED_BATCH_SIZE run; 16
|
||||
// and 40 go past it, where fastembed refuses to split this model.
|
||||
let s = EmbeddingScorer::try_new_with_model(EmbeddingModel::AllMiniLML6V2Q)
|
||||
.expect("model loads");
|
||||
for n in [15, 16, 40] {
|
||||
let mut items: Vec<String> = (0..n)
|
||||
.map(|i| format!("inventory row {i}: pallets of garden furniture"))
|
||||
.collect();
|
||||
items[n - 3] = "authentication failed for user admin: invalid password".to_string();
|
||||
let refs: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let batch = s.score_batch(&refs, "login error");
|
||||
assert_eq!(batch.len(), n);
|
||||
for sc in &batch {
|
||||
assert!(
|
||||
!sc.reason.contains("inference failed"),
|
||||
"{n} items: {}",
|
||||
sc.reason
|
||||
);
|
||||
}
|
||||
let top = (0..n)
|
||||
.max_by(|&a, &b| batch[a].score.total_cmp(&batch[b].score))
|
||||
.unwrap();
|
||||
assert_eq!(top, n - 3, "{n} items");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1532,35 +1532,50 @@ impl LogCompressor {
|
||||
|
||||
let omitted = all_lines.len().saturating_sub(selected.len());
|
||||
if omitted > 0 {
|
||||
// Keep public stats as input totals; describe only dropped identities here.
|
||||
let mut omitted_levels = [0u64; 4];
|
||||
for line in all_lines {
|
||||
if selected_numbers.contains(&line.line_number) {
|
||||
continue;
|
||||
}
|
||||
match line.level {
|
||||
LogLevel::Error => omitted_levels[0] += 1,
|
||||
LogLevel::Fail => omitted_levels[1] += 1,
|
||||
LogLevel::Warn => omitted_levels[2] += 1,
|
||||
LogLevel::Info => omitted_levels[3] += 1,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut summary_parts: Vec<String> = Vec::new();
|
||||
for (label, key) in [
|
||||
("ERROR", "errors"),
|
||||
("FAIL", "fails"),
|
||||
("WARN", "warnings"),
|
||||
("INFO", "info"),
|
||||
for (label, n) in [
|
||||
("ERROR", omitted_levels[0]),
|
||||
("FAIL", omitted_levels[1]),
|
||||
("WARN", omitted_levels[2]),
|
||||
("INFO", omitted_levels[3]),
|
||||
] {
|
||||
let n = stats.get(key).copied().unwrap_or(0);
|
||||
if n > 0 {
|
||||
summary_parts.push(format!("{} {}", n, label));
|
||||
}
|
||||
}
|
||||
if !summary_parts.is_empty() {
|
||||
let omitted_names = if omitted_short_summary_ids.is_empty() {
|
||||
String::new()
|
||||
let omitted_names = if omitted_short_summary_ids.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
let shown = omitted_short_summary_ids
|
||||
.iter()
|
||||
.take(5)
|
||||
.copied()
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let overflow = omitted_short_summary_ids.len().saturating_sub(5);
|
||||
if overflow > 0 {
|
||||
format!("; omitted: {shown}, +{overflow} more")
|
||||
} else {
|
||||
let shown = omitted_short_summary_ids
|
||||
.iter()
|
||||
.take(5)
|
||||
.copied()
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let overflow = omitted_short_summary_ids.len().saturating_sub(5);
|
||||
if overflow > 0 {
|
||||
format!("; omitted: {shown}, +{overflow} more")
|
||||
} else {
|
||||
format!("; omitted: {shown}")
|
||||
}
|
||||
};
|
||||
format!("; omitted: {shown}")
|
||||
}
|
||||
};
|
||||
if summary_parts.is_empty() {
|
||||
output.push(format!("[{} lines omitted{}]", omitted, omitted_names));
|
||||
} else {
|
||||
output.push(format!(
|
||||
"[{} lines omitted: {}{}]",
|
||||
omitted,
|
||||
@@ -1963,12 +1978,6 @@ mod tests {
|
||||
|
||||
let (output, _) = c.format_output(&selected, &parsed);
|
||||
assert!(!output.contains("; omitted: "));
|
||||
if !keep_summary_lines {
|
||||
assert_eq!(
|
||||
output,
|
||||
"FAILED outside.py::test_0\nFAILED outside.py::test_9\nERROR outside.py::test_10\nERROR outside.py::test_19\n[67 lines omitted: 10 ERROR, 10 FAIL, 51 INFO]"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2366,7 +2375,79 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_output_emits_summary_with_omitted_count() {
|
||||
fn omitted_marker_counts_only_dropped_lines_on_live_path() {
|
||||
let mut lines = (0..400)
|
||||
.map(|i| format!("INFO worker processed item {i}"))
|
||||
.collect::<Vec<_>>();
|
||||
let error = "ERROR worker failed: connection reset";
|
||||
lines.insert(200, error.to_string());
|
||||
let c = LogCompressor::new(LogCompressorConfig {
|
||||
enable_ccr: false,
|
||||
..Default::default()
|
||||
});
|
||||
let (result, _) = c.compress(&lines.join("\n"), 1.0);
|
||||
let marker = result
|
||||
.compressed
|
||||
.lines()
|
||||
.find(|line| line.contains("lines omitted:"))
|
||||
.expect("large input must have omitted lines");
|
||||
let pattern = Regex::new(r"(\d+) (ERROR|FAIL|WARN|INFO)").unwrap();
|
||||
let mut level_counts = pattern.captures_iter(marker);
|
||||
let count = level_counts.next().expect("omitted INFO count");
|
||||
|
||||
assert!(result.compressed.lines().any(|line| line == error));
|
||||
assert_eq!(&count[2], "INFO");
|
||||
assert_eq!(
|
||||
count[1].parse::<usize>().unwrap(),
|
||||
result.original_line_count - result.compressed_line_count
|
||||
);
|
||||
assert!(level_counts.next().is_none());
|
||||
assert_eq!(
|
||||
marker,
|
||||
format!("[{} lines omitted: {} INFO]", &count[1], &count[1])
|
||||
);
|
||||
assert_eq!(result.stats["errors"], 1);
|
||||
assert_eq!(result.stats["info"], 400);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn omitted_non_severity_lines_keep_count_notice_on_live_path() {
|
||||
use std::fmt::Write as _;
|
||||
|
||||
let count_pattern = Regex::new(r"(?m)^\[(\d+) lines omitted[^\]]*\]$").unwrap();
|
||||
let level_pattern = Regex::new(r"\d+ (ERROR|FAIL|WARN|INFO)\b").unwrap();
|
||||
let error = "ERROR retained failure";
|
||||
for prefix in ["DEBUG ", "TRACE ", ""] {
|
||||
let mut input = String::with_capacity(4096);
|
||||
for i in 0..100 {
|
||||
writeln!(input, "{prefix}progress step {i}").unwrap();
|
||||
}
|
||||
input.push_str(error);
|
||||
let c = LogCompressor::new(LogCompressorConfig {
|
||||
enable_ccr: false,
|
||||
..Default::default()
|
||||
});
|
||||
let (result, _) = c.compress(&input, 1.0);
|
||||
let marker = count_pattern
|
||||
.captures(&result.compressed)
|
||||
.expect("dropped lines must retain an omission count");
|
||||
assert_eq!(
|
||||
marker[1].parse::<usize>().unwrap(),
|
||||
result.original_line_count - result.compressed_line_count
|
||||
);
|
||||
assert!(!level_pattern.is_match(marker.get(0).unwrap().as_str()));
|
||||
assert_eq!(
|
||||
marker.get(0).unwrap().as_str(),
|
||||
format!("[{} lines omitted]", &marker[1])
|
||||
);
|
||||
assert!(result.compressed.lines().any(|line| line == error));
|
||||
assert_eq!(result.stats["errors"], 1);
|
||||
assert_eq!(result.stats["total"], 101);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_output_preserves_input_totals() {
|
||||
let c = cmp();
|
||||
let all_lines = vec![
|
||||
LogLine::new(0, "ERROR a"),
|
||||
@@ -2388,9 +2469,9 @@ mod tests {
|
||||
.collect::<Vec<_>>();
|
||||
let selected = vec![all_lines[0].clone()];
|
||||
let (output, stats) = c.format_output(&selected, &all_lines);
|
||||
assert!(output.contains("[3 lines omitted: 1 ERROR, 1 WARN, 2 INFO]"));
|
||||
assert_eq!(stats["errors"], 1);
|
||||
assert_eq!(stats["info"], 2);
|
||||
assert_eq!(output, "ERROR a\n[3 lines omitted: 1 WARN, 2 INFO]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2415,11 +2496,9 @@ mod tests {
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
assert!(
|
||||
output.ends_with(&format!(
|
||||
"[{count} lines omitted: {count} FAIL, 1 INFO; omitted: {shown}{overflow}]"
|
||||
)),
|
||||
"{output}"
|
||||
assert_eq!(
|
||||
output.lines().last().unwrap(),
|
||||
format!("[{count} lines omitted: {count} FAIL; omitted: {shown}{overflow}]")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2442,11 +2521,9 @@ mod tests {
|
||||
];
|
||||
|
||||
let (output, stats) = cmp().format_output(&selected, &all_lines);
|
||||
assert!(
|
||||
output.ends_with(
|
||||
"[3 lines omitted: 1 ERROR, 3 FAIL, 1 INFO; omitted: tests/test_ids.py::test_error, tests/test_ids.py::test_repeat, tests/test_ids.py::test_repeat]"
|
||||
),
|
||||
"{output}"
|
||||
assert_eq!(
|
||||
output.lines().last().unwrap(),
|
||||
"[3 lines omitted: 1 ERROR, 2 FAIL; omitted: tests/test_ids.py::test_error, tests/test_ids.py::test_repeat, tests/test_ids.py::test_repeat]"
|
||||
);
|
||||
assert_eq!(stats["errors"], 1);
|
||||
assert_eq!(stats["fails"], 3);
|
||||
@@ -2482,26 +2559,12 @@ mod tests {
|
||||
);
|
||||
|
||||
let (output, _) = c.format_output(&selected, &all_lines);
|
||||
assert!(
|
||||
output.ends_with(
|
||||
"[4 lines omitted: 4 FAIL, 1 INFO; omitted: tests/test_ids.py::test_1, tests/test_ids.py::test_2]"
|
||||
),
|
||||
"{output}"
|
||||
assert_eq!(
|
||||
output.lines().last().unwrap(),
|
||||
"[4 lines omitted: 2 FAIL, 1 INFO; omitted: tests/test_ids.py::test_1, tests/test_ids.py::test_2]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_output_marker_is_unchanged_without_omitted_short_summary_entries() {
|
||||
let c = cmp();
|
||||
let mut error = LogLine::new(0, "ERROR a");
|
||||
error.level = LogLevel::Error;
|
||||
let mut info = LogLine::new(1, "INFO b");
|
||||
info.level = LogLevel::Info;
|
||||
|
||||
let (output, _) = c.format_output(&[error.clone()], &[error, info]);
|
||||
assert_eq!(output, "ERROR a\n[1 lines omitted: 1 ERROR, 1 INFO]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn score_line_caps_at_one_point_zero() {
|
||||
let line = LogLine {
|
||||
|
||||
@@ -26,7 +26,10 @@ tracing-subscriber = { version = "0.3", features = ["json", "env-filter", "fmt"]
|
||||
# roots (Zscaler, Netskope, ...) are installed in the OS store, never in
|
||||
# Mozilla's list, so webpki alone rejects every re-signed upstream certificate.
|
||||
reqwest = { version = "0.12", default-features = false, features = ["stream", "rustls-tls", "rustls-tls-native-roots", "http2"] }
|
||||
tokio-tungstenite = { version = "0.30", default-features = false, features = ["connect", "rustls-tls-webpki-roots", "rustls-tls-native-roots"] }
|
||||
# websocket.rs always supplies tls::websocket_tls_config(), which loads our
|
||||
# direct webpki-roots 1.x dependency plus native/additive roots. Do not enable
|
||||
# tungstenite's unused default webpki store: it pulls the obsolete 0.26 shim.
|
||||
tokio-tungstenite = { version = "0.30", default-features = false, features = ["connect", "rustls-tls-native-roots"] }
|
||||
clap = { workspace = true, features = ["derive", "env"] }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
@@ -122,7 +125,7 @@ tokio-rustls = { version = "0.26", default-features = false, features = ["ring",
|
||||
# is the generator rustls' own test-suite uses; dev-only, never shipped.
|
||||
rcgen = { version = "0.14", default-features = false, features = ["ring", "pem"] }
|
||||
reqwest = { version = "0.12", default-features = false, features = ["stream", "rustls-tls", "http2", "json"] }
|
||||
tokio-tungstenite = { version = "0.30", default-features = false, features = ["connect", "rustls-tls-webpki-roots"] }
|
||||
tokio-tungstenite = { version = "0.30", default-features = false, features = ["connect", "rustls-tls-native-roots"] }
|
||||
futures-util = "0.3"
|
||||
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", "net", "io-util", "time", "test-util", "process"] }
|
||||
hyper = { version = "1", features = ["server", "http1", "http2"] }
|
||||
|
||||
@@ -43753,5 +43753,763 @@
|
||||
"thinking_always_on": true,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing"
|
||||
},
|
||||
"openrouter/anthropic/claude-haiku-5.5": {
|
||||
"input_cost_per_token": 1e-07,
|
||||
"output_cost_per_token": 5e-07,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"litellm_provider": "openrouter",
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"source": "https://openrouter.ai/api/v1/models",
|
||||
"supports_function_calling": true,
|
||||
"supports_tool_choice": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_vision": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_web_search": true,
|
||||
"supports_adaptive_thinking": true,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"supports_sampling_params": false
|
||||
},
|
||||
"claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens_batches": 2.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens_batches": 1.25e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens_batches": 3.125e-07,
|
||||
"cache_read_input_token_cost_above_100k_tokens_batches": 2.5e-08,
|
||||
"supports_anthropic_compaction": true,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"cache_creation_input_token_cost_batches": 6.25e-08,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"cache_read_input_token_cost_batches": 5e-09,
|
||||
"input_cost_per_token": 1e-07,
|
||||
"input_cost_per_token_batches": 5e-08,
|
||||
"litellm_provider": "anthropic",
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5e-07,
|
||||
"output_cost_per_token_batches": 2.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_native_structured_output": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"provider_specific_entry": {
|
||||
"us": 1.1
|
||||
},
|
||||
"supports_output_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://platform.claude.com/docs/en/models/haiku-5-5/overview",
|
||||
"supports_web_search": true,
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08
|
||||
},
|
||||
"bedrock_mantle/anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.75e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.875e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5.5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.375e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.2e-07,
|
||||
"cache_read_input_token_cost": 1.1e-08,
|
||||
"input_cost_per_token": 1.1e-07,
|
||||
"litellm_provider": "bedrock_mantle",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-haiku-5-5.html"
|
||||
},
|
||||
"bedrock_mantle/us-gov-west-1/anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 6e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 3e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 7.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.2e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 6e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"cache_creation_input_token_cost": 1.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.4e-07,
|
||||
"cache_read_input_token_cost": 1.2e-08,
|
||||
"input_cost_per_token": 1.2e-07,
|
||||
"litellm_provider": "bedrock_mantle",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 6e-07,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_output_config": true,
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"source": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-haiku-5-5.html"
|
||||
},
|
||||
"anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"input_cost_per_token": 1e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"apac.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.75e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.875e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5.5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.2e-07,
|
||||
"cache_creation_input_token_cost": 1.375e-07,
|
||||
"input_cost_per_token": 1.1e-07,
|
||||
"output_cost_per_token": 5.5e-07,
|
||||
"cache_read_input_token_cost": 1.1e-08,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"au.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.75e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.875e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5.5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.375e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.2e-07,
|
||||
"cache_read_input_token_cost": 1.1e-08,
|
||||
"input_cost_per_token": 1.1e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"azure_ai/claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08,
|
||||
"supports_mid_conversation_system": true,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"deprecation_date": "2027-09-29",
|
||||
"input_cost_per_token": 1e-07,
|
||||
"litellm_provider": "azure_ai",
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide"
|
||||
},
|
||||
"bedrock/us-gov-east-1/anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 6e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 3e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 7.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.2e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 6e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"cache_creation_input_token_cost": 1.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.4e-07,
|
||||
"cache_read_input_token_cost": 1.2e-08,
|
||||
"input_cost_per_token": 1.2e-07,
|
||||
"litellm_provider": "bedrock",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 6e-07,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json",
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_output_config": true,
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true
|
||||
},
|
||||
"bedrock/us-gov-west-1/anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 6e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 3e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 7.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.2e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 6e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"cache_creation_input_token_cost": 1.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.4e-07,
|
||||
"cache_read_input_token_cost": 1.2e-08,
|
||||
"input_cost_per_token": 1.2e-07,
|
||||
"litellm_provider": "bedrock",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 6e-07,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json",
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_output_config": true,
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true
|
||||
},
|
||||
"eu.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.75e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.875e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5.5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.375e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.2e-07,
|
||||
"cache_read_input_token_cost": 1.1e-08,
|
||||
"input_cost_per_token": 1.1e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"global.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"input_cost_per_token": 1e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"jp.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.75e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.875e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5.5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.375e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.2e-07,
|
||||
"cache_read_input_token_cost": 1.1e-08,
|
||||
"input_cost_per_token": 1.1e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"perplexity/anthropic/claude-haiku-5-5": {
|
||||
"litellm_provider": "perplexity",
|
||||
"mode": "responses",
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_web_search": true,
|
||||
"supports_function_calling": true,
|
||||
"input_cost_per_token": 1e-07,
|
||||
"output_cost_per_token": 5e-07,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"source": "https://docs.perplexity.ai/docs/agent-api/models"
|
||||
},
|
||||
"us-gov.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 6e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 3e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 7.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.2e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 6e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"cache_creation_input_token_cost": 1.5e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.4e-07,
|
||||
"cache_read_input_token_cost": 1.2e-08,
|
||||
"input_cost_per_token": 1.2e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 6e-07,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json",
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_output_config": true,
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true
|
||||
},
|
||||
"us.anthropic.claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5.5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.75e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.875e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1.1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5.5e-08,
|
||||
"bedrock_converse_supports_strict_tools": false,
|
||||
"cache_creation_input_token_cost": 1.375e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2.2e-07,
|
||||
"cache_read_input_token_cost": 1.1e-08,
|
||||
"input_cost_per_token": 1.1e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
"supports_tool_search": true,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_mid_conversation_system": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_native_structured_output": false,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_output_config": true,
|
||||
"bedrock_output_config_effort_ceiling": "xhigh",
|
||||
"supports_parallel_tool_use_config": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current/index.json"
|
||||
},
|
||||
"vertex_ai/claude-haiku-5-5": {
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08,
|
||||
"regional_endpoint_uplift_multiplier": 1.1,
|
||||
"supports_mid_conversation_system": true,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"cache_creation_input_token_cost_batches": 6.25e-08,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"cache_read_input_token_cost_batches": 5e-09,
|
||||
"input_cost_per_token": 1e-07,
|
||||
"input_cost_per_token_batches": 5e-08,
|
||||
"litellm_provider": "vertex_ai-anthropic_models",
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5e-07,
|
||||
"output_cost_per_token_batches": 2.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing"
|
||||
},
|
||||
"vertex_ai/claude-haiku-5-5@default": {
|
||||
"input_cost_per_token_above_100k_tokens": 5e-07,
|
||||
"output_cost_per_token_above_100k_tokens": 2.5e-06,
|
||||
"cache_creation_input_token_cost_above_100k_tokens": 6.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr_above_100k_tokens": 1e-06,
|
||||
"cache_read_input_token_cost_above_100k_tokens": 5e-08,
|
||||
"regional_endpoint_uplift_multiplier": 1.1,
|
||||
"supports_mid_conversation_system": true,
|
||||
"cache_creation_input_token_cost": 1.25e-07,
|
||||
"cache_creation_input_token_cost_above_1hr": 2e-07,
|
||||
"cache_creation_input_token_cost_batches": 6.25e-08,
|
||||
"cache_read_input_token_cost": 1e-08,
|
||||
"cache_read_input_token_cost_batches": 5e-09,
|
||||
"input_cost_per_token": 1e-07,
|
||||
"input_cost_per_token_batches": 5e-08,
|
||||
"litellm_provider": "vertex_ai-anthropic_models",
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"max_tokens": 128000,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 5e-07,
|
||||
"output_cost_per_token_batches": 2.5e-07,
|
||||
"search_context_cost_per_query": {
|
||||
"search_context_size_high": 0.01,
|
||||
"search_context_size_low": 0.01,
|
||||
"search_context_size_medium": 0.01
|
||||
},
|
||||
"supports_adaptive_thinking": true,
|
||||
"supports_assistant_prefill": false,
|
||||
"supports_computer_use": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_pdf_input": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_response_schema": true,
|
||||
"supports_sampling_params": false,
|
||||
"supports_tool_choice": true,
|
||||
"supports_vision": true,
|
||||
"supports_xhigh_reasoning_effort": true,
|
||||
"supports_max_reasoning_effort": true,
|
||||
"supports_forced_tool_use": true,
|
||||
"thinking_always_on": false,
|
||||
"prompt_cache_min_tokens": 512,
|
||||
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,8 +187,11 @@ mod tests {
|
||||
"claude-opus-5-5",
|
||||
"claude-opus-5",
|
||||
"claude-fable-5-1",
|
||||
"claude-haiku-5-5",
|
||||
"global.anthropic.claude-sonnet-5-5",
|
||||
"vertex_ai/claude-sonnet-5-5",
|
||||
"us.anthropic.claude-haiku-5-5",
|
||||
"vertex_ai/claude-haiku-5-5",
|
||||
] {
|
||||
assert_eq!(context_window_for(model), 1_000_000, "{model}");
|
||||
}
|
||||
|
||||
@@ -660,25 +660,44 @@ impl Ledger {
|
||||
let usd = if ev.failed {
|
||||
EventUsd::default()
|
||||
} else {
|
||||
match pricing::lookup(&ev.model) {
|
||||
Some(p) => EventUsd {
|
||||
compression: p.compression_savings_usd(ev.tokens_saved()),
|
||||
cache: p
|
||||
.cache_savings_usd(ev.usage.cache_read_tokens, ev.usage.cache_write_tokens),
|
||||
input_cost: p.input_cost_usd(
|
||||
// When the response carried no usage block,
|
||||
// bill the post-compression estimate instead
|
||||
// so passthrough lanes still show spend.
|
||||
if ev.usage.total_input() > 0 {
|
||||
ev.usage.input_tokens
|
||||
} else {
|
||||
ev.tokens_after
|
||||
},
|
||||
ev.usage.cache_read_tokens,
|
||||
ev.usage.cache_write_tokens,
|
||||
),
|
||||
output_cost: p.output_cost_usd(ev.usage.output_tokens),
|
||||
},
|
||||
match pricing::lookup_card(&ev.model) {
|
||||
Some(card) => {
|
||||
// When the response carried no usage block, bill
|
||||
// the post-compression estimate instead so
|
||||
// passthrough lanes still show spend.
|
||||
let uncached = if ev.usage.total_input() > 0 {
|
||||
ev.usage.input_tokens
|
||||
} else {
|
||||
ev.tokens_after
|
||||
};
|
||||
// The billed prompt picks the rate card: past a
|
||||
// model's long-context threshold every rate below
|
||||
// switches to the higher tier.
|
||||
let p = card.for_prompt(
|
||||
uncached
|
||||
.saturating_add(ev.usage.cache_read_tokens)
|
||||
.saturating_add(ev.usage.cache_write_tokens),
|
||||
);
|
||||
EventUsd {
|
||||
compression: card.compression_savings_usd(
|
||||
uncached,
|
||||
ev.usage.cache_read_tokens,
|
||||
ev.usage.cache_write_tokens,
|
||||
ev.usage.output_tokens,
|
||||
ev.tokens_saved(),
|
||||
),
|
||||
cache: p.cache_savings_usd(
|
||||
ev.usage.cache_read_tokens,
|
||||
ev.usage.cache_write_tokens,
|
||||
),
|
||||
input_cost: p.input_cost_usd(
|
||||
uncached,
|
||||
ev.usage.cache_read_tokens,
|
||||
ev.usage.cache_write_tokens,
|
||||
),
|
||||
output_cost: p.output_cost_usd(ev.usage.output_tokens),
|
||||
}
|
||||
}
|
||||
None => EventUsd::default(),
|
||||
}
|
||||
};
|
||||
@@ -1277,6 +1296,66 @@ mod tests {
|
||||
assert!(total > input, "total spend must exceed input-only spend");
|
||||
}
|
||||
|
||||
/// A Haiku 5.5 prompt over 100K bills every rate at the 5x card:
|
||||
/// 150K uncached in + 5K out is $0.075 + $0.0125, not the base
|
||||
/// card's $0.015 + $0.0025.
|
||||
#[test]
|
||||
fn long_prompt_bills_at_the_models_long_context_card() {
|
||||
let ledger = Ledger::in_memory();
|
||||
let mut ev = event("claude-haiku-5-5");
|
||||
ev.usage = Usage {
|
||||
input_tokens: 150_000,
|
||||
output_tokens: 5_000,
|
||||
cache_read_tokens: 0,
|
||||
cache_write_tokens: 0,
|
||||
};
|
||||
ledger.record(ev);
|
||||
let v = ledger.stats_payload(true);
|
||||
let input = v["session"]["input_cost_usd"].as_f64().unwrap();
|
||||
let output = v["session"]["output_cost_usd"].as_f64().unwrap();
|
||||
assert!((input - 0.075).abs() < 1e-9, "input: {input}");
|
||||
assert!((output - 0.0125).abs() < 1e-9, "output: {output}");
|
||||
}
|
||||
|
||||
/// Devin's example on #4037: 110K uncached compressed to 90K saves
|
||||
/// $0.055 - $0.009 = $0.046 of input, not 20K x $0.10/M = $0.002.
|
||||
#[test]
|
||||
fn compression_below_the_threshold_credits_the_avoided_long_card() {
|
||||
let ledger = Ledger::in_memory();
|
||||
let mut ev = event("claude-haiku-5-5");
|
||||
ev.tokens_before = 110_000;
|
||||
ev.tokens_after = 90_000;
|
||||
ev.usage = Usage {
|
||||
input_tokens: 90_000,
|
||||
output_tokens: 0,
|
||||
cache_read_tokens: 0,
|
||||
cache_write_tokens: 0,
|
||||
};
|
||||
ledger.record(ev);
|
||||
let v = ledger.stats_payload(true);
|
||||
let saved = v["session"]["compression_savings_usd"].as_f64().unwrap();
|
||||
assert!((saved - 0.046).abs() < 1e-9, "saved: {saved}");
|
||||
}
|
||||
|
||||
/// Cache reads count toward the threshold: 60K uncached + 60K
|
||||
/// read is a 120K prompt, so it bills at the long card too.
|
||||
#[test]
|
||||
fn cached_tokens_count_toward_the_long_context_threshold() {
|
||||
let ledger = Ledger::in_memory();
|
||||
let mut ev = event("claude-haiku-5-5");
|
||||
ev.usage = Usage {
|
||||
input_tokens: 60_000,
|
||||
output_tokens: 0,
|
||||
cache_read_tokens: 60_000,
|
||||
cache_write_tokens: 0,
|
||||
};
|
||||
ledger.record(ev);
|
||||
let v = ledger.stats_payload(true);
|
||||
let input = v["session"]["input_cost_usd"].as_f64().unwrap();
|
||||
// 60K x $0.50/M + 60K x $0.05/M.
|
||||
assert!((input - 0.033).abs() < 1e-9, "input: {input}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_token_counts_clamp_to_ceiling() {
|
||||
let ledger = Ledger::in_memory();
|
||||
|
||||
@@ -33,6 +33,17 @@
|
||||
//! while its Bedrock form is present). Those price at $0 with a WARN
|
||||
//! until the table is refreshed — see the module note below.
|
||||
//!
|
||||
//! # Long-context tiers
|
||||
//!
|
||||
//! Some models publish a second, higher rate card for long prompts
|
||||
//! (LiteLLM's `*_above_<N>k_tokens` fields: Claude Haiku 5.5 above
|
||||
//! 100K, Sonnet 4 / 4.5 above 200K, GPT-5.x above 272K). Above the
|
||||
//! threshold the provider re-prices the WHOLE request — input, output
|
||||
//! and cache alike — not just the tokens past it, so [`lookup_card`]
|
||||
//! keeps both cards and [`PriceCard::for_prompt`] picks one from the
|
||||
//! billed prompt. A tier field a row leaves out falls back to that
|
||||
//! rate's base price, the same rule the Python cost path follows.
|
||||
//!
|
||||
//! # Unknown models price at $0
|
||||
//!
|
||||
//! A miss returns `None`; the ledger then records $0 for every USD
|
||||
@@ -121,7 +132,71 @@ impl ModelPrice {
|
||||
}
|
||||
}
|
||||
|
||||
static BOOK: OnceLock<HashMap<String, ModelPrice>> = OnceLock::new();
|
||||
/// A model's rate cards: the base one, plus the long-context one for
|
||||
/// models that publish it (see the module doc).
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct PriceCard {
|
||||
pub base: ModelPrice,
|
||||
pub long_context: Option<LongContextTier>,
|
||||
}
|
||||
|
||||
/// The card a request bills at once its prompt passes `above_tokens`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct LongContextTier {
|
||||
/// Prompt size (uncached + cache read + cache write tokens) the
|
||||
/// request must exceed for this card to apply.
|
||||
pub above_tokens: u64,
|
||||
pub price: ModelPrice,
|
||||
}
|
||||
|
||||
impl PriceCard {
|
||||
/// The rates a request with `prompt_tokens` of billed prompt pays.
|
||||
pub fn for_prompt(&self, prompt_tokens: u64) -> ModelPrice {
|
||||
match self.long_context {
|
||||
Some(tier) if prompt_tokens > tier.above_tokens => tier.price,
|
||||
_ => self.base,
|
||||
}
|
||||
}
|
||||
|
||||
/// USD compression saved on one request: what it would have cost
|
||||
/// uncompressed minus what it did cost.
|
||||
///
|
||||
/// Inside one tier that is the removed tokens at that tier's input
|
||||
/// rate. When the uncompressed prompt would have passed the
|
||||
/// long-context threshold and the forwarded one does not, the
|
||||
/// provider would have re-priced the WHOLE request — every input
|
||||
/// bucket and the output — at the long card, so the saving is the
|
||||
/// difference of the two full bills, not the removed tokens at the
|
||||
/// cheap rate.
|
||||
pub fn compression_savings_usd(
|
||||
&self,
|
||||
uncached_input_tokens: u64,
|
||||
cache_read_tokens: u64,
|
||||
cache_write_tokens: u64,
|
||||
output_tokens: u64,
|
||||
tokens_saved: u64,
|
||||
) -> f64 {
|
||||
let prompt = uncached_input_tokens
|
||||
.saturating_add(cache_read_tokens)
|
||||
.saturating_add(cache_write_tokens);
|
||||
let sent = self.for_prompt(prompt);
|
||||
let unsent = self.for_prompt(prompt.saturating_add(tokens_saved));
|
||||
if unsent == sent {
|
||||
return sent.compression_savings_usd(tokens_saved);
|
||||
}
|
||||
let without = unsent.input_cost_usd(
|
||||
uncached_input_tokens.saturating_add(tokens_saved),
|
||||
cache_read_tokens,
|
||||
cache_write_tokens,
|
||||
) + unsent.output_cost_usd(output_tokens);
|
||||
let with =
|
||||
sent.input_cost_usd(uncached_input_tokens, cache_read_tokens, cache_write_tokens)
|
||||
+ sent.output_cost_usd(output_tokens);
|
||||
(without - with).max(0.0)
|
||||
}
|
||||
}
|
||||
|
||||
static BOOK: OnceLock<HashMap<String, PriceCard>> = OnceLock::new();
|
||||
|
||||
/// Bounded once-per-model warn set so an unknown model logs one WARN,
|
||||
/// not one per request. Capped so attacker-controlled model ids can't
|
||||
@@ -140,11 +215,48 @@ pub fn warm() {
|
||||
let _ = book();
|
||||
}
|
||||
|
||||
fn book() -> &'static HashMap<String, ModelPrice> {
|
||||
fn book() -> &'static HashMap<String, PriceCard> {
|
||||
BOOK.get_or_init(parse_vendored)
|
||||
}
|
||||
|
||||
fn parse_vendored() -> HashMap<String, ModelPrice> {
|
||||
/// A finite, non-negative price field, or `None`.
|
||||
fn price_field(spec: &serde_json::Map<String, serde_json::Value>, key: &str) -> Option<f64> {
|
||||
spec.get(key)
|
||||
.and_then(|v| v.as_f64())
|
||||
.filter(|c| c.is_finite() && *c >= 0.0)
|
||||
}
|
||||
|
||||
/// The row's long-context card, keyed off its
|
||||
/// `input_cost_per_token_above_<N>k_tokens` field. Every row in the
|
||||
/// vendored table publishes at most one such threshold.
|
||||
fn parse_long_context_tier(
|
||||
spec: &serde_json::Map<String, serde_json::Value>,
|
||||
base: &ModelPrice,
|
||||
) -> Option<LongContextTier> {
|
||||
let (thousands, input) = spec.keys().find_map(|key| {
|
||||
let n = key
|
||||
.strip_prefix("input_cost_per_token_above_")?
|
||||
.strip_suffix("k_tokens")?;
|
||||
if n.is_empty() || !n.bytes().all(|b| b.is_ascii_digit()) {
|
||||
return None;
|
||||
}
|
||||
Some((n.parse::<u64>().ok()?, price_field(spec, key)?))
|
||||
})?;
|
||||
let tiered = |field: &str, fallback: f64| {
|
||||
price_field(spec, &format!("{field}_above_{thousands}k_tokens")).unwrap_or(fallback)
|
||||
};
|
||||
Some(LongContextTier {
|
||||
above_tokens: thousands.saturating_mul(1000),
|
||||
price: ModelPrice {
|
||||
input,
|
||||
output: tiered("output_cost_per_token", base.output),
|
||||
cache_read: tiered("cache_read_input_token_cost", base.cache_read),
|
||||
cache_write: tiered("cache_creation_input_token_cost", base.cache_write),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_vendored() -> HashMap<String, PriceCard> {
|
||||
let raw: serde_json::Value = serde_json::from_str(VENDORED_JSON)
|
||||
.expect("vendored LiteLLM JSON must parse — same invariant as model_limits");
|
||||
let mut out = HashMap::new();
|
||||
@@ -166,23 +278,17 @@ fn parse_vendored() -> HashMap<String, ModelPrice> {
|
||||
if !input.is_finite() || !output.is_finite() || input < 0.0 || output < 0.0 {
|
||||
continue;
|
||||
}
|
||||
let cache_read = spec
|
||||
.get("cache_read_input_token_cost")
|
||||
.and_then(|v| v.as_f64())
|
||||
.filter(|c| c.is_finite() && *c >= 0.0)
|
||||
.unwrap_or(input);
|
||||
let cache_write = spec
|
||||
.get("cache_creation_input_token_cost")
|
||||
.and_then(|v| v.as_f64())
|
||||
.filter(|c| c.is_finite() && *c >= 0.0)
|
||||
.unwrap_or(input);
|
||||
let base = ModelPrice {
|
||||
input,
|
||||
output,
|
||||
cache_read: price_field(spec, "cache_read_input_token_cost").unwrap_or(input),
|
||||
cache_write: price_field(spec, "cache_creation_input_token_cost").unwrap_or(input),
|
||||
};
|
||||
out.insert(
|
||||
model_id.to_ascii_lowercase(),
|
||||
ModelPrice {
|
||||
input,
|
||||
output,
|
||||
cache_read,
|
||||
cache_write,
|
||||
PriceCard {
|
||||
long_context: parse_long_context_tier(spec, &base),
|
||||
base,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -236,20 +342,26 @@ fn push_revision_trimmed(push: &mut impl FnMut(String), id: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Look up per-token pricing for a model id. `None` means "not in
|
||||
/// the vendored table" — the caller records $0 for USD fields and
|
||||
/// this module logs one WARN per distinct model id.
|
||||
pub fn lookup(model: &str) -> Option<ModelPrice> {
|
||||
/// Look up a model's rate cards. `None` means "not in the vendored
|
||||
/// table" — the caller records $0 for USD fields and this module logs
|
||||
/// one WARN per distinct model id.
|
||||
pub fn lookup_card(model: &str) -> Option<PriceCard> {
|
||||
let table = book();
|
||||
for key in candidates(model) {
|
||||
if let Some(p) = table.get(&key) {
|
||||
return Some(*p);
|
||||
if let Some(card) = table.get(&key) {
|
||||
return Some(*card);
|
||||
}
|
||||
}
|
||||
warn_once(model);
|
||||
None
|
||||
}
|
||||
|
||||
/// Look up a model's base per-token pricing — the card a prompt below
|
||||
/// any long-context threshold pays. See [`lookup_card`].
|
||||
pub fn lookup(model: &str) -> Option<ModelPrice> {
|
||||
lookup_card(model).map(|card| card.base)
|
||||
}
|
||||
|
||||
fn warn_once(model: &str) {
|
||||
let set = WARNED.get_or_init(|| RwLock::new(std::collections::HashSet::new()));
|
||||
{
|
||||
@@ -288,6 +400,98 @@ mod tests {
|
||||
assert!(p.cache_write > p.input, "cache writes carry a premium");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn claude_haiku_5_5_base_rate_card() {
|
||||
let p = lookup("claude-haiku-5-5").expect("priced");
|
||||
assert!((p.input - 1e-7).abs() < 1e-15, "input $0.10/MTok");
|
||||
assert!((p.output - 5e-7).abs() < 1e-15, "output $0.50/MTok");
|
||||
assert!((p.cache_read - 1e-8).abs() < 1e-15, "cache read $0.01/MTok");
|
||||
assert!(
|
||||
(p.cache_write - 1.25e-7).abs() < 1e-15,
|
||||
"5m cache write $0.125/MTok"
|
||||
);
|
||||
}
|
||||
|
||||
/// Haiku 5.5 re-prices the whole request at 5x once the prompt
|
||||
/// passes 100K; at exactly 100K it still pays the base card.
|
||||
#[test]
|
||||
fn claude_haiku_5_5_long_prompt_card_above_100k() {
|
||||
let card = lookup_card("claude-haiku-5-5").expect("priced");
|
||||
let tier = card.long_context.expect("Haiku 5.5 publishes a 100K tier");
|
||||
assert_eq!(tier.above_tokens, 100_000);
|
||||
assert_eq!(card.for_prompt(100_000), card.base);
|
||||
let long = card.for_prompt(100_001);
|
||||
assert!((long.input - 5e-7).abs() < 1e-15, "input $0.50/MTok");
|
||||
assert!((long.output - 2.5e-6).abs() < 1e-15, "output $2.50/MTok");
|
||||
assert!(
|
||||
(long.cache_read - 5e-8).abs() < 1e-15,
|
||||
"cache read $0.05/MTok"
|
||||
);
|
||||
assert!(
|
||||
(long.cache_write - 6.25e-7).abs() < 1e-15,
|
||||
"5m cache write $0.625/MTok"
|
||||
);
|
||||
}
|
||||
|
||||
/// The threshold comes from each row's own field name, not a
|
||||
/// shared constant: Sonnet 4.5's card switches at 200K.
|
||||
#[test]
|
||||
fn long_context_threshold_is_read_per_model() {
|
||||
let card = lookup_card("claude-sonnet-4-5").expect("priced");
|
||||
let tier = card.long_context.expect("Sonnet 4.5 publishes a 200K tier");
|
||||
assert_eq!(tier.above_tokens, 200_000);
|
||||
assert_eq!(card.for_prompt(150_000), card.base);
|
||||
assert!((card.for_prompt(200_001).input - 6e-6).abs() < 1e-15);
|
||||
}
|
||||
|
||||
/// Compression that keeps a prompt under the threshold saves the
|
||||
/// long card on the whole request, not just the removed tokens at
|
||||
/// the base rate: 110K -> 90K uncached on Haiku 5.5, 1K output, is
|
||||
/// (110K x $0.50 + 1K x $2.50) - (90K x $0.10 + 1K x $0.50) per MTok.
|
||||
#[test]
|
||||
fn compression_across_the_threshold_saves_the_whole_premium() {
|
||||
let card = lookup_card("claude-haiku-5-5").expect("priced");
|
||||
let usd = card.compression_savings_usd(90_000, 0, 0, 1_000, 20_000);
|
||||
assert!((usd - (0.0575 - 0.0095)).abs() < 1e-9, "usd: {usd}");
|
||||
// Inside one tier it stays removed tokens at that tier's rate.
|
||||
let below = card.compression_savings_usd(50_000, 0, 0, 1_000, 20_000);
|
||||
assert!((below - 20_000.0 * 1e-7).abs() < 1e-12, "below: {below}");
|
||||
let above = card.compression_savings_usd(120_000, 0, 0, 1_000, 20_000);
|
||||
assert!((above - 20_000.0 * 5e-7).abs() < 1e-12, "above: {above}");
|
||||
}
|
||||
|
||||
/// A model without a published tier bills the base card at any size.
|
||||
#[test]
|
||||
fn flat_rated_model_has_no_long_context_tier() {
|
||||
let card = lookup_card("claude-opus-4-6").expect("priced");
|
||||
assert!(card.long_context.is_none());
|
||||
assert_eq!(card.for_prompt(900_000), card.base);
|
||||
}
|
||||
|
||||
/// A tier that omits a rate falls back to that rate's base price.
|
||||
#[test]
|
||||
fn missing_tier_field_falls_back_to_base_rate() {
|
||||
let spec: serde_json::Map<String, serde_json::Value> = serde_json::from_str(
|
||||
r#"{"input_cost_per_token_above_128k_tokens": 2e-6,
|
||||
"output_cost_per_token_above_128k_tokens_priority": 9e-6}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let base = ModelPrice {
|
||||
input: 1e-6,
|
||||
output: 4e-6,
|
||||
cache_read: 1e-7,
|
||||
cache_write: 1e-6,
|
||||
};
|
||||
let tier = parse_long_context_tier(&spec, &base).expect("tier parsed");
|
||||
assert_eq!(tier.above_tokens, 128_000);
|
||||
assert_eq!(tier.price.input, 2e-6);
|
||||
assert_eq!(
|
||||
tier.price.output, base.output,
|
||||
"a _priority variant is not the tier"
|
||||
);
|
||||
assert_eq!(tier.price.cache_read, base.cache_read);
|
||||
}
|
||||
|
||||
/// Bedrock cross-region pricing is region-specific, so an exact
|
||||
/// regional entry must win over the geo-stripped base id.
|
||||
#[test]
|
||||
|
||||
+9
-9
@@ -10,7 +10,7 @@ target "runtime-default" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,bedrock,redis"
|
||||
RUNTIME_USER = "nonroot"
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ target "runtime" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,bedrock,redis"
|
||||
RUNTIME_USER = "root"
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ target "runtime-nonroot" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,bedrock,redis"
|
||||
RUNTIME_USER = "nonroot"
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ target "runtime-code" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock,redis"
|
||||
RUNTIME_USER = "root"
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ target "runtime-code-nonroot" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock,redis"
|
||||
RUNTIME_USER = "nonroot"
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ target "runtime-slim" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime-slim"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,bedrock,redis"
|
||||
RUNTIME_USER = "root"
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ target "runtime-slim-nonroot" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime-slim"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,bedrock,redis"
|
||||
RUNTIME_USER = "nonroot"
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ target "runtime-code-slim" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime-slim"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock,redis"
|
||||
RUNTIME_USER = "root"
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ target "runtime-code-slim-nonroot" {
|
||||
inherits = ["_common", "docker-metadata-action"]
|
||||
target = "runtime-slim"
|
||||
args = {
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock"
|
||||
HEADROOM_EXTRAS = "proxy,code,bedrock,redis"
|
||||
RUNTIME_USER = "nonroot"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@ services:
|
||||
tty: true
|
||||
environment:
|
||||
HOME: /tmp/headroom-home
|
||||
# Docker creates /tmp/headroom-home as root:root, so $HOME is not
|
||||
# writable by the --user the container runs as (issue #4207). Keep the
|
||||
# HuggingFace/XDG caches on the bind-mounted workspace instead.
|
||||
HF_HOME: /tmp/headroom-home/.headroom/cache/huggingface
|
||||
XDG_CACHE_HOME: /tmp/headroom-home/.headroom/cache
|
||||
# Canonical Headroom filesystem contract (issue #175). Forwarded into
|
||||
# the container so the proxy resolves state/config to the bind-mounted
|
||||
# /tmp/headroom-home/.headroom path. HEADROOM_WORKSPACE (above) remains
|
||||
@@ -28,6 +33,9 @@ services:
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
HOME: /tmp/headroom-home
|
||||
# See the `cli` service above (issue #4207).
|
||||
HF_HOME: /tmp/headroom-home/.headroom/cache/huggingface
|
||||
XDG_CACHE_HOME: /tmp/headroom-home/.headroom/cache
|
||||
HEADROOM_HOST: 0.0.0.0
|
||||
HEADROOM_PROXY_TOKEN: ${HEADROOM_PROXY_TOKEN:-}
|
||||
# The container binds 0.0.0.0 so the loopback publication below can reach
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# ADR 0001: Main and release branch semantics
|
||||
|
||||
- Status: Accepted
|
||||
- Date: 2026-08-13
|
||||
|
||||
## Context
|
||||
|
||||
Headroom currently develops and releases from `main`. The target lifecycle needs
|
||||
`main` to continue moving while an exact source revision is qualified. A branch
|
||||
name alone is not evidence, and creating a `release` branch before qualification
|
||||
is authoritative would make unqualified code appear publishable.
|
||||
|
||||
## Decision
|
||||
|
||||
`main` remains the default integration branch and the target for ordinary pull
|
||||
requests. The future protected `release` branch represents qualified source. It
|
||||
may receive only an ancestry-preserving promotion of an exact Gate-A-qualified
|
||||
`main` SHA, a verified metadata-only Release Please change, an authorized hotfix,
|
||||
or release-control maintenance.
|
||||
|
||||
Promotion must leave the qualified candidate SHA reachable from `release`.
|
||||
Squash and rebase merges are therefore forbidden for promotion pull requests.
|
||||
Normal pull requests into `main` may retain the repository's usual merge policy.
|
||||
|
||||
The first `release` branch must be created from an exact SHA with a passing,
|
||||
unrevoked qualification manifest. Branch creation, protection, lifecycle
|
||||
activation, and publication credentials remain explicit administrator actions.
|
||||
They are not performed by this contract-only change.
|
||||
|
||||
Gate A admits source to `release`. Gate B independently authorizes publication
|
||||
of final distribution bytes. Neither branch membership nor a tag or GitHub
|
||||
Release substitutes for either gate.
|
||||
|
||||
## Consequences
|
||||
|
||||
Release Please will eventually watch `release`, but only after the qualification
|
||||
controller and migration guard are operational. Promotion automation must use an
|
||||
ancestry-preserving merge. A hotfix made on `release` requires qualification and
|
||||
forward synchronization to `main`; `release` must not become a second development
|
||||
branch.
|
||||
@@ -0,0 +1,35 @@
|
||||
# ADR 0002: Release artifact identity and provenance
|
||||
|
||||
- Status: Accepted
|
||||
- Date: 2026-08-13
|
||||
|
||||
## Context
|
||||
|
||||
Rebuilding a moving source reference can produce different bytes. Source identity
|
||||
alone cannot prove what qualification tested or what publication shipped.
|
||||
|
||||
## Decision
|
||||
|
||||
Every candidate is bound to an exact full Git commit SHA and an immutable artifact
|
||||
identified by SHA-256, filename, package name, version, size, and build-run
|
||||
identity. When runtime behavior comes from a payload that can differ from package
|
||||
bytes, its SHA-256 is recorded separately.
|
||||
|
||||
Evidence documents are themselves immutable bytes with a SHA-256 and an opaque
|
||||
URI. A producer identity records repository, workflow, run ID, attempt, and the
|
||||
producer commit. Cross-repository consumers verify the digest before processing
|
||||
the artifact or evidence. Secrets and credentials are never evidence fields.
|
||||
|
||||
The candidate artifact is built once. Downstream deterministic, integration, and
|
||||
benchmark lanes consume those exact bytes; they do not rebuild `main` and reuse
|
||||
the candidate identity. Final Gate B compares published bytes with the qualified
|
||||
artifact or applies an explicitly approved, policy-versioned runtime-payload
|
||||
equivalence rule.
|
||||
|
||||
## Consequences
|
||||
|
||||
Artifact stores and workflow runs require immutable retention sufficient for
|
||||
audit. A digest, source SHA, schema version, or producer mismatch makes evidence
|
||||
`inconclusive` or `fail` according to policy; it can never pass silently. Future
|
||||
controllers must enforce equality across documents in addition to validating
|
||||
each document's JSON Schema.
|
||||
@@ -0,0 +1,37 @@
|
||||
# ADR 0003: A1 versus B is the release benchmark claim
|
||||
|
||||
- Status: Accepted
|
||||
- Date: 2026-08-13
|
||||
|
||||
## Context
|
||||
|
||||
Comparing Headroom against a direct provider path changes more than compression
|
||||
and cannot isolate Headroom's effect. Release evidence needs a paired comparison
|
||||
whose intended difference is only optimization state.
|
||||
|
||||
## Decision
|
||||
|
||||
The headline release comparison is:
|
||||
|
||||
- A1 (`a1_passthrough`): the Headroom proxy and candidate artifact with
|
||||
optimization disabled.
|
||||
- B (`b_headroom`): the same Headroom proxy and candidate artifact with
|
||||
optimization enabled.
|
||||
|
||||
A1 and B must have equal candidate source SHA, artifact digest, rollout registry
|
||||
and snapshot digests, model, agent, taskset, environment image, and resource
|
||||
limits. Tasks are paired, arm order is randomized, and the versioned policy sets
|
||||
repeat count and statistical decision rules. A direct-provider A0 arm may be
|
||||
recorded for diagnosis but is not the headline comparator.
|
||||
|
||||
The benchmark producer reports an explicit identity-verification verdict. Any
|
||||
identity mismatch makes the experiment and release evidence inconclusive. JSON
|
||||
Schema constrains the arm shapes and intended optimization states; the benchmark
|
||||
worker and qualification controller must enforce equality between arms.
|
||||
|
||||
## Consequences
|
||||
|
||||
A single noisy run is not hard release evidence. Missing telemetry, provider
|
||||
outages, unequal environments, or identity drift remain visible and cannot be
|
||||
coerced into `pass`. Accuracy, savings, latency, reliability, and missing-data
|
||||
rules live in versioned policy rather than workflow shell code.
|
||||
@@ -0,0 +1,38 @@
|
||||
# ADR 0004: Black-box release benchmark boundary
|
||||
|
||||
- Status: Accepted
|
||||
- Date: 2026-08-13
|
||||
|
||||
## Context
|
||||
|
||||
Internal unit and compression tests are necessary but do not prove that the
|
||||
packaged proxy preserves real agent, streaming, and tool-use behavior. Conversely,
|
||||
benchmark infrastructure must not gain release credentials or execute arbitrary
|
||||
release commands.
|
||||
|
||||
## Decision
|
||||
|
||||
Release benchmarks exercise Headroom through its supported public protocol and
|
||||
observable provenance surfaces, using the immutable candidate artifact. They
|
||||
record taskset revision and digest, model and agent identities, environment,
|
||||
resource limits, rollout snapshot, artifact digest, attempts, telemetry
|
||||
completeness, and raw-result identity.
|
||||
|
||||
The benchmark repository receives only the minimum candidate and experiment
|
||||
identities needed to run. It verifies artifact digests before installation and
|
||||
returns an immutable result reference with authenticated producer identity. It
|
||||
does not receive provider secrets through release evidence, package-publish
|
||||
credentials, or permission to mutate the Headroom repository.
|
||||
|
||||
Failures and cancellations preserve terminal evidence. A provider or
|
||||
infrastructure failure is `inconclusive`, not a candidate pass and not necessarily
|
||||
a candidate-caused failure. The qualification controller applies the registered
|
||||
policy to the returned reference; callback identity alone does not establish a
|
||||
passing result.
|
||||
|
||||
## Consequences
|
||||
|
||||
Hermetic PR simulators, scheduled live smoke tests, and release-candidate lanes
|
||||
can share one result shape while retaining their execution depth. Cross-repository
|
||||
authentication, artifact transport, callback authorization, and retention need
|
||||
separate implementation and security review in later PRs.
|
||||
@@ -0,0 +1,40 @@
|
||||
# ADR 0005: Release overrides and fail-closed policy
|
||||
|
||||
- Status: Accepted
|
||||
- Date: 2026-08-13
|
||||
|
||||
## Context
|
||||
|
||||
Headroom product transforms may fail open to preserve requests, but release
|
||||
control makes a different safety decision: publication must not proceed without
|
||||
complete, matching, current evidence. Operational exceptions still need an
|
||||
auditable representation.
|
||||
|
||||
## Decision
|
||||
|
||||
Release evidence uses exactly four policy statuses: `pass`, `fail`,
|
||||
`inconclusive`, and `skipped_by_policy`. Missing, stale, invalid, mismatched,
|
||||
revoked, unauthorized, or schema-incompatible required evidence cannot produce
|
||||
`pass`. `skipped_by_policy` is allowed only when the selected policy version does
|
||||
not require that evidence.
|
||||
|
||||
Policy is versioned data. It maps risk classes to required Gate A and Gate B
|
||||
evidence and deterministic rules. Missing-data behavior is `inconclusive`.
|
||||
Thresholds and exceptions are not embedded as ad hoc workflow conditions.
|
||||
|
||||
An override records a unique ID, narrow scope, reason, human approver, approval
|
||||
time, expiry, and optional ticket URI. It never contains credentials. Controllers
|
||||
authenticate the approver, reject expired or unauthorized overrides, and include
|
||||
accepted overrides in the gate result. An unsafe runtime rollout override makes
|
||||
the rollout qualification-ineligible and cannot be overridden into a release
|
||||
pass by this mechanism.
|
||||
|
||||
Qualification revocation is explicit, immutable evidence linked to the original
|
||||
qualification. A revoked qualification cannot authorize promotion or publication.
|
||||
|
||||
## Consequences
|
||||
|
||||
The stable GitHub check will be named `release-policy` even when risk-specific
|
||||
evidence varies. Workflow code remains a thin adapter around a tested policy
|
||||
evaluator. Operational urgency stays visible to reviewers instead of silently
|
||||
weakening the evidence chain.
|
||||
+3
-3
@@ -51,12 +51,12 @@ export default function Layout({ children }: LayoutProps<'/'>) {
|
||||
<body className="flex flex-col min-h-screen">
|
||||
<RootProvider>
|
||||
{/* Dismissible; Fumadocs remembers the dismissal per id in localStorage. */}
|
||||
<Banner id="teams-perk-2026">
|
||||
<Banner id="teams-contact-2026">
|
||||
<a
|
||||
href="https://headroom-perks.vercel.app/?source=github&utm_source=docs&utm_medium=banner"
|
||||
href="https://headroomlabs.ai"
|
||||
className="font-medium underline-offset-4 hover:underline"
|
||||
>
|
||||
Headroom for Teams: 3 months free with a 12-month plan →
|
||||
Want more savings? Headroom for teams and enterprises: talk to us →
|
||||
</a>
|
||||
</Banner>
|
||||
{children}
|
||||
|
||||
+12
-12
@@ -15,7 +15,7 @@
|
||||
"fumadocs-typescript": "^5.5.1",
|
||||
"fumadocs-ui": "16.17.1",
|
||||
"lucide-react": "^1.48.0",
|
||||
"next": "^16.4.0",
|
||||
"next": "^16.4.3",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0",
|
||||
"recharts": "^3.10.1",
|
||||
@@ -193,23 +193,23 @@
|
||||
|
||||
"@mdx-js/mdx": ["@mdx-js/mdx@3.1.1", "", { "dependencies": { "@types/estree": "^1.0.0", "@types/estree-jsx": "^1.0.0", "@types/hast": "^3.0.0", "@types/mdx": "^2.0.0", "acorn": "^8.0.0", "collapse-white-space": "^2.0.0", "devlop": "^1.0.0", "estree-util-is-identifier-name": "^3.0.0", "estree-util-scope": "^1.0.0", "estree-walker": "^3.0.0", "hast-util-to-jsx-runtime": "^2.0.0", "markdown-extensions": "^2.0.0", "recma-build-jsx": "^1.0.0", "recma-jsx": "^1.0.0", "recma-stringify": "^1.0.0", "rehype-recma": "^1.0.0", "remark-mdx": "^3.0.0", "remark-parse": "^11.0.0", "remark-rehype": "^11.0.0", "source-map": "^0.7.0", "unified": "^11.0.0", "unist-util-position-from-estree": "^2.0.0", "unist-util-stringify-position": "^4.0.0", "unist-util-visit": "^5.0.0", "vfile": "^6.0.0" } }, ""],
|
||||
|
||||
"@next/env": ["@next/env@16.4.0", "", {}, "sha512-pyLlT5oafGlX8X7xjgGNXz5dNIDSxREm+qD6i9VLSZiZFopA/XWl8NM/KPmLx/8EG/++c49iid3gNWSQW1+2dQ=="],
|
||||
"@next/env": ["@next/env@16.4.3", "", {}, "sha512-a7tz1QCcWWkwC/rPJcPMJk/UNRu9CFhDd3OHYE5hddbJrs8BqRTalxI6GlKCWEGzRLHN+S/B7a4PAHCtm25aBQ=="],
|
||||
|
||||
"@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@16.4.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-yyZ+9MgViAKLLb5l1gPBGjRwnq3teNLb5Zx6JEw8LzNSTjlsnp+baUHFxTgl7PpjCmKf48VQfyipG1eBflb48Q=="],
|
||||
"@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@16.4.3", "", { "os": "darwin", "cpu": "arm64" }, "sha512-4yq5EXBt+VDtAZwTyfijaFp5D2C5oz3Ikw5a2kiX2K9nw72vrZX2q5UuAlkPtUMO1tQz6JTKpaKWjS7OOefTDQ=="],
|
||||
|
||||
"@next/swc-darwin-x64": ["@next/swc-darwin-x64@16.4.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-RePEEejEj1Auf5s9qEcG0JbcDP3ceNUS/ofNX8AhxzgIjTVlZIHMatlp16YplcSMpsVo/ZMQHJTjbMYJznjGUg=="],
|
||||
"@next/swc-darwin-x64": ["@next/swc-darwin-x64@16.4.3", "", { "os": "darwin", "cpu": "x64" }, "sha512-1Rvkn/LUhnEF8WxnRkOrqGhbwXui1bkWFxONKIbN+r7C+9KHDSZ+iUoj4CzymVMWUyZIyx9szcb9+kbKhD500A=="],
|
||||
|
||||
"@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@16.4.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-HhsyCqd+NpmvDDVY/LqkAN24f+QVvXh3ie+PfcwKinWL2Mu826JymQxJXGjAIfmJ4VlHjp4Pe/nZtXtUoEMAqw=="],
|
||||
"@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@16.4.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-dCKpXErGg3abUM6t5JTJV/ottVBTStJB5lRJTbgdUdQaQ+jNHiK56Hsc0YAEg/rinSh42hYG3HWiYmEMdilnxg=="],
|
||||
|
||||
"@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@16.4.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-sN9Pf+Zh+RpZAOmbR7d8KAA8T61CVhawtbEJ2Bk6QrRzx6Z/6haaF4UiwBzytM96GRRRWZh9/WALIEO3npMamA=="],
|
||||
"@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@16.4.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-WwYbhWkhYBvBtib1K4W0kL8MW2snBD2A5b3SN4vPpqalZbZs5+bQ1yzAdepVoOqrFfEW3dmREy4Zs1MrWcrFbw=="],
|
||||
|
||||
"@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@16.4.0", "", { "os": "linux", "cpu": "x64" }, "sha512-D5M5xLWQVd1CvR+L7BickM1weRfmM41x3L1NWcnKY/oyJJqr1qwaCgmu3dMAhLBOMdZwSuDCRV6DJRRpiUkbDQ=="],
|
||||
"@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@16.4.3", "", { "os": "linux", "cpu": "x64" }, "sha512-QymWvfUwDEC5/lpJOsxX5VAbyoR2D13+2Jsjz4be7gT4LPqEgdpkeLIR/HFfCLgKzoMhpJbp6I/JnogyNZHcaA=="],
|
||||
|
||||
"@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@16.4.0", "", { "os": "linux", "cpu": "x64" }, "sha512-8d5WLS6a9YalqpOgXdlbvonFu+sIgjA+CO6tGzetrpPVcUL56foa7B7664h41rAlbLi5fJwK4vWji3zf4QDy+w=="],
|
||||
"@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@16.4.3", "", { "os": "linux", "cpu": "x64" }, "sha512-Vmjd9D7DpA4Vv3cUlr82QWgJD/BQZmns801vtC5VWHg6jCIA4a5vMKpQnfrM2pyCrp2eV0ENdUg4PlN3bAc2Yw=="],
|
||||
|
||||
"@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@16.4.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-sQuOIiW3snb48UwrBcDMvFA/u03qtw2LeuSIxFIQ9AJuW9UG/4Ddsfo+eV73PnZwBhyncMtsKVh7PrzMol2/fA=="],
|
||||
"@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@16.4.3", "", { "os": "win32", "cpu": "arm64" }, "sha512-lG1pPdPLk7gTyGb00n5JIMLdBJgjb+UEhSdZvFbhUMg0DyC6z4B7RnpSKF9VCd4imkLObVbXOFA0kFCpw7yFow=="],
|
||||
|
||||
"@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@16.4.0", "", { "os": "win32", "cpu": "x64" }, "sha512-6/33lCuxpdHUy27RegyGM/5uTpF7YZd3UR4D0gpkOA/tWY5YR7msbQjqPgCZmSmxrrTLGCXYA4A8vT2H5DPGTQ=="],
|
||||
"@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@16.4.3", "", { "os": "win32", "cpu": "x64" }, "sha512-NmQC9RkJdnPXRaMxtkCzobB3teVjqF33oSOnwDfi+XYGWWYpt+xlGK3mtktSKLbdjwaWbJu2OkkMiRFGUUncKg=="],
|
||||
|
||||
"@radix-ui/number": ["@radix-ui/number@1.1.3", "", {}, "sha512-Road2bidD0uu/1BGDOWNdPI06g0lIRy6IF9GZcIrDK2KGItfor8IQwQa+yM2ERgHM1MmHxaxpTzk0/Jp42lNfA=="],
|
||||
|
||||
@@ -781,7 +781,7 @@
|
||||
|
||||
"nanoid": ["nanoid@3.3.20", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ=="],
|
||||
|
||||
"next": ["next@16.4.0", "", { "dependencies": { "@next/env": "16.4.0", "@swc/helpers": "0.5.23", "baseline-browser-mapping": "^2.9.19", "caniuse-lite": "^1.0.30001579", "postcss": "8.5.23", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "16.4.0", "@next/swc-darwin-x64": "16.4.0", "@next/swc-linux-arm64-gnu": "16.4.0", "@next/swc-linux-arm64-musl": "16.4.0", "@next/swc-linux-x64-gnu": "16.4.0", "@next/swc-linux-x64-musl": "16.4.0", "@next/swc-win32-arm64-msvc": "16.4.0", "@next/swc-win32-x64-msvc": "16.4.0", "sharp": "^0.35.4" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.51.1", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-N2C+9q89Z/oLrsepSRS4jRMtwmUZAoZuAHU0e9T6+sAB5DdhADmrnOW+zjYijlrYFmVfmQhGVGy9eMFoB7UgKg=="],
|
||||
"next": ["next@16.4.3", "", { "dependencies": { "@next/env": "16.4.3", "@swc/helpers": "0.5.23", "baseline-browser-mapping": "^2.9.19", "caniuse-lite": "^1.0.30001579", "postcss": "8.5.23", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "16.4.3", "@next/swc-darwin-x64": "16.4.3", "@next/swc-linux-arm64-gnu": "16.4.3", "@next/swc-linux-arm64-musl": "16.4.3", "@next/swc-linux-x64-gnu": "16.4.3", "@next/swc-linux-x64-musl": "16.4.3", "@next/swc-win32-arm64-msvc": "16.4.3", "@next/swc-win32-x64-msvc": "16.4.3", "sharp": "^0.35.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.51.1", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-OqxKTGi9u80FydydsMNYNjnuje9Au+kvHlt2GZ//ftdpDHm1dxKqAaENoOOTX5wKzn+9vaKUNIfZeyZUuLhCnA=="],
|
||||
|
||||
"next-themes": ["next-themes@0.4.6", "", { "peerDependencies": { "react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc", "react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc" } }, ""],
|
||||
|
||||
@@ -955,7 +955,7 @@
|
||||
|
||||
"zbsearch": ["zbsearch@4.0.1", "", {}, "sha512-lmnEEnb93QQcNv7qARDr7jBVPxYdZbZ9XdZ0dbZ0qaOvGne4jJMW4fjwPfVaUKQXv3FNWvGbDwRDgyaSb1pc8w=="],
|
||||
|
||||
"zod": ["zod@4.6.5", "", {}, "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q=="],
|
||||
"zod": ["zod@4.6.7", "", {}, "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg=="],
|
||||
|
||||
"zwitch": ["zwitch@2.0.4", "", {}, ""],
|
||||
|
||||
|
||||
@@ -41,26 +41,19 @@ Every call to `client.messages.create()` compresses messages first. The response
|
||||
|
||||
`withHeadroom()` returns a proxy around your Anthropic client that intercepts `messages.create()`:
|
||||
|
||||
1. Converts Anthropic-format messages to OpenAI format
|
||||
2. Sends them to the Headroom proxy's `/v1/compress` endpoint
|
||||
3. Converts the compressed messages back to Anthropic format
|
||||
4. Forwards the request to Anthropic as normal
|
||||
1. Sends your `messages` to the Headroom proxy's `/v1/compress` endpoint as they are, in Anthropic format
|
||||
2. Forwards the request to Anthropic with the compressed messages in place
|
||||
|
||||
### Message format conversion
|
||||
### Message format
|
||||
|
||||
The adapter handles the full Anthropic message format including content blocks:
|
||||
Nothing is converted. `POST /v1/compress` compresses Anthropic content blocks natively — see [Message format](/docs/proxy#message-format) — and returns the same shape it received, so every block reaches Anthropic exactly as you built it:
|
||||
|
||||
| Anthropic format | OpenAI format |
|
||||
|-----------------|---------------|
|
||||
| `{ type: "text", text: "..." }` | `{ role: "user", content: "..." }` |
|
||||
| `{ type: "tool_use", id, name, input }` | `{ tool_calls: [{ id, function: { name, arguments } }] }` |
|
||||
| `{ type: "tool_result", tool_use_id, content }` | `{ role: "tool", tool_call_id, content }` |
|
||||
- `thinking` and `redacted_thinking` blocks keep their `signature` and `data`, which Anthropic requires back unmodified within a tool-use turn
|
||||
- `cache_control` markers stay on the blocks that carry them
|
||||
- `tool_use` and `tool_result` blocks keep their ids; only the content of large `tool_result` blocks changes
|
||||
- images, documents, citations and server-tool blocks pass through untouched
|
||||
|
||||
This conversion is lossless. Your request and response behave identically to an unwrapped client.
|
||||
|
||||
<Callout type="info" title="The conversion is an SDK choice, not an API requirement">
|
||||
`POST /v1/compress` does no format conversion and compresses Anthropic content blocks natively — see [Message format](/docs/proxy#message-format). If you are calling the endpoint directly (from a gateway, or LiteLLM's `headroom` guardrail), send Anthropic-shaped messages as-is; you get the same shape back. Only this TypeScript adapter converts, because it normalises on OpenAI types internally.
|
||||
</Callout>
|
||||
If the proxy is unreachable and `fallback` is enabled, the original messages are forwarded unchanged.
|
||||
|
||||
## Options
|
||||
|
||||
|
||||
@@ -62,6 +62,19 @@ Headroom injects a `headroom_retrieve` tool into the LLM's available tools:
|
||||
|
||||
The LLM sees this tool alongside your application's tools and can call it whenever the compressed data is insufficient.
|
||||
|
||||
If your client already registers retrieval through MCP, Headroom keeps that
|
||||
client-owned tool instead of adding a second bare `headroom_retrieve`.
|
||||
Supported spellings include OpenCode's `headroom_headroom_retrieve` and MCP
|
||||
wrappers such as `mcp__headroom__headroom_retrieve` and
|
||||
`mcp_Headroom_headroom_retrieve`. The same rule applies to session-aware
|
||||
injection and the per-request fallback, so Headroom does not advertise an
|
||||
unavailable bare retrieval tool alongside the client's executable alias.
|
||||
|
||||
These ownership aliases are limited to the default `headroom` MCP server
|
||||
name. An unrelated server such as `mcp__other__headroom_retrieve` does not
|
||||
replace the proxy's retrieval tool. Optional CCR system instructions use
|
||||
the executable name selected from the available tool definitions.
|
||||
|
||||
## Phase 3: Response Handler
|
||||
|
||||
When the LLM calls `headroom_retrieve`:
|
||||
@@ -71,7 +84,9 @@ When the LLM calls `headroom_retrieve`:
|
||||
3. The result is added to the conversation
|
||||
4. The API call continues automatically
|
||||
|
||||
The client never sees CCR tool calls on the Anthropic and OpenAI proxy paths; Headroom resolves them transparently there.
|
||||
On the Anthropic and OpenAI proxy paths, only retrieval-only responses naming
|
||||
the proxy's bare `headroom_retrieve` are resolved server-side. Mixed responses
|
||||
and all MCP-registered retrieval aliases are forwarded for the client to execute.
|
||||
|
||||
<Callout type="warning" title="Gemini CCR boundary">
|
||||
Buffered native Gemini requests resolve `headroom_retrieve` server-side and
|
||||
|
||||
@@ -383,7 +383,7 @@ headroom proxy --learn --min-evidence 3
|
||||
| `HEADROOM_TOIN_PATH` | Override TOIN telemetry file location. Always wins when set. | derived from `${HEADROOM_WORKSPACE_DIR}` |
|
||||
| `HEADROOM_SUBSCRIPTION_STATE_PATH` | Override subscription tracker state file. Always wins when set. | derived from `${HEADROOM_WORKSPACE_DIR}` |
|
||||
| `HEADROOM_PERIODIC_TOIN_STATS` | Controls periodic TOIN stats logging in long-lived proxy workers. Set to `0`, `false`, `off`, or `no` to disable the 5-minute stats loop without disabling TOIN learning or request-time feedback. | `true` |
|
||||
| `HEADROOM_MEMORY_INJECTION_MODE` | Memory-context routing mode: `live_zone_tail` (default) or `disabled`. The legacy `system_prompt` mode was retired by PR-A2; supplying it raises. | `live_zone_tail` |
|
||||
| `HEADROOM_MEMORY_INJECTION_MODE` | Memory-context routing mode: `live_zone_tail` (default), `disabled`, or `tool` (auto-injection off; the agent calls memory tools explicitly). The legacy `system_prompt` mode was retired by PR-A2; supplying it raises. | `live_zone_tail` |
|
||||
| `HEADROOM_PROXY_PYTHON_FORWARDER_MODE` | Python forwarder serialization mode. `byte_faithful` (default) forwards original request bytes verbatim when no transform mutated the body and re-serializes canonically only when needed — keeps Anthropic prompt-cache hit-rate intact. `legacy_json_kwarg` is an explicit operator opt-in for emergency rollback to the historical `httpx ... json=body` behavior. NOT a fallback — only flip on explicit operator decision. | `byte_faithful` |
|
||||
| `HEADROOM_STRIP_INTERNAL_HEADERS` | Python proxy: whether to strip internal `x-headroom-*` request headers (e.g. `x-headroom-bypass`, `x-headroom-mode`, `x-headroom-user-id`, `x-headroom-stack`, `x-headroom-base-url`) before every upstream forwarder call (PR-A5, fixes P5-49). `enabled` (default) stops fingerprinting / leakage. `disabled` is an explicit operator opt-in for diagnostic shadow tracing — NOT a fallback. Inbound reads of these headers (bypass gating, memory user-id resolution) are unaffected because they read `request.headers` directly. | `enabled` |
|
||||
| `HEADROOM_PROXY_STRIP_INTERNAL_HEADERS` | Rust proxy: same policy as `HEADROOM_STRIP_INTERNAL_HEADERS` but for the Rust transparent proxy. Stripping happens inside `build_forward_request_headers` so both HTTP and WebSocket upstream calls are gated by one flag. `enabled` default; `disabled` operator opt-in for diagnostic shadow tracing. Response-side `X-Headroom-*` injection (e.g. `x-headroom-tokens-saved`) is unrelated and stays. | `enabled` |
|
||||
|
||||
@@ -116,11 +116,12 @@ pip install "headroom-ai[all]"
|
||||
| `autogen` | AutoGen AgentChat integration; **not in `[all]`** | `pip install "headroom-ai[autogen]"` |
|
||||
| `anyllm` | any-llm multi-provider backend (Python 3.11+); **not in `[all]`** | `pip install "headroom-ai[anyllm]"` |
|
||||
| `bedrock` | Native AWS Bedrock credentials/backend support; **not in `[all]`** | `pip install "headroom-ai[bedrock]"` |
|
||||
| `redis` | Redis client for state shared across replicas (`HEADROOM_CCR_BACKEND=redis`, `HEADROOM_COMPRESS_SESSION_STORE`); **not in `[all]`**, included in every Docker image | `pip install "headroom-ai[redis]"` |
|
||||
| `evals` | Evaluation framework (GSM8K, SQuAD, BFCL benchmarks) | `pip install "headroom-ai[evals]"` |
|
||||
| `pytorch-mps` | Apple-GPU (MPS) memory-embedder offload — **macOS only**, not in `[all]` (torch + sentence-transformers); opt in with `HEADROOM_EMBEDDER_RUNTIME=pytorch_mps` | `pip install "headroom-ai[pytorch-mps]"` |
|
||||
| `html` | HTML main-content extraction with trafilatura | `pip install "headroom-ai[html]"` |
|
||||
| `spreadsheet` | `.xlsx` / `.xls` ingestion with openpyxl and xlrd | `pip install "headroom-ai[spreadsheet]"` |
|
||||
| `sandbox` | Torch-free proxy bundle for constrained environments | `pip install "headroom-ai[sandbox]"` |
|
||||
| `lean` | Torch-free proxy bundle for constrained environments (a dependency profile; it provides no isolation). `sandbox` is a deprecated alias | `pip install "headroom-ai[lean]"` |
|
||||
| `all` | Runtime bundle: `proxy,code,ml,memory,relevance,image,reports,otel,evals,voice,html,mcp,spreadsheet` | `pip install "headroom-ai[all]"` |
|
||||
|
||||
`[all]` is the full built-in runtime bundle, not every integration or optional
|
||||
@@ -255,15 +256,15 @@ If you want a host `headroom` CLI that keeps Headroom itself inside a container
|
||||
|
||||
| Tag | Extras | Base image | Description |
|
||||
|---|---|---|---|
|
||||
| `latest` | `proxy,bedrock` | Debian slim | Default image, runs as non-root |
|
||||
| `<version>` | `proxy,bedrock` | Debian slim | Pinned release, same default variant |
|
||||
| `nonroot` | `proxy,bedrock` | Debian slim | Explicit non-root variant |
|
||||
| `code` | `proxy,code,bedrock` | Debian slim | Includes tree-sitter for code compression |
|
||||
| `code-nonroot` | `proxy,code,bedrock` | Debian slim | Code compression, non-root |
|
||||
| `slim` | `proxy,bedrock` | Distroless | Minimal image, no shell |
|
||||
| `slim-nonroot` | `proxy,bedrock` | Distroless | Minimal, non-root |
|
||||
| `code-slim` | `proxy,code,bedrock` | Distroless | Code compression, minimal |
|
||||
| `code-slim-nonroot` | `proxy,code,bedrock` | Distroless | Code compression, minimal, non-root |
|
||||
| `latest` | `proxy,bedrock,redis` | Debian slim | Default image, runs as non-root |
|
||||
| `<version>` | `proxy,bedrock,redis` | Debian slim | Pinned release, same default variant |
|
||||
| `nonroot` | `proxy,bedrock,redis` | Debian slim | Explicit non-root variant |
|
||||
| `code` | `proxy,code,bedrock,redis` | Debian slim | Includes tree-sitter for code compression |
|
||||
| `code-nonroot` | `proxy,code,bedrock,redis` | Debian slim | Code compression, non-root |
|
||||
| `slim` | `proxy,bedrock,redis` | Distroless | Minimal image, no shell |
|
||||
| `slim-nonroot` | `proxy,bedrock,redis` | Distroless | Minimal, non-root |
|
||||
| `code-slim` | `proxy,code,bedrock,redis` | Distroless | Code compression, minimal |
|
||||
| `code-slim-nonroot` | `proxy,code,bedrock,redis` | Distroless | Code compression, minimal, non-root |
|
||||
|
||||
### Build from source
|
||||
|
||||
|
||||
+72
-20
@@ -112,10 +112,10 @@ headroom proxy --mode cache
|
||||
|
||||
| Profile | Target savings | Mode | Notes |
|
||||
|---------|----------------|------|-------|
|
||||
| `coding` | emergent (~50%) | `cache` | **Default.** Delta-only compression at ~0 prefix-cache busts; never lossy-compresses file reads. |
|
||||
| `balanced` | ~70% | `token` | Moderate compression with structural compaction. |
|
||||
| `agent-90` | ~90% | `token` | Aggressive; pins a `0.10` keep-ratio and forces Kompress. |
|
||||
| `general` | emergent (~60%) | `token` | Non-coding workloads. |
|
||||
| `coding` | ~50% of new input tokens (emergent) | `cache` | **Default.** Delta-only compression at ~0 prefix-cache busts; never lossy-compresses file reads. Whole-request and lifetime ratios are much lower in cache mode. |
|
||||
| `balanced` | ~70% of new input tokens | `token` | Moderate compression with structural compaction. |
|
||||
| `agent-90` | ~90% of new input tokens | `token` | Aggressive; pins a `0.10` keep-ratio and forces Kompress. |
|
||||
| `general` | ~60% of new input tokens (emergent) | `token` | Non-coding workloads. |
|
||||
|
||||
An unrecognized `HEADROOM_SAVINGS_PROFILE` value logs a warning and falls back to `coding` (the same default an unset variable resolves to) — the proxy never fails to start over a bad profile name. `balanced` is used only as a last-resort fallback when the runtime has no `coding` entry at all (old-runtime/new-client version skew). See `headroom/agent_savings.py` for each profile's full set of knobs.
|
||||
|
||||
@@ -148,6 +148,35 @@ headroom proxy --codex-wire-debug
|
||||
HEADROOM_COMPRESS_PASSTHROUGH=1 headroom proxy
|
||||
```
|
||||
|
||||
Automatic memory lookup renders a separate, bounded embedding query:
|
||||
|
||||
| Input | Maximum characters |
|
||||
| --- | ---: |
|
||||
| Entire query, including delimiters | 4096 |
|
||||
| Latest user message tail | 2048 |
|
||||
| Each recent tool-output tail | 512 |
|
||||
| Each recent assistant-turn tail | 512 |
|
||||
|
||||
These are source-size limits, not token estimates. The local ONNX and
|
||||
sentence-transformers embedders then use their actual tokenizer and configured
|
||||
input window, including special tokens. When both sources are present, they
|
||||
reserve room for the question and context separately; unused space can go to
|
||||
the other source. Newest tool evidence is at the end of the context so retaining
|
||||
its tail does not silently discard it behind a long question.
|
||||
|
||||
Remote embedders that do not expose a local tokenizer retain the character
|
||||
limits; these do not guarantee an arbitrary remote model's token window.
|
||||
The raw `MemoryQuery` fields stay unchanged, and SDK callers that render without
|
||||
a budget still receive the full sources.
|
||||
|
||||
Anthropic's pre-upstream lookup keeps its existing 2.0-second deadline,
|
||||
configured by `ProxyConfig.anthropic_pre_upstream_memory_context_timeout_seconds`.
|
||||
Bounding the input limits embedding work; it is not a guarantee against cold
|
||||
model initialization or a slow embedding server. Memory failures include the
|
||||
exception representation, so an otherwise empty timeout is identifiable as
|
||||
`TimeoutError()`.
|
||||
|
||||
|
||||
<Callout type="info" title="LLMLingua removed from the proxy CLI">
|
||||
The old LLMLingua proxy toggles are no longer part of the CLI. Headroom's proxy compression path uses ContentRouter plus the current built-in compressors, including Kompress where applicable.
|
||||
</Callout>
|
||||
@@ -165,10 +194,10 @@ HEADROOM_SAVINGS_PROFILE=agent-90 headroom proxy
|
||||
|
||||
| Profile | Target savings | proxy_mode | force_kompress | Best for |
|
||||
|---------|---------------|------------|---------------|----------|
|
||||
| `coding` (default) | ~50% (emergent) | `cache` | No | Coding agents — preserves Anthropic prefix-cache stability |
|
||||
| `agent-90` | 90% | `token` | Yes | Non-coding, cost-sensitive, or high-volume workloads |
|
||||
| `balanced` | 70% | `token` | No | General-purpose moderate compression |
|
||||
| `general` | ~60% (emergent) | `token` | No | Non-coding chat, little code in context |
|
||||
| `coding` (default) | ~50% of new input tokens (emergent) | `cache` | No | Coding agents — preserves Anthropic prefix-cache stability. Whole-request and lifetime ratios are much lower in cache mode. |
|
||||
| `agent-90` | ~90% of new input tokens | `token` | Yes | Non-coding, cost-sensitive, or high-volume workloads |
|
||||
| `balanced` | ~70% of new input tokens | `token` | No | General-purpose moderate compression |
|
||||
| `general` | ~60% of new input tokens (emergent) | `token` | No | Non-coding chat, little code in context |
|
||||
|
||||
**`coding` (default)** — Optimizes for coding-agent workloads with Anthropic. Uses **cache mode** (`proxy_mode="cache"`): compresses only the newest delta in each turn so the provider's prefix-cache is never busted. User messages are compressed, system prompts preserved (hottest cache). `protect_recent` is `0` — in cache mode the delta already *is* the newest turn, so a turn-count guard would suppress the only thing cache mode compresses; byte-exact fidelity instead comes from `protect_reads=True` (file reads are never lossy-compressed). Lossless-first with lossy fallback; tool search and cross-turn dedup enabled. This is the profile that `headroom wrap` uses.
|
||||
|
||||
@@ -291,6 +320,7 @@ Fine-grained control over what gets compressed and how hard. Most users pick a [
|
||||
| `--mode` / `HEADROOM_MODE` | `cache` | `cache` compresses only the newest delta (prefix-cache safe); `token` maximizes removal. |
|
||||
| `--target-ratio` / `HEADROOM_TARGET_RATIO` | unset | Keep-ratio for ML text compression; lower = more aggressive (e.g. `0.10`). |
|
||||
| `HEADROOM_MIN_TOKENS` | `500` | Minimum block size before a tool output is compressed. |
|
||||
| `HEADROOM_SHELL_RESULT_MIN_CHARS` | `2000` | Shell tool results shorter than this many characters bypass lossy compression. For top-level text blocks, the threshold uses their combined text length. Byte-lossless folds such as search grouping may still apply. Applies to `bash`, `shell`, `local_shell`, and aliases such as `run_shell_command`/`execute_command`; set `0` to restore lossy compression. |
|
||||
| `HEADROOM_COMPRESS_USER_MESSAGES` | profile | Compress text inside user-role messages. The `coding` profile turns this on; set `0` to keep user text verbatim under it. Anthropic `tool_result` blocks compress either way. No `--compress-user-messages` flag on `headroom proxy`; the direct module entry point (`python -m headroom.proxy.server`) does accept one. |
|
||||
| `HEADROOM_COMPRESS_SYSTEM_MESSAGES` | unset | Compress system prompts. Off by default to keep the hottest cache prefix stable. |
|
||||
| `HEADROOM_PROTECT_RECENT` | profile | Never compress the N most recent turns. |
|
||||
@@ -381,13 +411,16 @@ when they are enabled.
|
||||
only, and so is every rotated backup (`proxy-8000.log.1`, …). This is not
|
||||
conditional on which content switch is on. If the log path already exists as a
|
||||
symlink, Headroom refuses to log rather than write through it, and says so.
|
||||
- **Windows:** **Headroom does not restrict the log file.** Read access on NTFS is
|
||||
decided by the file's ACL; `chmod` there only toggles the read-only attribute,
|
||||
and Python has no API for setting an ACL, so Headroom does not claim a
|
||||
protection it cannot establish. The log inherits the ACL of the directory it
|
||||
is written into, and the proxy logs a warning at startup saying so. Keep
|
||||
`%USERPROFILE%\.headroom` (or your chosen `--log-file` path) off shared
|
||||
volumes and out of directories with broadened permissions.
|
||||
- **Windows:** Headroom restricts the log file too, through an NTFS ACL —
|
||||
Python has no ACL API, so this goes directly through `ctypes` rather than a
|
||||
third-party dependency. The DACL it sets grants access to exactly the
|
||||
current user, replacing (not merging with) whatever was inherited from the
|
||||
parent directory. This can fail for reasons unrelated to Headroom's own
|
||||
code — a non-NTFS volume, a missing privilege — so the proxy re-reads the
|
||||
file afterward to confirm, and only logs a warning at startup if that
|
||||
check fails. If you see that warning, keep `%USERPROFILE%\.headroom` (or
|
||||
your chosen `--log-file` path) off shared volumes and out of directories
|
||||
with broadened permissions.
|
||||
|
||||
A log shipper or sidecar running as a different user or group cannot read the
|
||||
runtime log on Linux/macOS. Run the collector as the same user, or copy the file
|
||||
@@ -401,7 +434,7 @@ with a privileged job.
|
||||
| `HEADROOM_PROXY_TOKEN` | none | Require a token from non-loopback callers, as `X-Headroom-Proxy-Token: <token>` or `Authorization: Bearer <token>`. The token is removed from the request before it is forwarded upstream; clients that also send a provider credential should use `X-Headroom-Proxy-Token` and keep `Authorization` for the provider. Also gates the read-only operator routes (`/stats-history`, `/quota`, `/subscription-window`, `/metrics`), which otherwise answer loopback and trusted-CIDR callers only. |
|
||||
| `HEADROOM_ALLOW_UNAUTHENTICATED_BIND` | `false` | Acknowledge a non-loopback bind (`--host 0.0.0.0`, `::`, a LAN address) with **no** `HEADROOM_PROXY_TOKEN`. Without a token or this flag the proxy refuses to start, because `/v1/*` would relay upstream with the operator's credentials for every peer that can reach the port. Only set it when the runtime already restricts reachability (a container published on `127.0.0.1`). |
|
||||
| `HEADROOM_COMPRESS_ALLOW_REMOTE` | `false` | Allow non-loopback callers to reach [`POST /v1/compress`](#post-v1compress) and `POST /v1/usage`. Required to run Headroom as a remote gateway/sidecar; without it remote callers get `404`. |
|
||||
| `HEADROOM_OFFLINE` | `false` | Air-gap mode: refuse every connection Headroom itself initiates — telemetry, update checks, license reporting, model/tokenizer/binary/dataset downloads, remote Kompress, OTLP and Langfuse export, Copilot auth, the subscription pollers, the OpenAI embedders, Headroom Cloud compression and the TLS diagnostics (`headroom doctor --network` reports them as skipped). Four things still work on purpose: forwarding your own requests to the upstream you configured, operator-configured local endpoints (the Ollama embedder), loopback health probes, and paths an `is_offline()` check already disables. Refusals surface as messages, not tracebacks. See the air-gap notes in `docs/metrics-technical-guide.md`. |
|
||||
| `HEADROOM_OFFLINE` | `false` | Air-gap mode: refuse every connection Headroom itself initiates — telemetry, update checks, license reporting, model/tokenizer/binary/dataset downloads, litellm's pricing-table refresh, CrewAI's install tracking, remote Kompress, OTLP and Langfuse export, Copilot auth, the subscription pollers, the OpenAI embedders, Headroom Cloud compression and the TLS diagnostics (`headroom doctor --network` reports them as skipped). Four things still work on purpose: forwarding your own requests to the upstream you configured, operator-configured local endpoints (the Ollama embedder), loopback health probes, and paths an `is_offline()` check already disables. Refusals surface as messages, not tracebacks. See the air-gap notes in `docs/metrics-technical-guide.md`. |
|
||||
| `HEADROOM_LICENSE` | unset | Licence token, read by core and every licensed extension. `HEADROOM_LICENSE_KEY` is a deprecated alias for one release and logs a warning. A licence on its own sends nothing to Headroom. |
|
||||
| `HEADROOM_USAGE_REPORTING` | `false` | Set `1` to let the proxy validate the licence and post aggregate usage counts (no content) to the Headroom cloud. Off unless set; `HEADROOM_OFFLINE` still overrides it. |
|
||||
| `--stateless` / `HEADROOM_STATELESS` | `false` | Keep all state in memory; no filesystem writes (disables logs, memory, TOIN). |
|
||||
@@ -620,7 +653,7 @@ Keep carrying both yourself and send them upstream unchanged. Two consequences w
|
||||
| `transforms_applied` | array | Transform labels that ran. |
|
||||
| `transforms_summary` | object | Per-transform counts. |
|
||||
| `ccr_hashes` | array | Retrieval hashes for markers inserted (empty unless `mode: "ccr"`). |
|
||||
| `session` | object | [Session mode](#session-mode) only: `{ "id", "frozen_message_count", "cached_prefix_replayed" }`. |
|
||||
| `session` | object | [Session mode](#session-mode) only: `{ "id", "frozen_message_count", "cached_prefix_replayed" }`, described there. |
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -709,15 +742,27 @@ Pass `config.session_id` and Headroom keeps the conversation's replay state itse
|
||||
The response gains a `session` object:
|
||||
|
||||
```json
|
||||
"session": { "id": "conv-8f1c", "frozen_message_count": 12, "cached_prefix_replayed": true }
|
||||
"session": { "id": "conv-8f1c", "frozen_message_count": 12, "cached_prefix_replayed": false }
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| `id` | string | The session id this turn ran under: `config.session_id` as sent, or the `x-headroom-session-id` header when `HEADROOM_COMPRESS_SESSION_FROM_HEADER=1` and `config.session_id` is absent. |
|
||||
| `frozen_message_count` | integer | How many leading messages the pipeline was told not to recompress this turn. Headroom counts the leading run it can replay from the session's compression cache: plain messages always count, a tool result counts only once its content is in that cache, and the last message never counts. An explicit `config.frozen_message_count` wins when larger. It is derived from Headroom's own state, not from the provider, and it can be non-zero on a first turn. |
|
||||
| `cached_prefix_replayed` | boolean | `true` when the pipeline's output for some leading messages differed from what this endpoint returned for the session last turn, and Headroom overwrote those messages with last turn's bytes. `false` when nothing was overwritten: when the serving process holds no previous turn for the session (a first turn, expired state, or a replica that never served or loaded it), when the pipeline already produced last turn's bytes (the usual case), or when the replay was skipped as unsafe (this turn's messages do not line up with last turn's, or the replay would be larger than the pipeline's output). So `false` does not mean the returned prefix matches last turn's. |
|
||||
|
||||
<Callout type="warning" title="cached_prefix_replayed is not a prompt-cache hit">
|
||||
`cached_prefix_replayed` reports Headroom's own repair step. It says nothing about whether the provider served the prefix from its prompt cache. `false` is the normal value on a healthy session, and it is also what a turn that changed the prefix returns when there was nothing to replay. Read cache hits and misses from the provider's usage (`cache_read_input_tokens`, `prompt_tokens_details.cached_tokens`).
|
||||
</Callout>
|
||||
|
||||
What differs from the stateless contract:
|
||||
|
||||
- **Forward the returned messages verbatim.** They are what the next turn replays.
|
||||
- **`compress_user_messages` is refused** (`400`). User-message rewrites are not byte-replayable across turns, so they would bust the prefix later.
|
||||
- **Timeouts and busy sessions are a `503`, never fail-open.** Handing back originals would leave the caller forwarding bytes the replay state does not know about, so a compression timeout answers `503` with `error.type = "compression_timeout"`; retry the turn and it lands on consistent state. Turns for one session are serialized under a per-session lock, and a concurrent turn for the same session that waits more than 10 seconds gets the same `503`.
|
||||
- **State is in-process.** The replay cache lives for `HEADROOM_COMPRESSION_CACHE_TTL_SECONDS` of idle time (3900 by default, floor 600); the tracker's usage state expires after 10 idle minutes. Multi-process deployments (gunicorn workers, replicas) must pin a session to one process — hash the upstream on the session id — or replay silently misses.
|
||||
- **State is in-process by default.** The replay cache lives for `HEADROOM_COMPRESSION_CACHE_TTL_SECONDS` of idle time (3900 by default, floor 600); the tracker's usage state expires after 10 idle minutes. Without a shared store, multi-process deployments (gunicorn workers, replicas) must pin a session to one process — hash the upstream on the session id — or replay silently misses.
|
||||
- **`HEADROOM_COMPRESS_SESSION_STORE=redis://...` shares sessions across replicas.** Every replica also keeps each session's tracker in Redis, so any replica can serve the session's next turn and its `POST /v1/usage`. It needs the `redis` extra, which every Docker image includes. It also selects the Redis CCR store unless `HEADROOM_CCR_BACKEND` names another, so CCR markers resolve on any replica. Two limits remain. The per-session lock is per process: two concurrent turns of one session on two replicas both run, the first write wins (compare-and-set), and the next turn continues from the winner. Gateway-mode pending turns stay in-process, so `POST /v1/compress/response` must reach the replica that answered the request half; re-drive therefore still needs real affinity (`gateway.session_affinity`).
|
||||
- **An unreachable Redis does not fail turns.** A Redis error is a miss: the replica serves from its own memory, logs one `WARNING` when a kind of call (read, write) starts failing and an `INFO` when it works again, and skips Redis for 5 seconds after a connection error (each command times out after 1 second). The cost is the sharing. A replica with no local state for the session recompresses the history, which is slower, and the prefix it returns can differ from last turn's, which is a provider prompt-cache miss. `cached_prefix_replayed` stays `false` on those turns. A Redis that comes back empty is refilled as each session's next turn writes it whole. Run Redis with high availability if prompt-cache hits matter.
|
||||
- `HEADROOM_COMPRESS_SESSION_FROM_HEADER=1` lets the `x-headroom-session-id` header stand in for `config.session_id`. Off by default: gateways commonly stamp that header on all traffic, and a value shared across conversations (Claude Code subagents do this) would blend them into one replay state.
|
||||
|
||||
**Relaying provider usage: `POST /v1/usage`.** Session mode never sees the provider's response, so cache-hit attribution and savings accounting for the session come from this optional relay (same exposure rules as `/v1/compress`). Post the provider's `usage` block under the session id:
|
||||
@@ -747,7 +792,7 @@ The rule behind it is the proxy's own **no shrink without reload**, moved to the
|
||||
| --- | --- | --- | --- |
|
||||
| `can_redrive` | boolean | `false` | The gateway can call the provider again with a request Headroom hands it and post the result back. Unlocks re-driving turn hooks and, with `config.mode: "ccr"`, in-band CCR retrieval. Send `false` for streaming requests. |
|
||||
| `can_relay_response` | boolean | `false` | The gateway will post the provider's status and usage to `/v1/compress/response` after every turn. |
|
||||
| `session_affinity` | boolean | `true` | The gateway pins this session to one Headroom replica. Pending turns are in-process state, so `false` disables re-driving for the turn even when `can_redrive` is set. |
|
||||
| `session_affinity` | boolean | `true` | The gateway pins this session to one Headroom replica. Pending turns are in-process state, so `false` disables re-driving for the turn even when `can_redrive` is set. `HEADROOM_COMPRESS_SESSION_STORE` shares replay state, not pending turns, so it does not lift this. |
|
||||
| `plugin_version` | string | unset | Diagnostics only. |
|
||||
| `request_headers` | object | `{}` | The client's request headers the gateway is willing to hand over, as lowercase name → string value. Only `anthropic-beta` is read today: when a turn hook asks for an `anthropic-beta` token, the client's tokens go first in the returned `headers`; every other name is ignored, so a gateway may pass its whole header map. A non-object block or a non-string value is a `400`. Never forwarded anywhere by Headroom. |
|
||||
|
||||
@@ -792,6 +837,13 @@ The response keeps every field above and adds six:
|
||||
|
||||
Fail-open answers (bypass header, empty `messages`, stateless timeout) carry the same six keys with your original body, `obligations: []` and `headers: {}`.
|
||||
|
||||
**Savings on a gateway answer.** The token counts follow the proxy path, so a gateway can report the same figure `/stats` does. When compaction shortened `tools`, `tokens_before` and `tokens_after` also count the tool definitions before and after it, so `tokens_saved` includes the compaction saving. Two more fields carry the tool definitions kept out of the context, which no message count sees; both are absent on fail-open answers:
|
||||
|
||||
| Field | Description |
|
||||
| --- | --- |
|
||||
| `tool_tokens_saved` | Tool-search deferral plus tools a turn hook removed, net (`tool_search_deferred_tokens` after reconciliation + `turn_hook_tools_saved_tokens` after netting against message growth). `tokens_saved + tool_tokens_saved` is the `/stats` headline for the turn. |
|
||||
| `tool_tokens_deferred` | The deferral share of `tool_tokens_saved`. `/stats` books it as `estimated`: a deferred tool the model loads later is billed after all. Subtract it for a figure of measured savings only. |
|
||||
|
||||
When `relay_usage` is owed, the turn's `/stats` record is deferred until the response half arrives with billed input and output, cache counts, provider status and latency; a turn that never comes back is recorded as-is when it expires. Pending turns live `HEADROOM_GATEWAY_TURN_TTL_SECONDS` (default `120`, refreshed on every `redrive`), at most `HEADROOM_GATEWAY_MAX_PENDING_TURNS` at a time (default `10000`, oldest evicted first), and a turn may re-drive at most `HEADROOM_GATEWAY_MAX_REDRIVES` times (default `8`).
|
||||
|
||||
**`config.mode: "ccr"` on this contract.** When markers were inserted and re-driving is allowed, Headroom injects the `headroom_retrieve` tool into `body.tools` (`ccr_tool_injected` in `transforms_applied`), adds the `redrive` obligation, and the response half answers the model's retrieval calls itself — the gateway just keeps re-driving. Without `can_redrive`, `ccr` mode behaves as it does today: the markers are yours to resolve.
|
||||
|
||||
@@ -284,6 +284,8 @@ accept arbitrary environment variables — writes are restricted to a hardcoded
|
||||
| `HEADROOM_INTERCEPT_READ_MIN_CHARS` | ast-grep read-interception threshold |
|
||||
| `HEADROOM_VERIFY_TRUNCATION_ON_DISK` | Verify ast-grep Read truncation against disk when no client banner is found. Always returns `UNKNOWN` on Windows, where `dir_fd` / `O_NOFOLLOW` support is unavailable. |
|
||||
| `HEADROOM_VERIFY_TRUNCATION_MAX_BYTES` | Max on-disk file size (bytes) the disk-verify fallback will read |
|
||||
| `HEADROOM_DEFERRED_TOOL_AFFINITY` | Keep `defer_loading` tools out of the Anthropic prefix-tracker lineage key (default on; `0` counts them again) |
|
||||
| `HEADROOM_WEB_SEARCH_HISTORY` | Drop `web_search_call` history from a Responses request that declares no web_search tool (default on; `0` disables) |
|
||||
| `HEADROOM_BUFFERED_UPSTREAM_STREAM` | Send buffered CCR requests (and their continuations) upstream as `stream: true` and fold the reply (default on; `0` sends `stream: false`) |
|
||||
|
||||
Keys outside this list are ignored, and `/admin/upstream` is read-only — there is no
|
||||
|
||||
+11
-19
@@ -1,27 +1,19 @@
|
||||
---
|
||||
title: Headroom for Teams
|
||||
description: Headroom Enterprise for engineering teams — more savings, automatic model routing, attack removal, SSO and an org-wide savings dashboard. 3 months free with a 12-month plan.
|
||||
description: Not seeing the savings you want? Headroom Enterprise adds more cost savings, tokens secured, on premise deployment and deep attribution. Talk to us.
|
||||
---
|
||||
|
||||
Headroom OSS is built for one developer on one laptop. Headroom Enterprise is built
|
||||
for the whole team.
|
||||
**Not seeing the savings you want?** Headroom OSS is a framework. It was built to show
|
||||
what's possible on one developer's laptop, so it saves less than it could. We are
|
||||
building bigger savings for teams and enterprises in Headroom Enterprise, which adds:
|
||||
|
||||
| | Open source | Enterprise |
|
||||
|---|---|---|
|
||||
| Savings | Compression, plus tool search on Anthropic requests (on by default) | Also: tool search for every model, harness tuning, extra compressors |
|
||||
| Model routing | Rule-based and opt-in: turn it on with `HEADROOM_MODEL_ROUTER_ENABLED=1` and write the rules in [`HEADROOM_MODEL_ROUTES`](/docs/configuration#cost-aware-model-routing) | Automatic: a cheaper model per request when quality allows, with a shadow mode that shows the savings before you turn it on |
|
||||
| Security | — | Detect and strip prompt injection and risky tool calls |
|
||||
| Rollout | Per laptop | Managed or in your VPC, SSO, central config, org-wide savings |
|
||||
| Support | GitHub, Discord | Dedicated engineers, onboarding, priority response |
|
||||
- More cost savings
|
||||
- Tokens secured
|
||||
- On premise deployment
|
||||
- Deep attribution
|
||||
- And many more features
|
||||
|
||||
## 3 months free
|
||||
|
||||
Companies that sign a 12-month Enterprise plan get their first 3 months free. One
|
||||
perk per company.
|
||||
|
||||
**[Claim 3 months free →](https://headroom-perks.vercel.app/?source=github&utm_source=docs&utm_medium=teams-page)**
|
||||
|
||||
Prefer to talk first? Email [hello@headroomlabs.ai](mailto:hello@headroomlabs.ai)
|
||||
with your stack and rough monthly LLM spend.
|
||||
If you're a team or an enterprise, **talk to us**:
|
||||
[hello@headroomlabs.ai](mailto:hello@headroomlabs.ai) · [headroomlabs.ai](https://headroomlabs.ai)
|
||||
|
||||
Everything in the open-source repo stays open source under Apache 2.0.
|
||||
|
||||
@@ -93,6 +93,11 @@ print(f"Compression ratio: {result.compression_ratio:.1%}")
|
||||
- Verbose success output
|
||||
- Repeated patterns
|
||||
|
||||
Omission markers count `ERROR`, `FAIL`, `WARN`, and `INFO` levels only among the dropped lines, not the full input. An error retained in the compressed output is therefore not advertised as omitted. Debug, trace, and unclassified lines are not listed in the level breakdown.
|
||||
When only debug, trace, or unclassified lines are dropped, the marker is simply `[N lines omitted]`, without a severity breakdown.
|
||||
|
||||
`result.stats` continues to report whole-input totals; the marker's narrower counts do not change those statistics. CCR still retains the exact original log when enabled.
|
||||
|
||||
## DiffCompressor
|
||||
|
||||
Compresses unified diffs while keeping the actual changes and enough context to understand them.
|
||||
|
||||
@@ -364,6 +364,28 @@ pipx install --python python3.13 "headroom-ai[all]==0.21.4"
|
||||
If you already have Headroom installed under `pipx`, uninstall it first or
|
||||
reinstall it with the supported interpreter.
|
||||
|
||||
### Docker image frozen at an old version
|
||||
|
||||
**Symptom**: `headroom --version` inside the running container reports an old
|
||||
release (e.g. `0.27.0`) no matter how recently you pulled the image.
|
||||
|
||||
**Cause**: the project moved from the `chopratejas` personal account to the
|
||||
`headroomlabs-ai` org, and GHCR does not redirect packages across that move.
|
||||
`ghcr.io/chopratejas/headroom` still exists but stopped receiving pushes at
|
||||
that point, so it is permanently frozen at the last version built under the
|
||||
old namespace. A `HEADROOM_DOCKER_IMAGE` override, an install script, or a
|
||||
tutorial saved from before the move can still point there.
|
||||
|
||||
Pull the current image instead:
|
||||
|
||||
```bash
|
||||
docker pull ghcr.io/headroomlabs-ai/headroom:latest
|
||||
```
|
||||
|
||||
If you set `HEADROOM_DOCKER_IMAGE` yourself, check it does not still read
|
||||
`ghcr.io/chopratejas/headroom`. See [Docker install](/docs/docker-install)
|
||||
for the current default and the available tags.
|
||||
|
||||
### pip install fails with C++ compilation error
|
||||
|
||||
**Symptom**: `RuntimeError: Unsupported compiler -- at least C++11 support is needed!`
|
||||
|
||||
@@ -117,8 +117,20 @@ snapshot in response metadata (for example, a request for `gpt-5.5` returned
|
||||
Copilot plan and organization policy.
|
||||
|
||||
The proxy supports the native Copilot OpenAI-compatible request paths used by
|
||||
GPT and Claude models. Headroom's upstream auth hook replaces local client auth
|
||||
with the current Copilot API token on every Copilot-bound request.
|
||||
GPT and Claude models. Inline completions retain the editor's own `ghu_` OAuth
|
||||
bearer and native integration metadata on the completions host, including an
|
||||
operator-configured gateway with a base-path prefix. Headroom does not replace
|
||||
that editor identity with the proxy operator's Copilot seat or add chat-specific
|
||||
headers. Chat and Responses retain their existing managed Copilot API-token
|
||||
policy; a raw OAuth bearer on those routes does not gain the inline exception.
|
||||
|
||||
A configured base path is removed only for the same scheme and authority, at a
|
||||
complete path-segment boundary. Other recognized completions endpoints keep
|
||||
their native `/v1` paths.
|
||||
|
||||
The inline auth branch logs only the credential kind (`ghu_***`), not the
|
||||
editor's OAuth token. Case variants of unrelated provider API-key headers are
|
||||
removed before any Copilot auth branch forwards the request.
|
||||
|
||||
## Stop and undo
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ Verify with `curl -s localhost:8787/stats | jq .otel`.
|
||||
|
||||
**Multi-tenant labels:** `register_otel_metric_attribute_provider()` adds request-scoped attributes (tenant, team, cost centre) to every OTel datapoint. Max 16 attributes, 256 chars each.
|
||||
|
||||
**Air-gapped deployments:** `HEADROOM_OFFLINE=1` refuses every connection Headroom itself decides to make to a destination Headroom itself chose. That is the whole list, not a sample: the anonymous usage beacon (which is **on by default**), the update check, the license/usage reporter, **OTLP metric and Langfuse trace export**, HuggingFace / Kompress / fastembed model and tokenizer downloads (Python and Rust), the remote Kompress endpoint, the `headroom install` release-binary and codebase-memory-mcp downloads, the BFCL eval-dataset fetch and the provider SDK clients the eval harness drives, GitHub Copilot device-flow auth and token exchange, the Anthropic / Codex / Copilot subscription pollers, the OpenAI embedders, the Headroom Cloud compression modes in the ASGI and LiteLLM integrations, and the TLS diagnostics (`headroom doctor --network` endpoint checks and the certificate-chain re-probe after an upstream TLS failure).
|
||||
**Air-gapped deployments:** `HEADROOM_OFFLINE=1` refuses every connection Headroom itself decides to make to a destination Headroom itself chose. That is the whole list, not a sample: the anonymous usage beacon (which is **on by default**), the update check, the license/usage reporter, **OTLP metric and Langfuse trace export**, HuggingFace / Kompress / fastembed model and tokenizer downloads (Python and Rust), the remote Kompress endpoint, the `headroom install` release-binary and codebase-memory-mcp downloads, litellm's import-time pricing-table refresh, CrewAI's import-time install tracking, the BFCL eval-dataset fetch and the provider SDK clients the eval harness drives, GitHub Copilot device-flow auth and token exchange, the Anthropic / Codex / Copilot subscription pollers, the OpenAI embedders, the Headroom Cloud compression modes in the ASGI and LiteLLM integrations, and the TLS diagnostics (`headroom doctor --network` endpoint checks and the certificate-chain re-probe after an upstream TLS failure).
|
||||
|
||||
Four things are deliberately still allowed, and they are the complete set of exceptions:
|
||||
|
||||
@@ -279,6 +279,8 @@ Four things are deliberately still allowed, and they are the complete set of exc
|
||||
|
||||
Those four are enumerated with written reasons in `_EGRESS_ALLOWLIST` in `tests/test_offline_egress_chokepoint.py`, which fails the build if a new egress path appears that is neither guarded nor one of them. There is no category for "known violation": a path that can dial the internet with the flag set is a bug. A refusal reaches you as a message — a Click error on the CLI, a named "model unavailable" from a model loader, a logged line from a background poller — never as a traceback and never as a silent degradation. Enforcing the same policy at the network layer as well is still good practice; it is no longer the only thing standing between you and Headroom-initiated egress.
|
||||
|
||||
litellm's pricing-table refresh is refused by setting `LITELLM_LOCAL_MODEL_COST_MAP=True` before litellm is imported, so it holds only when Headroom is the first thing in the process to import litellm. A host that imports litellm before Headroom, such as a LiteLLM proxy loading the Headroom callback, has made that fetch already and must set the variable itself. Offline, cost and savings figures use the pricing table bundled with the installed litellm release, so a model released after it prices as unknown.
|
||||
|
||||
OTLP export is refused loudly: with `HEADROOM_OFFLINE=1` set, `HEADROOM_OTEL_METRICS_ENABLED=1` plus the default `otlp_http` exporter makes the proxy exit 78 at startup with an explanation, rather than quietly dropping metrics. There is no exemption for a collector that looks local — an in-cluster address is not reliably distinguishable from an internet one. For metrics under an air-gap, either scrape `localhost:8787/metrics` or set `HEADROOM_OTEL_METRICS_EXPORTER=console`, both of which stay on-box. `HEADROOM_KOMPRESS_ENDPOINT` and `HEADROOM_LANGFUSE_ENABLED` are refused the same way, for the same reason.
|
||||
|
||||
---
|
||||
|
||||
Generated
+241
-208
@@ -13,29 +13,29 @@
|
||||
"class-variance-authority": "0.7.1",
|
||||
"clsx": "2.1.1",
|
||||
"dotted-map": "^3.1.0",
|
||||
"fumadocs-core": "16.17.1",
|
||||
"fumadocs-mdx": "15.4.7",
|
||||
"fumadocs-twoslash": "^4.0.2",
|
||||
"fumadocs-typescript": "^5.5.1",
|
||||
"fumadocs-ui": "16.17.1",
|
||||
"lucide-react": "^1.48.0",
|
||||
"next": "^16.4.0",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0",
|
||||
"fumadocs-core": "16.17.7",
|
||||
"fumadocs-mdx": "15.4.9",
|
||||
"fumadocs-twoslash": "^4.0.3",
|
||||
"fumadocs-typescript": "^5.5.2",
|
||||
"fumadocs-ui": "16.17.7",
|
||||
"lucide-react": "^1.61.0",
|
||||
"next": "^16.4.3",
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1",
|
||||
"recharts": "^3.10.1",
|
||||
"tailwind-merge": "^3.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ai-sdk/openai": "^4.0.91",
|
||||
"@anthropic-ai/sdk": "^0.133.0",
|
||||
"@ai-sdk/openai": "^4.0.99",
|
||||
"@anthropic-ai/sdk": "^0.137.0",
|
||||
"@tailwindcss/postcss": "^4.3.3",
|
||||
"@types/mdx": "^2.0.14",
|
||||
"@types/node": "^26.6.5",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"ai": "7.0.137",
|
||||
"openai": "^7.32.0",
|
||||
"postcss": "^8.5.29",
|
||||
"ai": "7.0.148",
|
||||
"openai": "^7.39.0",
|
||||
"postcss": "^8.5.31",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"typescript": "^7.0.2"
|
||||
},
|
||||
@@ -44,14 +44,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@ai-sdk/gateway": {
|
||||
"version": "4.0.110",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-4.0.110.tgz",
|
||||
"integrity": "sha512-5IwnOR6v7KC+D9eddUqsCobXl/FbLUVb2LaQc/uyuQdpP3/n9s0YLc9zl4/W3IS/R2pjHrqUfCzEAeOu7bFLoQ==",
|
||||
"version": "4.0.121",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-4.0.121.tgz",
|
||||
"integrity": "sha512-cPNXvQ4B5OkmVAm98Dxe1fHdMthyqqqAG0HJx3D92NUa9FpcvkNxdAqiuZdeAhNAodFb9lBrslzzzEwxuVS53A==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@ai-sdk/provider": "4.0.26",
|
||||
"@ai-sdk/provider-utils": "5.0.58",
|
||||
"@ai-sdk/provider": "4.0.31",
|
||||
"@ai-sdk/provider-utils": "5.0.65",
|
||||
"@vercel/oidc": "3.2.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -62,14 +62,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@ai-sdk/openai": {
|
||||
"version": "4.0.91",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/openai/-/openai-4.0.91.tgz",
|
||||
"integrity": "sha512-Nk382R6us0GNxI1cGJUXMryz1XHpyrmC3K/Rmqdx9tIsqAlc7UtuO/hC9dd31F41w8uzoS362HJSDXgAI7zKbA==",
|
||||
"version": "4.0.99",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/openai/-/openai-4.0.99.tgz",
|
||||
"integrity": "sha512-XRHUiXgxhVEe0smSp537lzCqMsOVg6jvGTWDbTZeGMTc+iHeOwgHgZMFBvOiNWXZ8n125Jta72m+64PtU1WNJA==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@ai-sdk/provider": "4.0.26",
|
||||
"@ai-sdk/provider-utils": "5.0.58"
|
||||
"@ai-sdk/provider": "4.0.31",
|
||||
"@ai-sdk/provider-utils": "5.0.65"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -79,9 +79,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@ai-sdk/provider": {
|
||||
"version": "4.0.26",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-4.0.26.tgz",
|
||||
"integrity": "sha512-BZ443uBEq6HuMA+Z4b7Hpm65GpZSo7pWqnYqpf/7tAO3C48JbtvAhOE2JnODFj+jodsZzfRHkAyQb64xuD2tZQ==",
|
||||
"version": "4.0.31",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-4.0.31.tgz",
|
||||
"integrity": "sha512-3wJnwVTFg8SwOyoZCv+ov7Re2GB+7IQnU5a5MYJACrtiWDDUHgqTBeeesq2MB2ddgojzL8hgWleltwpAgtUqfg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
@@ -92,13 +92,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@ai-sdk/provider-utils": {
|
||||
"version": "5.0.58",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-5.0.58.tgz",
|
||||
"integrity": "sha512-iXSwKR/7LpHzAlyrUl+bTinwzmZ3Nmup1viwPisM5Gn5cogRdIG4rV9w1ZDuKFcrXyu/AeVs42E1CX/0aNwrfQ==",
|
||||
"version": "5.0.65",
|
||||
"resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-5.0.65.tgz",
|
||||
"integrity": "sha512-LCugcsP8oWmdeI3BASf4Fuo1wiC6Qx0YrefFssl7n12s+LV4DNi5RdwWQrtrB4oek3GGNQRN/h/NSwVZM2eHKw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@ai-sdk/provider": "4.0.26",
|
||||
"@ai-sdk/provider": "4.0.31",
|
||||
"@standard-schema/spec": "^1.1.0",
|
||||
"@workflow/serde": "4.1.0",
|
||||
"eventsource-parser": "^3.0.8",
|
||||
@@ -123,12 +123,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@anthropic-ai/sdk": {
|
||||
"version": "0.133.0",
|
||||
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.133.0.tgz",
|
||||
"integrity": "sha512-jlqUN8p8ESTJj+GJnA4KjzbEfF1waEoGzRT8jwytlYGFFgv+/DUQOxlYGvYw10UzhD1kwLqYzxvA3FrTB2YWuQ==",
|
||||
"version": "0.137.0",
|
||||
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.137.0.tgz",
|
||||
"integrity": "sha512-YpEnbPz8kWF1BWthwUCnRhci7OvDLSUO8NFKoevoPkjNkK9CJeibZITgxr9vhqOP8Le61e5tNDHFTxw1dc6Png==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.4.1",
|
||||
"json-schema-to-ts": "^3.1.1",
|
||||
"standardwebhooks": "^1.0.0"
|
||||
},
|
||||
@@ -154,16 +155,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@base-ui/react": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@base-ui/react/-/react-1.8.0.tgz",
|
||||
"integrity": "sha512-P0/1sxo6SBVZOklKMIedvTWqw2s2IQzi9x5bIVsXu980cuSOD4NeuRSs+/L7LZQfDkZP/uRZyGPyfFl/B1oH+Q==",
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@base-ui/react/-/react-1.9.0.tgz",
|
||||
"integrity": "sha512-S8CSYosASBKtpL8SWUfS78rFElfLijiCgA7oHOK22jCJ95FULsYyKwBNFOgudt0RA+/7yNc7F81bOvQnRgbBiQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.29.7",
|
||||
"@base-ui/utils": "0.4.0",
|
||||
"@babel/runtime": "^7.29.7 || ^8.0.0",
|
||||
"@base-ui/utils": "0.5.0",
|
||||
"@floating-ui/react-dom": "^2.1.9",
|
||||
"@floating-ui/utils": "^0.2.12",
|
||||
"use-sync-external-store": "^1.6.0"
|
||||
"use-sync-external-store": "^1.7.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
@@ -192,15 +193,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@base-ui/utils": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@base-ui/utils/-/utils-0.4.0.tgz",
|
||||
"integrity": "sha512-bO9fz25kKtPf+aZVyfQrC0PDmJdmVni31W2hCS5/Owb+inwdIL3XU26pCPRPlt4LSxZrBgLwubXQXQlKaFEZzw==",
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@base-ui/utils/-/utils-0.5.0.tgz",
|
||||
"integrity": "sha512-dYGGcEttjkYiMoa5nHm8vLaJ2UcuTWxo3BFAwOYXeRg/q7UVVvA6cacEIXEs3FgBfK1CGtW1ptElqs7wsx+t9A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.29.7",
|
||||
"@babel/runtime": "^7.29.7 || ^8.0.0",
|
||||
"@floating-ui/utils": "^0.2.12",
|
||||
"reselect": "^5.2.0",
|
||||
"use-sync-external-store": "^1.6.0"
|
||||
"reselect": "^5.3.0",
|
||||
"use-sync-external-store": "^1.7.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^17 || ^18 || ^19",
|
||||
@@ -213,6 +214,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@base-ui/utils/node_modules/reselect": {
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/reselect/-/reselect-5.3.0.tgz",
|
||||
"integrity": "sha512-XGoLeRAVzUTcJ1qkxPQhDJyIZ5d6zzZD9nT7AEZOaaU9UbWclhycElmhO+VD5bFeLuzhPBaOV2oXC8uG35ZSpg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.11.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
|
||||
@@ -694,9 +701,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@fumadocs/tailwind": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@fumadocs/tailwind/-/tailwind-0.1.3.tgz",
|
||||
"integrity": "sha512-gDgLbTnY5b+nogCg2y/pP7GsaQS4Zt/0vftJAu07Wy7Wsb3/lwd9GwoGqccCnPElTFwMG+pPwrmHXBPexEfE8A==",
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@fumadocs/tailwind/-/tailwind-0.1.4.tgz",
|
||||
"integrity": "sha512-1LAmuroJ6TJoQodyODRhMC9ThAkfrV2N5vZjaj4KKs+dpF2bs0d/2z0604iMKBLv2BKstR7zE9TUa/L0pxGnhA==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"tailwindcss": "^4.0.0"
|
||||
@@ -1347,15 +1354,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/env": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.0.tgz",
|
||||
"integrity": "sha512-pyLlT5oafGlX8X7xjgGNXz5dNIDSxREm+qD6i9VLSZiZFopA/XWl8NM/KPmLx/8EG/++c49iid3gNWSQW1+2dQ==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.3.tgz",
|
||||
"integrity": "sha512-a7tz1QCcWWkwC/rPJcPMJk/UNRu9CFhDd3OHYE5hddbJrs8BqRTalxI6GlKCWEGzRLHN+S/B7a4PAHCtm25aBQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@next/swc-darwin-arm64": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.0.tgz",
|
||||
"integrity": "sha512-yyZ+9MgViAKLLb5l1gPBGjRwnq3teNLb5Zx6JEw8LzNSTjlsnp+baUHFxTgl7PpjCmKf48VQfyipG1eBflb48Q==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.3.tgz",
|
||||
"integrity": "sha512-4yq5EXBt+VDtAZwTyfijaFp5D2C5oz3Ikw5a2kiX2K9nw72vrZX2q5UuAlkPtUMO1tQz6JTKpaKWjS7OOefTDQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -1369,9 +1376,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-darwin-x64": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.0.tgz",
|
||||
"integrity": "sha512-RePEEejEj1Auf5s9qEcG0JbcDP3ceNUS/ofNX8AhxzgIjTVlZIHMatlp16YplcSMpsVo/ZMQHJTjbMYJznjGUg==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.3.tgz",
|
||||
"integrity": "sha512-1Rvkn/LUhnEF8WxnRkOrqGhbwXui1bkWFxONKIbN+r7C+9KHDSZ+iUoj4CzymVMWUyZIyx9szcb9+kbKhD500A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -1385,9 +1392,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-arm64-gnu": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.0.tgz",
|
||||
"integrity": "sha512-HhsyCqd+NpmvDDVY/LqkAN24f+QVvXh3ie+PfcwKinWL2Mu826JymQxJXGjAIfmJ4VlHjp4Pe/nZtXtUoEMAqw==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.3.tgz",
|
||||
"integrity": "sha512-dCKpXErGg3abUM6t5JTJV/ottVBTStJB5lRJTbgdUdQaQ+jNHiK56Hsc0YAEg/rinSh42hYG3HWiYmEMdilnxg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -1404,9 +1411,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-arm64-musl": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.0.tgz",
|
||||
"integrity": "sha512-sN9Pf+Zh+RpZAOmbR7d8KAA8T61CVhawtbEJ2Bk6QrRzx6Z/6haaF4UiwBzytM96GRRRWZh9/WALIEO3npMamA==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.3.tgz",
|
||||
"integrity": "sha512-WwYbhWkhYBvBtib1K4W0kL8MW2snBD2A5b3SN4vPpqalZbZs5+bQ1yzAdepVoOqrFfEW3dmREy4Zs1MrWcrFbw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -1423,9 +1430,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-x64-gnu": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.0.tgz",
|
||||
"integrity": "sha512-D5M5xLWQVd1CvR+L7BickM1weRfmM41x3L1NWcnKY/oyJJqr1qwaCgmu3dMAhLBOMdZwSuDCRV6DJRRpiUkbDQ==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.3.tgz",
|
||||
"integrity": "sha512-QymWvfUwDEC5/lpJOsxX5VAbyoR2D13+2Jsjz4be7gT4LPqEgdpkeLIR/HFfCLgKzoMhpJbp6I/JnogyNZHcaA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -1442,9 +1449,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-linux-x64-musl": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.0.tgz",
|
||||
"integrity": "sha512-8d5WLS6a9YalqpOgXdlbvonFu+sIgjA+CO6tGzetrpPVcUL56foa7B7664h41rAlbLi5fJwK4vWji3zf4QDy+w==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.3.tgz",
|
||||
"integrity": "sha512-Vmjd9D7DpA4Vv3cUlr82QWgJD/BQZmns801vtC5VWHg6jCIA4a5vMKpQnfrM2pyCrp2eV0ENdUg4PlN3bAc2Yw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -1461,9 +1468,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-arm64-msvc": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.0.tgz",
|
||||
"integrity": "sha512-sQuOIiW3snb48UwrBcDMvFA/u03qtw2LeuSIxFIQ9AJuW9UG/4Ddsfo+eV73PnZwBhyncMtsKVh7PrzMol2/fA==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.3.tgz",
|
||||
"integrity": "sha512-lG1pPdPLk7gTyGb00n5JIMLdBJgjb+UEhSdZvFbhUMg0DyC6z4B7RnpSKF9VCd4imkLObVbXOFA0kFCpw7yFow==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -1477,9 +1484,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/swc-win32-x64-msvc": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.0.tgz",
|
||||
"integrity": "sha512-6/33lCuxpdHUy27RegyGM/5uTpF7YZd3UR4D0gpkOA/tWY5YR7msbQjqPgCZmSmxrrTLGCXYA4A8vT2H5DPGTQ==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.3.tgz",
|
||||
"integrity": "sha512-NmQC9RkJdnPXRaMxtkCzobB3teVjqF33oSOnwDfi+XYGWWYpt+xlGK3mtktSKLbdjwaWbJu2OkkMiRFGUUncKg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -1492,6 +1499,16 @@
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@opentelemetry/api": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.10.0.tgz",
|
||||
"integrity": "sha512-lMkyes8iHrG+mk6WH7X70MdCLI2RS0FwNBY1PyQ8UemaijE2m5mv5A0Niy3HtbYTFrgkUEQjFMXmSAk2hQDuPQ==",
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/number": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.3.tgz",
|
||||
@@ -3310,9 +3327,9 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@yuku-core/binding-android-arm64": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-android-arm64/-/binding-android-arm64-0.17.0.tgz",
|
||||
"integrity": "sha512-Uge3U7s9vdCcYb9IiIWBIQmGEttlvWkvWYb9Qu6iUNS2IhAu4/D/g4ucbEmjemkflWYGpWsKZlX+JxcacIlR+g==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-android-arm64/-/binding-android-arm64-0.19.0.tgz",
|
||||
"integrity": "sha512-wdL2XmTiZixAOaHk9Z0JJZ8u9Qm8d333Zjpc6gaxXFX+UR5BlsfxZ7a2+2Rm71pamppsPYGUGFq2oVLbh6DISw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -3323,9 +3340,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-darwin-arm64": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-darwin-arm64/-/binding-darwin-arm64-0.17.0.tgz",
|
||||
"integrity": "sha512-jpWhRhfsAFUKXR/dUFoA9NgHeeIl5Yn0hmBEDt4QUEmnYuYZSDXeKQeSCazvIvfzbI0lyIkFSf5/TQeRPwiNuA==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-darwin-arm64/-/binding-darwin-arm64-0.19.0.tgz",
|
||||
"integrity": "sha512-7sNJa6XJhyetnTy64jw3NEi4YgUcezHk1G5GH9FSvXAuC8wIlbaOwT9lgq5qo5sspjrZJQlBR1TWflP49uRpMw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -3336,9 +3353,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-darwin-x64": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-darwin-x64/-/binding-darwin-x64-0.17.0.tgz",
|
||||
"integrity": "sha512-AoWoVw8rktzCHXvpoygUu2QZ37LVlCp77p0oZ8EijCMUIaWzTMNUnkRGosEGvzXJOOpzB4wuXYVkphcV55Er+g==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-darwin-x64/-/binding-darwin-x64-0.19.0.tgz",
|
||||
"integrity": "sha512-pTC7dYEc59isdyizc3nsuyFNBu2LU5wMYZ1be6UMr59PY/AJNtO1aBLWV0MgL/z7C1nv/2sX4TNjGgKLoeevJw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -3349,9 +3366,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-freebsd-x64": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-freebsd-x64/-/binding-freebsd-x64-0.17.0.tgz",
|
||||
"integrity": "sha512-CpyBhwZSzkRX6ZPt3AYVlG0TYk11cTP6rZ7Rz0Ux1BLxHgy4TmEW4UGsiKnL5FMAY/nM3HudevWmvaUVV4Qgng==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-freebsd-x64/-/binding-freebsd-x64-0.19.0.tgz",
|
||||
"integrity": "sha512-xrZjF6XOEwyLOiDIfrwDdRCS6ghxcJeirNC1KivQhVcUwlRonaU79S3/Uiyx3lBylPnT8qKJ3/aMT+H52nGTJQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -3362,9 +3379,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-linux-arm-gnu": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm-gnu/-/binding-linux-arm-gnu-0.17.0.tgz",
|
||||
"integrity": "sha512-H6SQK917PjtWpbQmqUsRAqDDToutDqoXWzLKKAFY+6PSfNnzRPLrydm6SG/GkHT91L8Z2/yJPwXzzF98t1UlbQ==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm-gnu/-/binding-linux-arm-gnu-0.19.0.tgz",
|
||||
"integrity": "sha512-0OyIH53C0I1CbADHn9FSdCfX5qbpeLwJhmOVhonFJNYheybOnkSJ50qGMfTJIb8y5zrwqvLs7FVBvz6Fk8maZg==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
@@ -3378,9 +3395,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-linux-arm-musl": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm-musl/-/binding-linux-arm-musl-0.17.0.tgz",
|
||||
"integrity": "sha512-sAxyv9p/3+fxJgXcUsaJ+8IRQWvZ4F264Gx7Kj/VBuIQX95Ih7jP/zUZPGr2UM/3NHFnXIb74Rhyuk6WLufIrQ==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm-musl/-/binding-linux-arm-musl-0.19.0.tgz",
|
||||
"integrity": "sha512-z/iPfkCOCSXE34VXNt0uP1ORSW+4mEa9b5CiJcWZeqZH08g49bFU/jRM2T04f+Wpw5mJ6HIzNBiojxeAbrHjeg==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
@@ -3394,9 +3411,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-linux-arm64-gnu": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-0.17.0.tgz",
|
||||
"integrity": "sha512-hDcx5Nt04jMwkllwZVtxiWt1qQI5gCqaFcT1JLP6Lw9eOqx1Yt8p21NuqZuqknmnW5napB3dSwF7Op+eySHdrQ==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-0.19.0.tgz",
|
||||
"integrity": "sha512-jLNTi+gzaRwBJ+gwhCJ+rDb5dmx/8hEBx93UWd7hjMSqPTL1D1wvVSvXVAldV5kALvju7b0/m51EHEhs4+I1fA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -3410,9 +3427,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-linux-arm64-musl": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm64-musl/-/binding-linux-arm64-musl-0.17.0.tgz",
|
||||
"integrity": "sha512-SGWvwtPe3uXVGjpKk6LTjO4ieGzad/a5h3cbSeduSIiNDfotM200kifB5cPUfg2LhfbM4uCImsApYZOqXW8lkw==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-arm64-musl/-/binding-linux-arm64-musl-0.19.0.tgz",
|
||||
"integrity": "sha512-YwyPIdW/rN2Fmv0MTFWi47FaB3F9g+2b+sJISyAw83Yd60RWH4T3Nx6XkAHHVN+uKJNBAd6So7/BVihSiFYvuQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -3426,9 +3443,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-linux-x64-gnu": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-x64-gnu/-/binding-linux-x64-gnu-0.17.0.tgz",
|
||||
"integrity": "sha512-Vq258yq8+UZQwdD26b6lz9FtqwHwOVWyjy+lcbYKlAhFuN/0FNO2UzlkG5F/0pXR0iRK/Xyxkq5IZpLJHS+2HQ==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-x64-gnu/-/binding-linux-x64-gnu-0.19.0.tgz",
|
||||
"integrity": "sha512-/vskaAXVX3ESR43FiTdfiYS7z1b9uoQJwVQ/0RgUHgN2sWoAyCZs+aX4CgU7eKGIHTVfp9VFwv+c+2XchYiEtQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -3442,9 +3459,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-linux-x64-musl": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-x64-musl/-/binding-linux-x64-musl-0.17.0.tgz",
|
||||
"integrity": "sha512-luEtfpzTP3Xph+HHz2rIVGH1VLbext5SFYrUyhKlbgoahkZ8MDzKI9TYsOVt0HukQkyEtW7+fG7yXJcdKqD4GA==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-linux-x64-musl/-/binding-linux-x64-musl-0.19.0.tgz",
|
||||
"integrity": "sha512-FuXL5igeSKib9Rye02TdH+D6SQezTyGxIATMu1Qsn/QywrzwpGl35OLpS2C1x5vpGLeVE2XgiLd5mVPFHmIglQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -3458,9 +3475,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-win32-arm64": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-win32-arm64/-/binding-win32-arm64-0.17.0.tgz",
|
||||
"integrity": "sha512-CaqorOjCPJgUoDwS5nztgeZW4ay21enm3A4A42EY/CotiyDbFO7lKfrqTftGb+ZXrwJ41gNtY1gQ0AaWm0Wvwg==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-win32-arm64/-/binding-win32-arm64-0.19.0.tgz",
|
||||
"integrity": "sha512-YuJAe7zEKT1Xa7LuHlhGJpPnYQeVtvo0rZvNjJRqkH0hQGOw4C8QeP30Tg5VKGzZfo2x8CjhjEhKt4TmLwfmdg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -3471,9 +3488,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-core/binding-win32-x64": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-win32-x64/-/binding-win32-x64-0.17.0.tgz",
|
||||
"integrity": "sha512-gPDXHz0dPwvgj1GO7xzK8jPktrCh9xyMXZKmwqq+5bemxrSXSDUK/osSw93xmHha/PQP2WcJ1WiJ8+XEx+ciHg==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-core/binding-win32-x64/-/binding-win32-x64-0.19.0.tgz",
|
||||
"integrity": "sha512-o8iY/mXwlRkedp0LNTr4+TEfXTPQwoNZmv6k+1WIAd1ZXEn8xJJTBCtB0osaVvdZo/x/cNmV16UrWrrGpM5Mvw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -3484,9 +3501,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@yuku-toolchain/types": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-toolchain/types/-/types-0.17.0.tgz",
|
||||
"integrity": "sha512-3T4eKUuFAtuwbyRc2OIpanxPTl4CZdbmOvg1HB9UmRrPb3bsF3fFfbLSyIFYtZrE9/cNqLyEq/7g3Hm6nHIekA==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@yuku-toolchain/types/-/types-0.19.0.tgz",
|
||||
"integrity": "sha512-tFkNbsP4WXX9UMUC5syJGdK9dPMLK0PPaIuXCcCYH75sZ8MrebfBZ2XvCILRTw8AgLivSSCfDa4R67iYBDa4Kg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
@@ -3507,15 +3524,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ai": {
|
||||
"version": "7.0.137",
|
||||
"resolved": "https://registry.npmjs.org/ai/-/ai-7.0.137.tgz",
|
||||
"integrity": "sha512-JxrPkSQknxIN/gYqS3UQksExS6eWI23QMPBrKMGXeeFHhru6xFtF4MuMq17WaHD+lXPh0lne6H0BM2Z2VMW9EQ==",
|
||||
"version": "7.0.148",
|
||||
"resolved": "https://registry.npmjs.org/ai/-/ai-7.0.148.tgz",
|
||||
"integrity": "sha512-FPgfIAhz/FrlzcvqTN7pGGibahR5rD19NXZWX9WQ1tskTic+CN+jxvubpreyq8uN1maIEHPwvZmil/3IYN8FIw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@ai-sdk/gateway": "4.0.110",
|
||||
"@ai-sdk/provider": "4.0.26",
|
||||
"@ai-sdk/provider-utils": "5.0.58"
|
||||
"@ai-sdk/gateway": "4.0.121",
|
||||
"@ai-sdk/provider": "4.0.31",
|
||||
"@ai-sdk/provider-utils": "5.0.65"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -4120,9 +4137,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/fumadocs-core": {
|
||||
"version": "16.17.1",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-core/-/fumadocs-core-16.17.1.tgz",
|
||||
"integrity": "sha512-zquUMPZaCEdsxFZ6ReZPzVN2yCP9tS3GZRndK0WtxbsvZ9KvvUDCeoLIpOZ6d3JU0uwSsclaIUGxI5ifvTftOQ==",
|
||||
"version": "16.17.7",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-core/-/fumadocs-core-16.17.7.tgz",
|
||||
"integrity": "sha512-o8uR1JuFgAHrUSbX/hzThOsvW8tFXfV4vlrWf7VeFd+lbQsRqwr8R7gvs96Vwwzn5xSDfgg0boQalyv1llJAQQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fumari/image-size": "^0.1.1",
|
||||
@@ -4232,9 +4249,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/fumadocs-mdx": {
|
||||
"version": "15.4.7",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-mdx/-/fumadocs-mdx-15.4.7.tgz",
|
||||
"integrity": "sha512-54lE+dIlIkebSxcN1Lqe0yn5lkKI4zm/Fxl+Se+IqSGyANsBVoa7XaDFFUSLfklxfkSM1NKkrbw0yzvRWVb9rw==",
|
||||
"version": "15.4.9",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-mdx/-/fumadocs-mdx-15.4.9.tgz",
|
||||
"integrity": "sha512-vsZGzpGsWptlBAX8sWb7R87KIt9+3GhJa5GpkwJqBv/OaN9QGul34hJikKdq6C8pT2XOwKMB499lvj31JaHbGg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@mdx-js/mdx": "^3.1.1",
|
||||
@@ -4243,7 +4260,7 @@
|
||||
"esbuild": "^0.28.2",
|
||||
"estree-util-value-to-estree": "^3.5.0",
|
||||
"github-slugger": "^2.0.0",
|
||||
"magic-string": "^1.4.2",
|
||||
"magic-string": "^1.4.3",
|
||||
"mdast-util-mdx": "^3.0.0",
|
||||
"picocolors": "^1.1.1",
|
||||
"picomatch": "^4.0.7",
|
||||
@@ -4253,8 +4270,8 @@
|
||||
"unist-util-remove-position": "^5.0.0",
|
||||
"vfile": "^6.0.3",
|
||||
"yaml": "^2.9.1",
|
||||
"yuku-analyzer": "^0.17.0",
|
||||
"zod": "^4.6.5"
|
||||
"yuku-analyzer": "^0.19.0",
|
||||
"zod": "^4.6.7"
|
||||
},
|
||||
"bin": {
|
||||
"fumadocs-mdx": "bin.js"
|
||||
@@ -4315,15 +4332,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/fumadocs-twoslash": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-twoslash/-/fumadocs-twoslash-4.0.2.tgz",
|
||||
"integrity": "sha512-SZVadHkuPO8CbtNvM8K9VzgzWAWUi3MDGAQYKVtgi/11Ni3OgZJ3H5YV+P1UwF/HapaSnJKUnLVRH2TM8VsUTg==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-twoslash/-/fumadocs-twoslash-4.0.3.tgz",
|
||||
"integrity": "sha512-QBa+wKTNRQdcnQHBCGL1EvOKKtvKUWJGJmxZl3PvNf6VnK56ZZyLMZWUEMWsdycERetViRHrjDcES8CShHZYMg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.8.0",
|
||||
"@base-ui/react": "^1.9.0",
|
||||
"@types/hast": "^3.0.5",
|
||||
"cn": "^0.4.0",
|
||||
"mdast-util-from-markdown": "^2.0.3",
|
||||
"cn": "^0.5.0",
|
||||
"mdast-util-from-markdown": "^2.1.0",
|
||||
"mdast-util-to-hast": "^13.2.1",
|
||||
"typescript": "~7.0.2"
|
||||
},
|
||||
@@ -4341,10 +4358,22 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/fumadocs-twoslash/node_modules/cn": {
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.npmjs.org/cn/-/cn-0.5.0.tgz",
|
||||
"integrity": "sha512-JGEixZEpfFXm1P5uXwvEobOFLlHwIWi5v4tjd1ZwfiYmcEilkuD2l+054rvJcYCR1B+uVThHeUbgmNz1FwuxuA==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"cn": "bin/cn.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
},
|
||||
"node_modules/fumadocs-typescript": {
|
||||
"version": "5.5.1",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-typescript/-/fumadocs-typescript-5.5.1.tgz",
|
||||
"integrity": "sha512-dnK9YeF5UL3zENYthI/529QWRoQDw2JjyhZmXPVbGMs/kRdQ4env5qGKgtxr/J11jpqf0lPt92zB+4p3yUmTOw==",
|
||||
"version": "5.5.2",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-typescript/-/fumadocs-typescript-5.5.2.tgz",
|
||||
"integrity": "sha512-QbKLRpx2Hfyq3R4NpPHKEz0TW+csBuT9IFLhrjyalfP89HpsZBwpHRVCOl//d2Smcbpmj9N4UCp03p97od+NkA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"estree-util-value-to-estree": "^3.5.0",
|
||||
@@ -4385,13 +4414,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/fumadocs-ui": {
|
||||
"version": "16.17.1",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-ui/-/fumadocs-ui-16.17.1.tgz",
|
||||
"integrity": "sha512-ByW1NbvEbMfsZfW+DkWewSEX7Ituv732K0y2ga1ri+Zghf+4zu2sa0QjJetC3DaKffyvx5vbPVxwjyYCeNtRhg==",
|
||||
"version": "16.17.7",
|
||||
"resolved": "https://registry.npmjs.org/fumadocs-ui/-/fumadocs-ui-16.17.7.tgz",
|
||||
"integrity": "sha512-3zqnVKUnDoGRLu2I0IniEwnurW/eGQeZNS80bgrebPdfp1BYd+51EeBEwxgGJgNWBAFLFxQvuE0TBDgqKVndsQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fuma-translate/react": "^1.0.2",
|
||||
"@fumadocs/tailwind": "0.1.3",
|
||||
"@fumadocs/tailwind": "0.1.4",
|
||||
"@radix-ui/react-accordion": "^1.2.20",
|
||||
"@radix-ui/react-collapsible": "^1.1.20",
|
||||
"@radix-ui/react-dialog": "^1.1.23",
|
||||
@@ -4415,7 +4444,7 @@
|
||||
"peerDependencies": {
|
||||
"@types/mdx": "*",
|
||||
"@types/react": "*",
|
||||
"fumadocs-core": "16.17.1",
|
||||
"fumadocs-core": "16.17.7",
|
||||
"next": "16.x.x",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
@@ -4966,9 +4995,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/lucide-react": {
|
||||
"version": "1.55.0",
|
||||
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.55.0.tgz",
|
||||
"integrity": "sha512-bSozQHiI3/8q7JvgoqVRGOYUi7fYT3siAZwmZsljjsOH2Husp/2ODdFf/leD+ZC/2yKfn7r8oh6yeoR3ITR5vA==",
|
||||
"version": "1.61.0",
|
||||
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.61.0.tgz",
|
||||
"integrity": "sha512-v2SQPPPNjnr+BlhL9Spuzmo5yR+hLkftfuE4E3jaxdNPgSH0hJKPcLJBP7yAta87jQNPsSERS59PJjCJ/CorBA==",
|
||||
"license": "ISC",
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
@@ -5023,7 +5052,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/mdast-util-from-markdown": {
|
||||
"version": "2.0.3",
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-2.1.0.tgz",
|
||||
"integrity": "sha512-KRLgmPaP2H1ul2bpoJkOS+9pAcDAAj9Nu1mqLnh8NLeJG5tlvj42TH80PIGBpROWlRXLk0lDrWNuZCFy/tsB4A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/mdast": "^4.0.0",
|
||||
@@ -5976,12 +6007,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/next": {
|
||||
"version": "16.4.0",
|
||||
"resolved": "https://registry.npmjs.org/next/-/next-16.4.0.tgz",
|
||||
"integrity": "sha512-N2C+9q89Z/oLrsepSRS4jRMtwmUZAoZuAHU0e9T6+sAB5DdhADmrnOW+zjYijlrYFmVfmQhGVGy9eMFoB7UgKg==",
|
||||
"version": "16.4.3",
|
||||
"resolved": "https://registry.npmjs.org/next/-/next-16.4.3.tgz",
|
||||
"integrity": "sha512-OqxKTGi9u80FydydsMNYNjnuje9Au+kvHlt2GZ//ftdpDHm1dxKqAaENoOOTX5wKzn+9vaKUNIfZeyZUuLhCnA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@next/env": "16.4.0",
|
||||
"@next/env": "16.4.3",
|
||||
"@swc/helpers": "0.5.23",
|
||||
"baseline-browser-mapping": "^2.9.19",
|
||||
"caniuse-lite": "^1.0.30001579",
|
||||
@@ -5995,15 +6026,15 @@
|
||||
"node": ">=20.9.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@next/swc-darwin-arm64": "16.4.0",
|
||||
"@next/swc-darwin-x64": "16.4.0",
|
||||
"@next/swc-linux-arm64-gnu": "16.4.0",
|
||||
"@next/swc-linux-arm64-musl": "16.4.0",
|
||||
"@next/swc-linux-x64-gnu": "16.4.0",
|
||||
"@next/swc-linux-x64-musl": "16.4.0",
|
||||
"@next/swc-win32-arm64-msvc": "16.4.0",
|
||||
"@next/swc-win32-x64-msvc": "16.4.0",
|
||||
"sharp": "^0.35.4"
|
||||
"@next/swc-darwin-arm64": "16.4.3",
|
||||
"@next/swc-darwin-x64": "16.4.3",
|
||||
"@next/swc-linux-arm64-gnu": "16.4.3",
|
||||
"@next/swc-linux-arm64-musl": "16.4.3",
|
||||
"@next/swc-linux-x64-gnu": "16.4.3",
|
||||
"@next/swc-linux-x64-musl": "16.4.3",
|
||||
"@next/swc-win32-arm64-msvc": "16.4.3",
|
||||
"@next/swc-win32-x64-msvc": "16.4.3",
|
||||
"sharp": "^0.35.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@opentelemetry/api": "^1.1.0",
|
||||
@@ -6066,9 +6097,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/openai": {
|
||||
"version": "7.32.0",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-7.32.0.tgz",
|
||||
"integrity": "sha512-avqxu/jl1gsVBCBgFNPr9sTh+wZppQphuhhFy1zEvAJxEaJ4t0ery6hZdOT9kws/EcNTARoQcZs2IT3bliE1SA==",
|
||||
"version": "7.39.0",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-7.39.0.tgz",
|
||||
"integrity": "sha512-iEA9ndbrj32vhYZwJg2v9BQVuztGUOb2SBQU16ZcWNkQHWEBjtarxjqR9c6d5PbWMG0Eyfhk66OZ0iJ8XpFjyw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
@@ -6148,9 +6179,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.5.29",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.29.tgz",
|
||||
"integrity": "sha512-49cGhUbXj8Qenv0iTMxA1cFBzxXoctpC9Ujd77t1WcbJIr6nF/eI7g/8MgxrYldFRuAXvja7xQRwavoW7kgrxQ==",
|
||||
"version": "8.5.31",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.31.tgz",
|
||||
"integrity": "sha512-YUbWYCgErwnMAVkjUnYa+KlMBzGpHwiIt/DE7f0G33AuX2LH9UcTk6KgWxd3zRU+pN3u/C+Xl3EnMLM4Hea7Sg==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
@@ -6167,7 +6198,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.19",
|
||||
"nanoid": "^3.3.20",
|
||||
"picocolors": "^1.1.1",
|
||||
"source-map-js": "^1.2.2"
|
||||
},
|
||||
@@ -6195,24 +6226,24 @@
|
||||
}
|
||||
},
|
||||
"node_modules/react": {
|
||||
"version": "19.3.0",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.3.0.tgz",
|
||||
"integrity": "sha512-E8LUcbtBWt20bbl2YoHfx4ZDBdxVTfOKtCZn9cDSJ4l6/nuoApcpIBcj47t2wZoVX8g2ZHuMHbiShgCR1T5Sog==",
|
||||
"version": "19.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz",
|
||||
"integrity": "sha512-QNhWdt7nrgVWWQG58QuGsAR3jv3Hbe4mb4vz7w2csnHavciZJgda1CPNaldF6eVxv90ud3jUXpKlHL69gO38yw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-dom": {
|
||||
"version": "19.3.0",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.0.tgz",
|
||||
"integrity": "sha512-JDk8dgif51OjFoDE70+OT9ICyYr+69HlmihNwp1+Nsfbna3t5sIiCa9ZJktDmQ4/1b/rn26hIAR2uYXDMr5r0Q==",
|
||||
"version": "19.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz",
|
||||
"integrity": "sha512-Y0bARz53lhEC1NMCASs0/j+faB/zqt3R8hpvg1e8+61ZVJ4UL0UdC4cBbXfZMcIuhrfgeILTLe+ZeBCavQPtKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"scheduler": "^0.28.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.3.0"
|
||||
"react": "^19.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
@@ -6849,9 +6880,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "7.29.1",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.29.1.tgz",
|
||||
"integrity": "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q==",
|
||||
"version": "7.30.1",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.30.1.tgz",
|
||||
"integrity": "sha512-03KrMbjIFDWQR5RNPrSw3bd1r12JpyFQl9/yxjUbJtqkjmllqC5lFjZh6ujeuJCKr8EOQvRW872Oy/az+nLYxg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -7007,7 +7038,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/use-sync-external-store": {
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.7.0.tgz",
|
||||
"integrity": "sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
@@ -7088,55 +7121,55 @@
|
||||
}
|
||||
},
|
||||
"node_modules/yuku-analyzer": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/yuku-analyzer/-/yuku-analyzer-0.17.0.tgz",
|
||||
"integrity": "sha512-MJWtt5HvXVR51mGOR2uMXQ45t1X1oMkmx4vaP/Li1HNC69OFG/qYmxf++aVazkXH5pdxTYTHYRUPl67b7NYxjA==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/yuku-analyzer/-/yuku-analyzer-0.19.0.tgz",
|
||||
"integrity": "sha512-Iu7DV5cWOQ3ERSA7oBquz/RT5IEGsUyUeCivYs9lQaZ4nSjM31yD17mH616JKcTyVoVWYivsFZ+twT3UyBosTA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@yuku-toolchain/types": "^0.17.0",
|
||||
"yuku-ast": "^0.17.0",
|
||||
"yuku-core": "0.17.0"
|
||||
"@yuku-toolchain/types": "^0.19.0",
|
||||
"yuku-ast": "^0.19.0",
|
||||
"yuku-core": "0.19.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/yuku-ast": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/yuku-ast/-/yuku-ast-0.17.0.tgz",
|
||||
"integrity": "sha512-htIzp3bLNdBtOSh8L8pJ7nkTft2kw/C3ghTToSg3FKtzi0YGkvAdEUUza9c744tnbeXtKUMEupFOYHuVNXn1yQ==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/yuku-ast/-/yuku-ast-0.19.0.tgz",
|
||||
"integrity": "sha512-PyCsiScaelhxBGzL8dyeJkLqvRZycoh78R31Vrt/WqYrm0hMFoKwIw/X7Dx5mBKLWAMlV9I9HEyBOHnj2gZVyw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@yuku-toolchain/types": "^0.17.0"
|
||||
"@yuku-toolchain/types": "^0.19.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/yuku-core": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/yuku-core/-/yuku-core-0.17.0.tgz",
|
||||
"integrity": "sha512-4BgHT4euQ62wr/9h5UWoMzt4QTrmT3WUo96aRiY2R6RRCyKjCveU23MNwNJISzYvNnbFGZ7O2E1SU5zgWqzS+Q==",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/yuku-core/-/yuku-core-0.19.0.tgz",
|
||||
"integrity": "sha512-kYK9e1XdfirNhkipzW0wmMcSWcVF/CWnuugodfVYRCUwvoBefweL9HzB96OiKEhsx78V5WbUxbJqlizMX869Qg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@yuku-toolchain/types": "^0.17.0"
|
||||
"@yuku-toolchain/types": "^0.19.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@yuku-core/binding-android-arm64": "0.17.0",
|
||||
"@yuku-core/binding-darwin-arm64": "0.17.0",
|
||||
"@yuku-core/binding-darwin-x64": "0.17.0",
|
||||
"@yuku-core/binding-freebsd-x64": "0.17.0",
|
||||
"@yuku-core/binding-linux-arm-gnu": "0.17.0",
|
||||
"@yuku-core/binding-linux-arm-musl": "0.17.0",
|
||||
"@yuku-core/binding-linux-arm64-gnu": "0.17.0",
|
||||
"@yuku-core/binding-linux-arm64-musl": "0.17.0",
|
||||
"@yuku-core/binding-linux-x64-gnu": "0.17.0",
|
||||
"@yuku-core/binding-linux-x64-musl": "0.17.0",
|
||||
"@yuku-core/binding-win32-arm64": "0.17.0",
|
||||
"@yuku-core/binding-win32-x64": "0.17.0"
|
||||
"@yuku-core/binding-android-arm64": "0.19.0",
|
||||
"@yuku-core/binding-darwin-arm64": "0.19.0",
|
||||
"@yuku-core/binding-darwin-x64": "0.19.0",
|
||||
"@yuku-core/binding-freebsd-x64": "0.19.0",
|
||||
"@yuku-core/binding-linux-arm-gnu": "0.19.0",
|
||||
"@yuku-core/binding-linux-arm-musl": "0.19.0",
|
||||
"@yuku-core/binding-linux-arm64-gnu": "0.19.0",
|
||||
"@yuku-core/binding-linux-arm64-musl": "0.19.0",
|
||||
"@yuku-core/binding-linux-x64-gnu": "0.19.0",
|
||||
"@yuku-core/binding-linux-x64-musl": "0.19.0",
|
||||
"@yuku-core/binding-win32-arm64": "0.19.0",
|
||||
"@yuku-core/binding-win32-x64": "0.19.0"
|
||||
}
|
||||
},
|
||||
"node_modules/zbsearch": {
|
||||
@@ -7149,9 +7182,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "4.6.5",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.5.tgz",
|
||||
"integrity": "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q==",
|
||||
"version": "4.6.7",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
|
||||
"integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
|
||||
+14
-14
@@ -17,29 +17,29 @@
|
||||
"class-variance-authority": "0.7.1",
|
||||
"clsx": "2.1.1",
|
||||
"dotted-map": "^3.1.0",
|
||||
"fumadocs-core": "16.17.1",
|
||||
"fumadocs-mdx": "15.4.7",
|
||||
"fumadocs-twoslash": "^4.0.2",
|
||||
"fumadocs-typescript": "^5.5.1",
|
||||
"fumadocs-ui": "16.17.1",
|
||||
"lucide-react": "^1.48.0",
|
||||
"next": "^16.4.0",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0",
|
||||
"fumadocs-core": "16.17.7",
|
||||
"fumadocs-mdx": "15.4.9",
|
||||
"fumadocs-twoslash": "^4.0.3",
|
||||
"fumadocs-typescript": "^5.5.2",
|
||||
"fumadocs-ui": "16.17.7",
|
||||
"lucide-react": "^1.61.0",
|
||||
"next": "^16.4.3",
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1",
|
||||
"recharts": "^3.10.1",
|
||||
"tailwind-merge": "^3.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ai-sdk/openai": "^4.0.91",
|
||||
"@anthropic-ai/sdk": "^0.133.0",
|
||||
"@ai-sdk/openai": "^4.0.99",
|
||||
"@anthropic-ai/sdk": "^0.137.0",
|
||||
"@tailwindcss/postcss": "^4.3.3",
|
||||
"@types/mdx": "^2.0.14",
|
||||
"@types/node": "^26.6.5",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"ai": "7.0.137",
|
||||
"openai": "^7.32.0",
|
||||
"postcss": "^8.5.29",
|
||||
"ai": "7.0.148",
|
||||
"openai": "^7.39.0",
|
||||
"postcss": "^8.5.31",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"typescript": "^7.0.2"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
# HEAOSS-6 Pull Request Split Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Replace PR #3382 with six focused draft pull requests whose cumulative tip preserves its reviewed HEAOSS-6 behavior.
|
||||
|
||||
**Architecture:** Build a linear Git branch stack from current upstream `main`. Each branch introduces one independently useful layer: decisions, policy contracts, evidence contracts, manifest tooling, reusable release builds, then candidate orchestration.
|
||||
|
||||
**Tech Stack:** Git, GitHub CLI, Python 3.13, pytest, JSON Schema 2020-12, GitHub Actions, Ruff, mypy, actionlint
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-09-17-heaoss-6-pr-split-design.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- The first branch is based on current upstream `main`; each later branch is based on its immediate predecessor.
|
||||
- Every pull request is opened as a draft and targets the preceding branch.
|
||||
- The original PR #3382 stays unchanged until all six drafts and the cumulative-equivalence audit exist.
|
||||
- No unrelated merge-commit changes from PR #3382 may enter the new stack.
|
||||
- Release publishing behavior remains intact after every executable slice.
|
||||
- Every PR body states `Part of HEAOSS-6; split from #3382.` and identifies its stack position.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Release Qualification Decisions
|
||||
|
||||
**Files:**
|
||||
- Create: `docs/adr/0001-main-release-branch-semantics.md`
|
||||
- Create: `docs/adr/0002-release-artifact-identity.md`
|
||||
- Create: `docs/adr/0003-a1-b-release-benchmark.md`
|
||||
- Create: `docs/adr/0004-black-box-release-benchmarks.md`
|
||||
- Create: `docs/adr/0005-release-overrides-and-fail-closed-policy.md`
|
||||
- Existing: `docs/superpowers/specs/2026-09-17-heaoss-6-pr-split-design.md`
|
||||
- Existing: `docs/superpowers/plans/2026-09-17-heaoss-6-pr-split.md`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: HEAOSS-6 decisions preserved on `upstream/pr-3382`.
|
||||
- Produces: Stable terminology for source, artifact, rollout, policy, benchmark, and override identity used by later PRs.
|
||||
|
||||
- [ ] **Step 1: Restore the five reviewed ADRs**
|
||||
|
||||
```powershell
|
||||
git checkout upstream/pr-3382 -- docs/adr/0001-main-release-branch-semantics.md docs/adr/0002-release-artifact-identity.md docs/adr/0003-a1-b-release-benchmark.md docs/adr/0004-black-box-release-benchmarks.md docs/adr/0005-release-overrides-and-fail-closed-policy.md
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Verify documentation integrity**
|
||||
|
||||
Run both `git diff --check` and `git diff --cached --check`; stop if either exits nonzero. The restore command stages the ADRs, so the cached check is required to inspect those files.
|
||||
Run `rg -n 'TB[D]|TO[D]O'` against the five restored ADRs and this split's specification and plan. Exit 1 means no placeholders; exit 0 reports unresolved markers, and exit 2 is a scan error.
|
||||
Expected: both whitespace checks exit 0 and no unresolved placeholder is present in these seven documents. Unrelated plans and ADRs are outside this slice's placeholder check.
|
||||
|
||||
- [ ] **Step 3: Commit the documentation slice**
|
||||
|
||||
```powershell
|
||||
git add docs/adr docs/superpowers
|
||||
git commit -m "docs(release): define qualification decisions"
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Push and open draft PR 1**
|
||||
|
||||
```powershell
|
||||
git push -u origin jd/heaoss-6-01-release-qualification-decisions
|
||||
gh pr create --repo headroomlabs-ai/headroom --draft --base main --head JerrettDavis:jd/heaoss-6-01-release-qualification-decisions --title "docs(release): define qualification decisions" --body-file <body-file>
|
||||
```
|
||||
|
||||
### Task 2: Shared Policy Contracts
|
||||
|
||||
**Files:**
|
||||
- Create: `release/contracts/common.schema.json`
|
||||
- Create: `release/contracts/policy.schema.json`
|
||||
- Create: `release/contracts/examples/policy.valid.json`
|
||||
- Create: `release/contracts/README.md`
|
||||
- Modify: `pyproject.toml`
|
||||
- Modify: `uv.lock`
|
||||
- Create: `tests/test_release_contracts.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: ADR terminology from Task 1.
|
||||
- Produces: JSON Schema definitions referenced as `common.schema.json#/$defs/...` and a complete `policy.schema.json` consumer.
|
||||
|
||||
- [ ] **Step 1: Create the stacked branch and restore contract sources**
|
||||
|
||||
```powershell
|
||||
git switch -c jd/heaoss-6-02-release-policy-contracts
|
||||
git checkout upstream/pr-3382 -- release/contracts/common.schema.json release/contracts/policy.schema.json release/contracts/examples/policy.valid.json release/contracts/README.md pyproject.toml uv.lock
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Add focused policy contract tests**
|
||||
|
||||
Extract the schema-registry helpers and policy-specific cases from PR #3382's
|
||||
`tests/test_release_contracts.py`. The resulting test file must load local
|
||||
schemas through `referencing.Registry`, validate `policy.valid.json`, reject an
|
||||
unknown schema version, and enforce policy pass/fail invariants.
|
||||
|
||||
- [ ] **Step 3: Validate and commit**
|
||||
|
||||
Run: `uv lock --check`
|
||||
|
||||
Run: `uv run --extra dev pytest tests/test_release_contracts.py -q`
|
||||
|
||||
Run: `uv run --extra dev ruff check tests/test_release_contracts.py`
|
||||
|
||||
Expected: all commands exit 0.
|
||||
|
||||
```powershell
|
||||
git add release/contracts tests/test_release_contracts.py pyproject.toml uv.lock
|
||||
git commit -m "feat(release): define versioned policy contracts"
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Push and open draft PR 2 targeting PR 1's branch**
|
||||
|
||||
Use title `feat(release): define versioned policy contracts` and base
|
||||
`jd/heaoss-6-01-release-qualification-decisions`.
|
||||
|
||||
### Task 3: Qualification Evidence Contracts
|
||||
|
||||
**Files:**
|
||||
- Create: `release/contracts/benchmark-result-ref.schema.json`
|
||||
- Create: `release/contracts/candidate-manifest.schema.json`
|
||||
- Create: `release/contracts/gate-result.schema.json`
|
||||
- Create: `release/contracts/integration-result.schema.json`
|
||||
- Create: `release/contracts/qualification-manifest.schema.json`
|
||||
- Create: matching files under `release/contracts/examples/`
|
||||
- Modify: `tests/test_release_contracts.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `common.schema.json` definitions and the release policy contract.
|
||||
- Produces: Complete evidence formats used by candidate tooling and future qualification lanes.
|
||||
|
||||
- [ ] **Step 1: Create the branch and restore all remaining schemas/examples**
|
||||
|
||||
Create `jd/heaoss-6-03-qualification-evidence-contracts` from Task 2, then
|
||||
restore the declared files from `upstream/pr-3382`.
|
||||
|
||||
- [ ] **Step 2: Restore the complete reviewed contract test suite**
|
||||
|
||||
```powershell
|
||||
git checkout upstream/pr-3382 -- tests/test_release_contracts.py
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Validate and commit**
|
||||
|
||||
Run: `uv run --extra dev pytest tests/test_release_contracts.py -q`
|
||||
|
||||
Run: `uv run --extra dev ruff check tests/test_release_contracts.py`
|
||||
|
||||
Expected: all contract examples and negative invariants pass.
|
||||
|
||||
Commit as `feat(release): add qualification evidence contracts`.
|
||||
|
||||
- [ ] **Step 4: Push and open draft PR 3 targeting PR 2's branch**
|
||||
|
||||
### Task 4: Candidate Manifest CLI
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/candidate_manifest.py`
|
||||
- Create: `tests/test_candidate_manifest.py`
|
||||
- Modify: `.gitignore`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `release/contracts/candidate-manifest.schema.json` and common definitions.
|
||||
- Produces: `inventory`, `create`, and `verify` CLI commands used by Task 6.
|
||||
|
||||
- [ ] **Step 1: Create the branch and restore reviewed CLI files**
|
||||
|
||||
Create `jd/heaoss-6-04-candidate-manifest-cli`, then restore the three declared
|
||||
paths from `upstream/pr-3382`.
|
||||
|
||||
- [ ] **Step 2: Validate behavior and types**
|
||||
|
||||
Run: `uv run --extra dev pytest tests/test_candidate_manifest.py tests/test_release_contracts.py -q`
|
||||
|
||||
Run: `uv run --extra dev ruff check scripts/candidate_manifest.py tests/test_candidate_manifest.py`
|
||||
|
||||
Run: `uv run --extra dev mypy scripts/candidate_manifest.py`
|
||||
|
||||
Expected: all commands exit 0.
|
||||
|
||||
- [ ] **Step 3: Commit, push, and open draft PR 4 targeting PR 3's branch**
|
||||
|
||||
Commit as `feat(release): add immutable candidate manifest verifier`.
|
||||
|
||||
### Task 5: Read-Only Release Build Workflow
|
||||
|
||||
**Files:**
|
||||
- Create: `.github/workflows/release-build.yml`
|
||||
- Modify: `.github/workflows/release.yml`
|
||||
- Modify: `tests/test_release_workflows.py`
|
||||
- Modify: `docs/content/docs/releases.mdx`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Existing release build and smoke jobs.
|
||||
- Produces: Reusable `workflow_call` accepting `source_sha`, `manual_version`, and `release_tag`, with version/npm/canonical outputs and retained artifacts.
|
||||
|
||||
- [ ] **Step 1: Create the branch and restore the reviewed extraction**
|
||||
|
||||
Create `jd/heaoss-6-05-read-only-release-build`, then restore the four declared
|
||||
paths from `upstream/pr-3382`.
|
||||
|
||||
- [ ] **Step 2: Validate workflow structure and release invariants**
|
||||
|
||||
Run: `uv run --extra dev pytest tests/test_release_workflows.py -q`
|
||||
|
||||
Run: `actionlint .github/workflows/release.yml .github/workflows/release-build.yml`
|
||||
|
||||
Expected: 50 or more release workflow tests pass and actionlint emits no findings.
|
||||
|
||||
- [ ] **Step 3: Commit, push, and open draft PR 5 targeting PR 4's branch**
|
||||
|
||||
Commit as `refactor(release): extract read-only build workflow`.
|
||||
|
||||
### Task 6: Immutable Candidate Workflow
|
||||
|
||||
**Files:**
|
||||
- Create: `.github/workflows/candidate-artifact.yml`
|
||||
- Create: `tests/test_candidate_workflow.py`
|
||||
- Modify: `docs/content/docs/releases.mdx`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 4 CLI and Task 5 reusable workflow.
|
||||
- Produces: A manual exact-main-SHA candidate artifact and independently verified retained bytes.
|
||||
|
||||
- [ ] **Step 1: Create the branch and restore candidate orchestration**
|
||||
|
||||
Create `jd/heaoss-6-06-immutable-candidate-workflow`, then restore the workflow
|
||||
and test from `upstream/pr-3382`. Reconcile the release documentation so only
|
||||
candidate-specific additions remain in this branch.
|
||||
|
||||
- [ ] **Step 2: Run cumulative focused validation**
|
||||
|
||||
Run: `uv run --extra dev pytest tests/test_candidate_workflow.py tests/test_candidate_manifest.py tests/test_release_contracts.py tests/test_release_workflows.py -q`
|
||||
|
||||
Run: `uv run --extra dev ruff check scripts/candidate_manifest.py tests/test_candidate_manifest.py tests/test_candidate_workflow.py tests/test_release_contracts.py tests/test_release_workflows.py`
|
||||
|
||||
Run: `uv run --extra dev mypy scripts/candidate_manifest.py`
|
||||
|
||||
Run: `actionlint .github/workflows/candidate-artifact.yml .github/workflows/release-build.yml .github/workflows/release.yml`
|
||||
|
||||
Expected: 96 focused tests or the current-main-adjusted equivalent pass; lint,
|
||||
types, and workflow validation exit 0.
|
||||
|
||||
- [ ] **Step 3: Audit cumulative equivalence**
|
||||
|
||||
```powershell
|
||||
git diff --stat upstream/pr-3382...HEAD
|
||||
git diff upstream/pr-3382 HEAD -- .github docs/adr docs/content/docs/releases.mdx release scripts tests/test_candidate_manifest.py tests/test_candidate_workflow.py tests/test_release_contracts.py tests/test_release_workflows.py pyproject.toml uv.lock .gitignore
|
||||
```
|
||||
|
||||
Expected: only the approved split documents and intentional current-main
|
||||
reconciliation differ. Investigate and document every other difference.
|
||||
|
||||
- [ ] **Step 4: Commit, push, and open draft PR 6 targeting PR 5's branch**
|
||||
|
||||
Commit as `feat(release): build immutable exact-SHA candidates`.
|
||||
|
||||
### Task 7: Link the Stack and Supersede PR #3382
|
||||
|
||||
**Files:**
|
||||
- Modify: GitHub draft PR bodies only.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: URLs and exact head/base SHAs for all six draft PRs.
|
||||
- Produces: Navigable stack metadata and a non-destructive supersession notice on #3382.
|
||||
|
||||
- [ ] **Step 1: Update each draft body with complete previous/next links**
|
||||
|
||||
Use `gh pr edit` and verify the rendered bodies with `gh pr view --json body`.
|
||||
|
||||
- [ ] **Step 2: Convert #3382 to draft and prepend the supersession notice**
|
||||
|
||||
The notice must link all six drafts and retain the prior validation history
|
||||
below it. Do not close #3382.
|
||||
|
||||
- [ ] **Step 3: Verify authoritative GitHub state**
|
||||
|
||||
Run `gh pr view` for all seven PRs and verify draft status, base branch, head
|
||||
branch, mergeability, and URLs. Confirm every new PR head SHA matches the pushed
|
||||
local branch.
|
||||
|
||||
- [ ] **Step 4: Report hosted-check status without claiming unobserved success**
|
||||
|
||||
List terminal, pending, or failing checks for each exact head. Hosted checks may
|
||||
continue after handoff; local validation and PR creation are required before
|
||||
the task is reported complete.
|
||||
@@ -0,0 +1,243 @@
|
||||
# HEAOSS-6 Pull Request Split Design
|
||||
|
||||
## Purpose
|
||||
|
||||
Replace the 3,279-line change in PR #3382 with a reviewable stack of six draft
|
||||
pull requests. Every pull request must have one coherent deliverable, pass its
|
||||
own focused validation, and leave the repository in a useful state if the stack
|
||||
stops there.
|
||||
|
||||
The final stack must preserve the behavior and safety properties already
|
||||
reviewed on PR #3382: versioned qualification evidence contracts, fail-closed
|
||||
candidate manifest verification, exact-main-SHA builds, a read-only build call
|
||||
tree, deterministic artifact inventory, and independent verification of the
|
||||
retained candidate bytes.
|
||||
|
||||
## Constraints
|
||||
|
||||
- Base the first branch on the current upstream `main`.
|
||||
- Stack every later branch on its immediate predecessor.
|
||||
- Keep each pull request draft until the whole stack is reconstructed and its
|
||||
cumulative tip is equivalent to PR #3382, except for deliberate documentation
|
||||
and history changes described here.
|
||||
- Do not modify or delete the original PR #3382 branch while constructing the
|
||||
stack.
|
||||
- Do not include unrelated changes from merge commits or the dirty primary
|
||||
checkout.
|
||||
- Preserve the release workflow's existing publish behavior at every executable
|
||||
step of the stack.
|
||||
- Use conventional commit messages and include the HEAOSS-6 context and stack
|
||||
position in every pull request body.
|
||||
|
||||
## Stack Topology
|
||||
|
||||
| Position | Branch | Base | Deliverable |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | `jd/heaoss-6-01-release-qualification-decisions` | `main` | Release qualification ADRs and this split specification |
|
||||
| 2 | `jd/heaoss-6-02-release-policy-contracts` | PR 1 branch | Shared evidence vocabulary and versioned release policy contract |
|
||||
| 3 | `jd/heaoss-6-03-qualification-evidence-contracts` | PR 2 branch | Candidate, benchmark, integration, gate, and qualification evidence schemas |
|
||||
| 4 | `jd/heaoss-6-04-candidate-manifest-cli` | PR 3 branch | Local candidate inventory, manifest creation, and fail-closed verification CLI |
|
||||
| 5 | `jd/heaoss-6-05-read-only-release-build` | PR 4 branch | Reusable read-only build/smoke workflow used by the existing release pipeline |
|
||||
| 6 | `jd/heaoss-6-06-immutable-candidate-workflow` | PR 5 branch | Manual exact-SHA candidate build, bundling, retention, and independent verification |
|
||||
|
||||
GitHub draft PRs use the preceding branch as their base. This makes each diff
|
||||
show only its own deliverable while retaining an executable cumulative tip.
|
||||
|
||||
## PR 1: Release Qualification Decisions
|
||||
|
||||
### Scope
|
||||
|
||||
- Add ADR 0001 defining authoritative-main release semantics.
|
||||
- Add ADR 0002 defining artifact and runtime-payload identity.
|
||||
- Add ADR 0003 defining the A1/B benchmark comparison.
|
||||
- Add ADR 0004 defining black-box release benchmarks.
|
||||
- Add ADR 0005 defining overrides and fail-closed policy.
|
||||
- Add this stack design document.
|
||||
|
||||
### Value at Merge
|
||||
|
||||
The repository gains an explicit, reviewable release-qualification model before
|
||||
automation encodes it. No runtime or workflow behavior changes.
|
||||
|
||||
### Validation
|
||||
|
||||
- Markdown and formatting checks applicable to documentation.
|
||||
- Confirm the ADRs contain no unresolved placeholders and agree on identity,
|
||||
policy, and override terminology.
|
||||
|
||||
## PR 2: Shared Policy Contracts
|
||||
|
||||
### Scope
|
||||
|
||||
- Add `release/contracts/common.schema.json` with shared identity, status,
|
||||
rollout, producer, environment, override, and equivalence definitions.
|
||||
- Add `release/contracts/policy.schema.json` and its valid example.
|
||||
- Add `release/contracts/README.md` covering schema versioning and validation.
|
||||
- Add `jsonschema>=4.23.0,<5.0` to the development dependencies and refresh
|
||||
`uv.lock`.
|
||||
- Introduce the reusable schema loading and validation test helpers in
|
||||
`tests/test_release_contracts.py`, with positive and negative policy tests.
|
||||
|
||||
### Value at Merge
|
||||
|
||||
Policy authors can publish and validate a complete versioned release policy.
|
||||
The shared vocabulary is exercised by a real consumer in the same pull request;
|
||||
it is not unused scaffolding.
|
||||
|
||||
### Validation
|
||||
|
||||
- `uv lock --check`
|
||||
- `uv run --extra dev pytest tests/test_release_contracts.py -q`
|
||||
- `uv run --extra dev ruff check tests/test_release_contracts.py`
|
||||
|
||||
## PR 3: Qualification Evidence Contracts
|
||||
|
||||
### Scope
|
||||
|
||||
- Add candidate-manifest, benchmark-result-reference, integration-result,
|
||||
gate-result, and qualification-manifest schemas.
|
||||
- Add one valid example for every schema.
|
||||
- Extend contract tests to validate every example, reject malformed identities,
|
||||
enforce pass/fail invariants, enforce Gate B runtime-payload equivalence, and
|
||||
reject unsupported schema versions.
|
||||
|
||||
### Value at Merge
|
||||
|
||||
Qualification producers and consumers have a complete, machine-validated
|
||||
evidence interchange format. The contracts are independently useful without
|
||||
the candidate workflow and can be adopted by later qualification lanes.
|
||||
|
||||
### Validation
|
||||
|
||||
- `uv run --extra dev pytest tests/test_release_contracts.py -q`
|
||||
- `uv run --extra dev ruff check tests/test_release_contracts.py`
|
||||
- Validate that all relative `$ref` targets resolve from the checked-in schema
|
||||
registry.
|
||||
|
||||
## PR 4: Candidate Manifest CLI
|
||||
|
||||
### Scope
|
||||
|
||||
- Add `scripts/candidate_manifest.py` with `inventory`, `create`, and `verify`
|
||||
commands.
|
||||
- Add `.candidate/` to `.gitignore` for local command output.
|
||||
- Add focused tests for deterministic ordering, hashes, sizes, package/version
|
||||
identity, source SHA, producer repository/workflow/run identity, rollout
|
||||
identity, safe qualification eligibility, schema versions, missing files,
|
||||
changed bytes, and unsupported embedded schemas.
|
||||
|
||||
### Value at Merge
|
||||
|
||||
Maintainers can create and independently verify immutable candidate manifests
|
||||
locally or from any later CI workflow. The CLI is fully functional before it is
|
||||
wired into GitHub Actions.
|
||||
|
||||
### Validation
|
||||
|
||||
- `uv run --extra dev pytest tests/test_candidate_manifest.py tests/test_release_contracts.py -q`
|
||||
- `uv run --extra dev ruff check scripts/candidate_manifest.py tests/test_candidate_manifest.py`
|
||||
- `uv run --extra dev mypy scripts/candidate_manifest.py`
|
||||
|
||||
## PR 5: Read-Only Release Build Workflow
|
||||
|
||||
### Scope
|
||||
|
||||
- Extract version resolution, package construction, the cross-platform wheel
|
||||
matrix, distribution collection, and smoke imports from `release.yml` into
|
||||
the reusable `release-build.yml` workflow.
|
||||
- Make `release.yml` call the reusable workflow, then retain all publishing and
|
||||
release creation in `release.yml`.
|
||||
- Ensure every publisher waits for the complete build/smoke group.
|
||||
- Preserve the release workflow entry points and published outputs.
|
||||
- Update release workflow tests and release documentation to describe the new
|
||||
boundary.
|
||||
|
||||
### Value at Merge
|
||||
|
||||
The production release uses a reusable, contents-read-only build boundary with
|
||||
no publishing job in its call tree. This is immediately useful even without the
|
||||
candidate workflow and removes duplicated future build logic.
|
||||
|
||||
### Validation
|
||||
|
||||
- `uv run --extra dev pytest tests/test_release_workflows.py -q`
|
||||
- `actionlint .github/workflows/release.yml .github/workflows/release-build.yml`
|
||||
- Hosted PR dry-run must complete all platform builds and smoke-import jobs;
|
||||
publishing jobs must remain skipped.
|
||||
|
||||
## PR 6: Immutable Candidate Workflow
|
||||
|
||||
### Scope
|
||||
|
||||
- Add `candidate-artifact.yml` as a manual workflow accepting only a full SHA
|
||||
reachable from authoritative `main`.
|
||||
- Call `release-build.yml` directly under `contents: read` permissions.
|
||||
- Produce a deterministic artifact inventory and X-001A candidate manifest.
|
||||
- Verify the manifest before upload, download the retained artifact in a
|
||||
separate job, and verify the exact bytes again.
|
||||
- Reject wrong source, repository, producer, workflow, run, attempt,
|
||||
package/version, filename, size, digest, rollout identity, unsafe rollout,
|
||||
qualification-ineligible rollout, or unsupported schema.
|
||||
- Add focused structural workflow tests and document the candidate workflow.
|
||||
|
||||
### Value at Merge
|
||||
|
||||
Maintainers can build and retain an immutable release candidate from an exact
|
||||
commit on authoritative `main` without exposing publishing permissions. The
|
||||
same bytes are verified independently after artifact retention.
|
||||
|
||||
### Validation
|
||||
|
||||
- `uv run --extra dev pytest tests/test_candidate_workflow.py tests/test_candidate_manifest.py tests/test_release_contracts.py tests/test_release_workflows.py -q`
|
||||
- `uv run --extra dev ruff check scripts/candidate_manifest.py tests/test_candidate_manifest.py tests/test_candidate_workflow.py tests/test_release_contracts.py tests/test_release_workflows.py`
|
||||
- `uv run --extra dev mypy scripts/candidate_manifest.py`
|
||||
- `actionlint .github/workflows/candidate-artifact.yml .github/workflows/release-build.yml .github/workflows/release.yml`
|
||||
- Hosted fork validation must build all five platform targets, run all smoke
|
||||
jobs, emit the candidate, download it independently, and verify its bytes.
|
||||
No publishing job may run.
|
||||
|
||||
## Reconstruction Method
|
||||
|
||||
For each branch, restore only the files or coherent hunks assigned to that pull
|
||||
request from PR #3382's reviewed tip. Where one original test file spans two
|
||||
stack positions, split its tests by the behavior introduced at that position.
|
||||
Commit and validate each branch before creating the next branch from it.
|
||||
|
||||
After PR 6, compare its cumulative tree to PR #3382 with `git diff`, allowing
|
||||
only this specification and any necessary stack metadata. Review every
|
||||
remaining difference rather than assuming equivalence from file counts.
|
||||
|
||||
## Draft Pull Request Format
|
||||
|
||||
Each draft body must include:
|
||||
|
||||
- `Stack: N of 6` and links to adjacent draft PRs when available.
|
||||
- The branch/base relationship.
|
||||
- A concise statement of the independently deliverable value.
|
||||
- Exact local validation results for that branch.
|
||||
- A note that hosted validation is pending or a link to its exact run.
|
||||
- `Part of HEAOSS-6; split from #3382.`
|
||||
- Runtime rollout safety and rollback notes appropriate to the slice.
|
||||
|
||||
## Original PR Transition
|
||||
|
||||
Keep #3382 unchanged until all six draft heads exist and the cumulative tip has
|
||||
passed local equivalence and validation checks. Then convert #3382 to draft and
|
||||
replace its leading status section with a supersession notice linking the six
|
||||
drafts. Do not close it until the stack is confirmed visible and complete; its
|
||||
existing discussion and hosted validation remain useful review evidence.
|
||||
|
||||
## Completion Criteria
|
||||
|
||||
The split is complete only when:
|
||||
|
||||
1. Six draft PRs exist with the topology above.
|
||||
2. Every PR diff contains only its declared slice and has passing focused local
|
||||
validation.
|
||||
3. PR 5 demonstrates unchanged release build/smoke behavior with publication
|
||||
skipped on PR validation.
|
||||
4. PR 6 demonstrates candidate creation and independent byte verification with
|
||||
no publishing permissions or publishing jobs in its call tree.
|
||||
5. The cumulative PR 6 tree is reconciled against PR #3382 and every difference
|
||||
is documented and intentional.
|
||||
6. PR #3382 is a draft with a supersession notice linking the complete stack.
|
||||
+61
-8
@@ -22,6 +22,8 @@ from ``e2e/init/Dockerfile``).
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -149,6 +151,59 @@ def _verify_claude_local(ctx: CaseContext) -> None:
|
||||
raise AssertionError(f"Unexpected Claude install commands: {claude_calls}")
|
||||
|
||||
|
||||
def _expect_shell_exports(shell_file: Path, expected: dict[str, str]) -> None:
|
||||
"""Check exported values in a child process after sourcing an rc file.
|
||||
|
||||
Args:
|
||||
shell_file: Scratch shell configuration written by the init case.
|
||||
expected: Environment variables that init must export verbatim.
|
||||
|
||||
Raises:
|
||||
AssertionError: If sourcing fails or the exported values differ.
|
||||
"""
|
||||
# Clear inherited values so missing exports cannot accidentally pass. A
|
||||
# separate Python child also distinguishes assignments from real exports.
|
||||
env = {
|
||||
name: value
|
||||
for name, value in os.environ.items()
|
||||
if name not in expected and name not in {"BASH_ENV", "ENV"}
|
||||
}
|
||||
probe = (
|
||||
"import json, os, sys; "
|
||||
"print(json.dumps({name: os.environ.get(name) for name in sys.argv[1:]}))"
|
||||
)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-c",
|
||||
'. "$1" && "$2" -c "$3" "${@:4}"',
|
||||
"headroom-env-check",
|
||||
str(shell_file),
|
||||
sys.executable,
|
||||
probe,
|
||||
*expected,
|
||||
],
|
||||
env=env,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
timeout=10,
|
||||
)
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as exc:
|
||||
raise AssertionError(f"{shell_file.name} could not be sourced successfully") from exc
|
||||
try:
|
||||
actual = json.loads(result.stdout)
|
||||
except json.JSONDecodeError as exc:
|
||||
raise AssertionError(
|
||||
f"{shell_file.name} did not produce exported environment values"
|
||||
) from exc
|
||||
if actual != expected:
|
||||
raise AssertionError(f"{shell_file.name} exported {actual!r}; expected {expected!r}")
|
||||
|
||||
|
||||
def _verify_copilot_global(ctx: CaseContext) -> None:
|
||||
config = json.loads((ctx.home / ".copilot" / "config.json").read_text(encoding="utf-8"))
|
||||
if "SessionStart" not in config["hooks"]:
|
||||
@@ -158,15 +213,13 @@ def _verify_copilot_global(ctx: CaseContext) -> None:
|
||||
session_start = config["hooks"]["SessionStart"][0]["command"]
|
||||
_expect_hook_command(session_start, "init-user")
|
||||
|
||||
expected_env = {
|
||||
"COPILOT_PROVIDER_TYPE": "openai",
|
||||
"COPILOT_PROVIDER_BASE_URL": "http://127.0.0.1:9005/v1",
|
||||
"COPILOT_PROVIDER_WIRE_API": "completions",
|
||||
}
|
||||
for shell_file in (ctx.home / ".bashrc", ctx.home / ".zshrc", ctx.home / ".profile"):
|
||||
content = shell_file.read_text(encoding="utf-8")
|
||||
for literal in (
|
||||
'export COPILOT_PROVIDER_TYPE="openai"',
|
||||
'export COPILOT_PROVIDER_BASE_URL="http://127.0.0.1:9005/v1"',
|
||||
'export COPILOT_PROVIDER_WIRE_API="completions"',
|
||||
):
|
||||
if literal not in content:
|
||||
raise AssertionError(f"{shell_file.name} missing {literal!r}")
|
||||
_expect_shell_exports(shell_file, expected_env)
|
||||
|
||||
copilot_calls = [
|
||||
record["argv"] for record in _read_jsonl(ctx.shim_log) if record["tool"] == "copilot"
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
# OpenClaw 2026.9.3 requires Node >=24.16.0 (or >=26.1.0). Install the
|
||||
# OpenClaw 2026.10.6 requires Node >=24.22.1 <25 (or >=26.12.1). Install the
|
||||
# Node 24 LTS line alongside Python 3.11. Also install git for packages
|
||||
# that clone at install time.
|
||||
RUN apt-get update && \
|
||||
|
||||
@@ -10,7 +10,8 @@ PATH. `npm ci` does not support global installs, so diagnostics must also use
|
||||
`npm list --prefix /opt/wrap-tools`.
|
||||
|
||||
After editing a CLI version in `package.json`, regenerate the lockfile using
|
||||
Node 22 and npm 11.16.0 on Linux:
|
||||
Node 24.22.1+ within the Node 24 line and npm 11.16.0 on Linux (the pinned
|
||||
OpenClaw version no longer supports Node 22):
|
||||
|
||||
```sh
|
||||
cd e2e/wrap/tools
|
||||
@@ -34,4 +35,11 @@ to make a build pass.
|
||||
These are existing test tools, not new product dependencies. Codex is maintained
|
||||
by OpenAI; OpenClaw and its transitive dependencies retain their upstream
|
||||
maintainers. Their install surface includes registry downloads, native optional
|
||||
packages and lifecycle scripts, as before. Top-level CLI versions are unchanged.
|
||||
packages and lifecycle scripts, as before. OpenClaw 2026.10.6 and its fixed
|
||||
Undici override follow the upstream #4453 security repair.
|
||||
|
||||
The raw audit still reports npm 12.2.1's bundled ip-address and Undici copies.
|
||||
`npm-audit-exceptions.json` records the upstream-approved E2E-only risk
|
||||
acceptance, restricted to exact advisory/path/version combinations and expiring
|
||||
on 2026-11-15. Security CI rejects other findings and expired or stale entries;
|
||||
these exceptions are not a claim that the contained packages are patched.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"expires": "2026-11-15",
|
||||
"reason": "E2E harness only, never shipped in the wheel or SDK. npm 12.2.1 bundles undici 6.29.0 and ip-address 10.7.2; bundled copies ignore overrides and no newer npm release is available. OpenClaw is updated to 2026.10.6 and uses fixed Undici 8.12.3, so no OpenClaw path is excepted. Three further undici 6.x advisories (GHSA-2m5v-pch6-74hx, GHSA-qrxm-fqhp-jwvm, GHSA-9fm3-97px-rjf6) published after #4453 cover the same bundled copy. Recheck npm upstream and remove these exact-path exceptions by the existing expiry.",
|
||||
"advisories": {
|
||||
"GHSA-4qv8-2p9j-2685": {
|
||||
"node_modules/npm/node_modules/undici": "6.29.0"
|
||||
},
|
||||
"GHSA-xjj6-f33q-929c": {
|
||||
"node_modules/npm/node_modules/undici": "6.29.0"
|
||||
},
|
||||
"GHSA-rxp7-6hxx-x8q5": {
|
||||
"node_modules/npm/node_modules/ip-address": "10.7.2"
|
||||
},
|
||||
"GHSA-2m5v-pch6-74hx": {
|
||||
"node_modules/npm/node_modules/undici": "6.29.0"
|
||||
},
|
||||
"GHSA-qrxm-fqhp-jwvm": {
|
||||
"node_modules/npm/node_modules/undici": "6.29.0"
|
||||
},
|
||||
"GHSA-9fm3-97px-rjf6": {
|
||||
"node_modules/npm/node_modules/undici": "6.29.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+329
-302
File diff suppressed because it is too large
Load Diff
@@ -4,11 +4,15 @@
|
||||
"private": true,
|
||||
"description": "Locked CLI dependencies for the Docker wrap E2E harness",
|
||||
"dependencies": {
|
||||
"@openai/codex": "0.162.1",
|
||||
"openclaw": "2026.10.2"
|
||||
"@openai/codex": "0.163.0",
|
||||
"openclaw": "2026.10.6"
|
||||
},
|
||||
"overrides": {
|
||||
"@modelcontextprotocol/sdk": "1.32.1",
|
||||
"npm": "12.2.1"
|
||||
"npm": "12.2.1",
|
||||
"zod": "4.6.6",
|
||||
"openclaw": {
|
||||
"undici": "8.12.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ from typing import Any
|
||||
|
||||
from ._ort import ensure_ort_dylib_pinned
|
||||
from ._version import __version__ # noqa: F401
|
||||
from .offline import pin_litellm_cost_map_local
|
||||
|
||||
# Must run before anything can import `headroom._core`: on Windows the
|
||||
# Rust core resolves onnxruntime.dll at runtime (ort load-dynamic), and
|
||||
@@ -83,6 +84,12 @@ from ._version import __version__ # noqa: F401
|
||||
# ~microseconds. See `headroom/_ort.py` for the full story.
|
||||
ensure_ort_dylib_pinned()
|
||||
|
||||
# Under HEADROOM_OFFLINE, litellm must not fetch its pricing table from GitHub
|
||||
# at import time. Each litellm import in this package pins that itself; this
|
||||
# call also covers a host that imports litellm after Headroom. A no-op unless
|
||||
# the switch is set. See `headroom/offline.py`.
|
||||
pin_litellm_cost_map_local()
|
||||
|
||||
from .compress import ( # noqa: E402
|
||||
CompressConfig,
|
||||
CompressResult,
|
||||
|
||||
@@ -0,0 +1,494 @@
|
||||
"""Windows NTFS ACL implementation backing :mod:`headroom.fileperms`.
|
||||
|
||||
Python ships no ACL API, so this module talks to ``advapi32``/``kernel32``
|
||||
through ``ctypes`` directly rather than adding a third-party dependency
|
||||
(``pywin32``) for a handful of calls. Imported only on Windows; every public
|
||||
function fails closed (returns ``False``) on any error rather than raising,
|
||||
because the caller's contract (see :mod:`headroom.fileperms`) is "report
|
||||
whether owner-only protection took effect" — a partially-applied ACL that
|
||||
raised out of a logging setup path would be worse than one that silently
|
||||
reports failure and lets the caller warn.
|
||||
|
||||
Both entry points restrict a HANDLE, not a path: :func:`restrict_handle` for
|
||||
a file we hold open (its fd's handle is reopened via ``ReOpenFile`` for
|
||||
``WRITE_DAC``, which the CRT's own open does not request, with no path
|
||||
re-resolution and therefore no TOCTOU window), and :func:`restrict_path` for
|
||||
one we did not (rotated backups) — opened with ``FILE_FLAG_OPEN_REPARSE_POINT``
|
||||
so a symlink/junction at the path is restricted as the link itself rather
|
||||
than followed, mirroring the POSIX ``O_NOFOLLOW`` used for the same purpose.
|
||||
|
||||
The DACL this sets has exactly one entry: full control for the calling
|
||||
user's own SID, created fresh (not merged with the inherited DACL) and
|
||||
applied with ``PROTECTED_DACL_SECURITY_INFORMATION`` so the parent
|
||||
directory's inherited entries — which is what made the file readable in the
|
||||
first place — are dropped rather than left alongside the new entry. That is
|
||||
deliberately stricter than POSIX ``0600`` relative to an administrator:
|
||||
POSIX root bypasses file permissions outright, while this ACL does not carve
|
||||
out Administrators/SYSTEM, matching what "owner-only" says.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import msvcrt
|
||||
import os
|
||||
from ctypes import wintypes
|
||||
|
||||
_advapi32 = ctypes.WinDLL("advapi32", use_last_error=True) # type: ignore[attr-defined]
|
||||
_kernel32 = ctypes.WinDLL("kernel32", use_last_error=True) # type: ignore[attr-defined]
|
||||
|
||||
_SE_FILE_OBJECT = 1
|
||||
_DACL_SECURITY_INFORMATION = 0x00000004
|
||||
_PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000
|
||||
_NO_INHERITANCE = 0
|
||||
_SET_ACCESS = 2
|
||||
_ERROR_SUCCESS = 0
|
||||
_FILE_ALL_ACCESS = 0x001F01FF
|
||||
_TOKEN_QUERY = 0x0008
|
||||
_TokenUser = 1
|
||||
_WRITE_DAC = 0x00040000
|
||||
_READ_CONTROL = 0x00020000
|
||||
_OPEN_EXISTING = 3
|
||||
_CREATE_NEW = 1
|
||||
_GENERIC_WRITE = 0x40000000
|
||||
_ERROR_FILE_NOT_FOUND = 2
|
||||
_FILE_BEGIN = 0
|
||||
_FILE_ATTRIBUTE_NORMAL = 0x80
|
||||
_FILE_ATTRIBUTE_REPARSE_POINT = 0x400
|
||||
_FILE_SHARE_READ = 1
|
||||
_FILE_SHARE_WRITE = 2
|
||||
_FILE_SHARE_DELETE = 4
|
||||
_FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
|
||||
_INVALID_HANDLE_VALUE = wintypes.HANDLE(-1).value
|
||||
|
||||
|
||||
class _TRUSTEE_W(ctypes.Structure):
|
||||
pass
|
||||
|
||||
|
||||
_TRUSTEE_W._fields_ = [
|
||||
("pMultipleTrustee", ctypes.POINTER(_TRUSTEE_W)),
|
||||
("MultipleTrusteeOperation", ctypes.c_int),
|
||||
("TrusteeForm", ctypes.c_int),
|
||||
("TrusteeType", ctypes.c_int),
|
||||
("ptstrName", ctypes.c_void_p),
|
||||
]
|
||||
|
||||
|
||||
class _EXPLICIT_ACCESS_W(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("grfAccessPermissions", wintypes.DWORD),
|
||||
("grfAccessMode", ctypes.c_int),
|
||||
("grfInheritance", wintypes.DWORD),
|
||||
("Trustee", _TRUSTEE_W),
|
||||
]
|
||||
|
||||
|
||||
_advapi32.BuildTrusteeWithSidW.argtypes = [ctypes.POINTER(_TRUSTEE_W), ctypes.c_void_p]
|
||||
_advapi32.BuildTrusteeWithSidW.restype = None
|
||||
|
||||
_advapi32.SetEntriesInAclW.argtypes = [
|
||||
wintypes.ULONG,
|
||||
ctypes.POINTER(_EXPLICIT_ACCESS_W),
|
||||
ctypes.c_void_p,
|
||||
ctypes.POINTER(ctypes.c_void_p),
|
||||
]
|
||||
_advapi32.SetEntriesInAclW.restype = wintypes.DWORD
|
||||
|
||||
_advapi32.SetSecurityInfo.argtypes = [
|
||||
wintypes.HANDLE,
|
||||
ctypes.c_int,
|
||||
wintypes.DWORD,
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_void_p,
|
||||
]
|
||||
_advapi32.SetSecurityInfo.restype = wintypes.DWORD
|
||||
|
||||
_advapi32.GetSecurityInfo.argtypes = [
|
||||
wintypes.HANDLE,
|
||||
ctypes.c_int,
|
||||
wintypes.DWORD,
|
||||
ctypes.POINTER(ctypes.c_void_p),
|
||||
ctypes.POINTER(ctypes.c_void_p),
|
||||
ctypes.POINTER(ctypes.c_void_p),
|
||||
ctypes.POINTER(ctypes.c_void_p),
|
||||
ctypes.POINTER(ctypes.c_void_p),
|
||||
]
|
||||
_advapi32.GetSecurityInfo.restype = wintypes.DWORD
|
||||
|
||||
_advapi32.GetAclInformation.argtypes = [
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_void_p,
|
||||
wintypes.DWORD,
|
||||
ctypes.c_int,
|
||||
]
|
||||
_advapi32.GetAclInformation.restype = wintypes.BOOL
|
||||
|
||||
_advapi32.GetAce.argtypes = [ctypes.c_void_p, wintypes.DWORD, ctypes.POINTER(ctypes.c_void_p)]
|
||||
_advapi32.GetAce.restype = wintypes.BOOL
|
||||
|
||||
_advapi32.EqualSid.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||
_advapi32.EqualSid.restype = wintypes.BOOL
|
||||
|
||||
_advapi32.OpenProcessToken.argtypes = [
|
||||
wintypes.HANDLE,
|
||||
wintypes.DWORD,
|
||||
ctypes.POINTER(wintypes.HANDLE),
|
||||
]
|
||||
_advapi32.OpenProcessToken.restype = wintypes.BOOL
|
||||
|
||||
_advapi32.GetTokenInformation.argtypes = [
|
||||
wintypes.HANDLE,
|
||||
ctypes.c_int,
|
||||
ctypes.c_void_p,
|
||||
wintypes.DWORD,
|
||||
ctypes.POINTER(wintypes.DWORD),
|
||||
]
|
||||
_advapi32.GetTokenInformation.restype = wintypes.BOOL
|
||||
|
||||
_kernel32.GetCurrentProcess.restype = wintypes.HANDLE
|
||||
_kernel32.CloseHandle.argtypes = [wintypes.HANDLE]
|
||||
_kernel32.LocalFree.argtypes = [ctypes.c_void_p]
|
||||
_kernel32.ReOpenFile.argtypes = [wintypes.HANDLE, wintypes.DWORD, wintypes.DWORD, wintypes.DWORD]
|
||||
_kernel32.ReOpenFile.restype = wintypes.HANDLE
|
||||
_kernel32.CreateFileW.argtypes = [
|
||||
wintypes.LPCWSTR,
|
||||
wintypes.DWORD,
|
||||
wintypes.DWORD,
|
||||
ctypes.c_void_p,
|
||||
wintypes.DWORD,
|
||||
wintypes.DWORD,
|
||||
wintypes.HANDLE,
|
||||
]
|
||||
_kernel32.CreateFileW.restype = wintypes.HANDLE
|
||||
_kernel32.SetFilePointerEx.argtypes = [
|
||||
wintypes.HANDLE,
|
||||
ctypes.c_longlong,
|
||||
ctypes.POINTER(ctypes.c_longlong),
|
||||
wintypes.DWORD,
|
||||
]
|
||||
_kernel32.SetFilePointerEx.restype = wintypes.BOOL
|
||||
_kernel32.SetEndOfFile.argtypes = [wintypes.HANDLE]
|
||||
_kernel32.SetEndOfFile.restype = wintypes.BOOL
|
||||
|
||||
|
||||
class _ByHandleFileInformation(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("dwFileAttributes", wintypes.DWORD),
|
||||
("ftCreationTime", wintypes.FILETIME),
|
||||
("ftLastAccessTime", wintypes.FILETIME),
|
||||
("ftLastWriteTime", wintypes.FILETIME),
|
||||
("dwVolumeSerialNumber", wintypes.DWORD),
|
||||
("nFileSizeHigh", wintypes.DWORD),
|
||||
("nFileSizeLow", wintypes.DWORD),
|
||||
("nNumberOfLinks", wintypes.DWORD),
|
||||
("nFileIndexHigh", wintypes.DWORD),
|
||||
("nFileIndexLow", wintypes.DWORD),
|
||||
]
|
||||
|
||||
|
||||
_kernel32.GetFileInformationByHandle.argtypes = [
|
||||
wintypes.HANDLE,
|
||||
ctypes.POINTER(_ByHandleFileInformation),
|
||||
]
|
||||
_kernel32.GetFileInformationByHandle.restype = wintypes.BOOL
|
||||
|
||||
|
||||
class _AclSizeInformation(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("AceCount", wintypes.DWORD),
|
||||
("AclBytesInUse", wintypes.DWORD),
|
||||
("AclBytesFree", wintypes.DWORD),
|
||||
]
|
||||
|
||||
|
||||
class _AceHeader(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("AceType", ctypes.c_ubyte),
|
||||
("AceFlags", ctypes.c_ubyte),
|
||||
("AceSize", wintypes.WORD),
|
||||
]
|
||||
|
||||
|
||||
def _current_user_sid() -> tuple[ctypes.c_void_p, ctypes.Array[ctypes.c_char]]:
|
||||
"""The calling process's user SID, plus the buffer it lives in.
|
||||
|
||||
Caller must keep the buffer alive for as long as the SID pointer is used
|
||||
-- the SID is a view into it, not a copy.
|
||||
"""
|
||||
token = wintypes.HANDLE()
|
||||
if not _advapi32.OpenProcessToken(
|
||||
_kernel32.GetCurrentProcess(), _TOKEN_QUERY, ctypes.byref(token)
|
||||
):
|
||||
raise ctypes.WinError(ctypes.get_last_error()) # type: ignore[attr-defined]
|
||||
try:
|
||||
size = wintypes.DWORD(0)
|
||||
_advapi32.GetTokenInformation(token, _TokenUser, None, 0, ctypes.byref(size))
|
||||
buf = ctypes.create_string_buffer(size.value)
|
||||
if not _advapi32.GetTokenInformation(token, _TokenUser, buf, size, ctypes.byref(size)):
|
||||
raise ctypes.WinError(ctypes.get_last_error()) # type: ignore[attr-defined]
|
||||
# TOKEN_USER is { SID_AND_ATTRIBUTES { PSID Sid; DWORD Attributes; } };
|
||||
# the first pointer-sized field is the PSID.
|
||||
sid = ctypes.cast(buf, ctypes.POINTER(ctypes.c_void_p))[0]
|
||||
return ctypes.c_void_p(sid), buf
|
||||
finally:
|
||||
_kernel32.CloseHandle(token)
|
||||
|
||||
|
||||
def _apply_owner_only_dacl(handle: wintypes.HANDLE) -> bool:
|
||||
"""Replace *handle*'s DACL with a single owner-only entry.
|
||||
|
||||
*handle* must already carry ``WRITE_DAC``.
|
||||
"""
|
||||
try:
|
||||
sid, _buf = _current_user_sid()
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
trustee = _TRUSTEE_W()
|
||||
_advapi32.BuildTrusteeWithSidW(ctypes.byref(trustee), sid)
|
||||
entry = _EXPLICIT_ACCESS_W()
|
||||
entry.grfAccessPermissions = _FILE_ALL_ACCESS
|
||||
entry.grfAccessMode = _SET_ACCESS
|
||||
entry.grfInheritance = _NO_INHERITANCE
|
||||
entry.Trustee = trustee
|
||||
|
||||
new_dacl = ctypes.c_void_p()
|
||||
# Passing NULL for the existing-ACL argument builds a fresh ACL containing
|
||||
# only *entry*, rather than merging with whatever inherited entries the
|
||||
# file already had -- those inherited entries are exactly what made it
|
||||
# readable, so merging would defeat the point.
|
||||
if (
|
||||
_advapi32.SetEntriesInAclW(1, ctypes.byref(entry), None, ctypes.byref(new_dacl))
|
||||
!= _ERROR_SUCCESS
|
||||
):
|
||||
return False
|
||||
try:
|
||||
rc = _advapi32.SetSecurityInfo(
|
||||
handle,
|
||||
_SE_FILE_OBJECT,
|
||||
_DACL_SECURITY_INFORMATION | _PROTECTED_DACL_SECURITY_INFORMATION,
|
||||
None,
|
||||
None,
|
||||
new_dacl,
|
||||
None,
|
||||
)
|
||||
return bool(rc == _ERROR_SUCCESS)
|
||||
finally:
|
||||
_kernel32.LocalFree(new_dacl)
|
||||
|
||||
|
||||
def restrict_handle(fd: int) -> bool:
|
||||
"""Make the open file behind CRT descriptor *fd* owner-only.
|
||||
|
||||
The CRT's own ``CreateFileW`` call underneath ``os.open``/``open()`` does
|
||||
not request ``WRITE_DAC``, so this reopens the same file object (via
|
||||
``ReOpenFile`` -- no path involved, so nothing for a symlink to redirect)
|
||||
with that right, applies the DACL, and closes the reopened handle. *fd*
|
||||
itself is left exactly as the caller had it.
|
||||
"""
|
||||
try:
|
||||
original = wintypes.HANDLE(msvcrt.get_osfhandle(fd)) # type: ignore[attr-defined]
|
||||
except OSError:
|
||||
return False
|
||||
reopened = _kernel32.ReOpenFile(
|
||||
original,
|
||||
_WRITE_DAC | _READ_CONTROL,
|
||||
_FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,
|
||||
0,
|
||||
)
|
||||
if not reopened or reopened == _INVALID_HANDLE_VALUE:
|
||||
return False
|
||||
try:
|
||||
return _apply_owner_only_dacl(reopened)
|
||||
finally:
|
||||
_kernel32.CloseHandle(reopened)
|
||||
|
||||
|
||||
def restrict_path(path: str) -> bool:
|
||||
"""Make the file at *path* owner-only without following a symlink there.
|
||||
|
||||
For files this process did not open itself (rotated log backups).
|
||||
``FILE_FLAG_OPEN_REPARSE_POINT`` opens a symlink/junction as the link
|
||||
itself rather than its target, the Windows equivalent of the POSIX
|
||||
``O_NOFOLLOW`` the caller's own ``islink`` check already guards against
|
||||
on both platforms.
|
||||
"""
|
||||
handle = _kernel32.CreateFileW(
|
||||
path,
|
||||
_WRITE_DAC | _READ_CONTROL,
|
||||
_FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,
|
||||
None,
|
||||
_OPEN_EXISTING,
|
||||
_FILE_FLAG_OPEN_REPARSE_POINT,
|
||||
None,
|
||||
)
|
||||
if not handle or handle == _INVALID_HANDLE_VALUE:
|
||||
return False
|
||||
try:
|
||||
return _apply_owner_only_dacl(handle)
|
||||
finally:
|
||||
_kernel32.CloseHandle(handle)
|
||||
|
||||
|
||||
def open_no_follow(path: str, *, truncate: bool) -> int:
|
||||
"""Create-or-open *path* for append/truncate, refusing a symlink or
|
||||
junction there, and apply the owner-only DACL -- all against the one
|
||||
HANDLE this opens, so there is no window between checking the path and
|
||||
writing through it.
|
||||
|
||||
This is the primitive :func:`headroom.fileperms.open_owner_only` needs
|
||||
and plain ``os.open()`` cannot provide on Windows: the CRT open it wraps
|
||||
has no ``O_NOFOLLOW`` equivalent, so it silently follows a planted
|
||||
symlink/junction to whatever it points at, and anything opened that way
|
||||
-- including a later DACL change -- lands on the target, not the
|
||||
intended file. ``FILE_FLAG_OPEN_REPARSE_POINT`` makes this CreateFileW
|
||||
call open the reparse point itself rather than its target regardless of
|
||||
*disposition*, so the attribute check below sees the real thing even on
|
||||
the create-or-open path a planted link races against.
|
||||
|
||||
Raises ``OSError`` on any failure, including when *path* is a symlink or
|
||||
junction -- matching the POSIX ``O_NOFOLLOW`` contract this mirrors, and
|
||||
the caller's existing "failing closed is deliberate" policy.
|
||||
|
||||
Always opens with ``OPEN_EXISTING`` first, regardless of *truncate*.
|
||||
``CREATE_ALWAYS``/``OPEN_ALWAYS`` against an existing reparse point does
|
||||
not error or open the link -- it deletes it and creates a fresh regular
|
||||
file in its place, *before* this function ever gets a handle to inspect,
|
||||
so the refusal below would silently never fire for exactly the request
|
||||
(truncate) that most needs it. Truncating, when asked for, happens via
|
||||
``SetEndOfFile`` on the one handle this function opens, once that handle
|
||||
is confirmed not to be a reparse point -- never by asking ``CreateFileW``
|
||||
to recreate the path.
|
||||
"""
|
||||
access = _GENERIC_WRITE | _WRITE_DAC
|
||||
share = _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE
|
||||
flags = _FILE_FLAG_OPEN_REPARSE_POINT | _FILE_ATTRIBUTE_NORMAL
|
||||
|
||||
handle = _kernel32.CreateFileW(path, access, share, None, _OPEN_EXISTING, flags, None)
|
||||
if not handle or handle == _INVALID_HANDLE_VALUE:
|
||||
err = ctypes.get_last_error() # type: ignore[attr-defined]
|
||||
if err != _ERROR_FILE_NOT_FOUND:
|
||||
raise OSError(f"CreateFileW failed for {path!r}: error {err}")
|
||||
# Nothing there yet. CREATE_NEW fails outright instead of silently
|
||||
# opening whatever a symlink planted in the gap since the check
|
||||
# above left behind -- the same race OPEN_EXISTING already closed
|
||||
# for the file-exists case, closed here for the file-missing one.
|
||||
handle = _kernel32.CreateFileW(path, access, share, None, _CREATE_NEW, flags, None)
|
||||
if not handle or handle == _INVALID_HANDLE_VALUE:
|
||||
err = ctypes.get_last_error() # type: ignore[attr-defined]
|
||||
raise OSError(f"CreateFileW failed for {path!r}: error {err}")
|
||||
try:
|
||||
info = _ByHandleFileInformation()
|
||||
if not _kernel32.GetFileInformationByHandle(handle, ctypes.byref(info)):
|
||||
err = ctypes.get_last_error() # type: ignore[attr-defined]
|
||||
raise OSError(f"GetFileInformationByHandle failed for {path!r}: error {err}")
|
||||
if info.dwFileAttributes & _FILE_ATTRIBUTE_REPARSE_POINT:
|
||||
raise OSError(f"refusing to open {path!r}: it is a symlink or junction")
|
||||
if truncate:
|
||||
if not _kernel32.SetFilePointerEx(handle, 0, None, _FILE_BEGIN):
|
||||
err = ctypes.get_last_error() # type: ignore[attr-defined]
|
||||
raise OSError(f"SetFilePointerEx failed for {path!r}: error {err}")
|
||||
if not _kernel32.SetEndOfFile(handle):
|
||||
err = ctypes.get_last_error() # type: ignore[attr-defined]
|
||||
raise OSError(f"SetEndOfFile failed for {path!r}: error {err}")
|
||||
# Best-effort, like every other restrict_* call: a failure here does
|
||||
# not fail the open (see fileperms.verify_owner_only for why), but a
|
||||
# planted symlink always fails above regardless of this result.
|
||||
_apply_owner_only_dacl(handle)
|
||||
fd: int = msvcrt.open_osfhandle( # type: ignore[attr-defined]
|
||||
handle, os.O_APPEND if not truncate else os.O_TRUNC
|
||||
)
|
||||
return fd
|
||||
except BaseException:
|
||||
_kernel32.CloseHandle(handle)
|
||||
raise
|
||||
|
||||
|
||||
def verify_handle(fd: int) -> bool:
|
||||
"""Like :func:`verify_path`, for a file this process already holds open."""
|
||||
try:
|
||||
handle = wintypes.HANDLE(msvcrt.get_osfhandle(fd)) # type: ignore[attr-defined]
|
||||
except OSError:
|
||||
return False
|
||||
return _verify_handle(handle)
|
||||
|
||||
|
||||
def verify_path(path: str) -> bool:
|
||||
"""Re-read the DACL at *path* and confirm it grants access to exactly the
|
||||
calling user and no one else.
|
||||
|
||||
Independent of :func:`restrict_path`/:func:`restrict_handle`'s own
|
||||
success return: that return says the API calls reported success, this
|
||||
re-reads what is actually on the object now. Used to decide whether to
|
||||
warn, so the warning reflects the file in front of it rather than a
|
||||
static assumption about the platform. Only needs ``READ_CONTROL``, not
|
||||
``WRITE_DAC`` -- it never modifies the DACL.
|
||||
"""
|
||||
handle = _kernel32.CreateFileW(
|
||||
path,
|
||||
_READ_CONTROL,
|
||||
_FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,
|
||||
None,
|
||||
_OPEN_EXISTING,
|
||||
_FILE_FLAG_OPEN_REPARSE_POINT,
|
||||
None,
|
||||
)
|
||||
if not handle or handle == _INVALID_HANDLE_VALUE:
|
||||
return False
|
||||
try:
|
||||
return _verify_handle(handle)
|
||||
finally:
|
||||
_kernel32.CloseHandle(handle)
|
||||
|
||||
|
||||
def _verify_handle(handle: wintypes.HANDLE) -> bool:
|
||||
try:
|
||||
sid, _buf = _current_user_sid()
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
dacl = ctypes.c_void_p()
|
||||
sec_desc = ctypes.c_void_p()
|
||||
rc = _advapi32.GetSecurityInfo(
|
||||
handle,
|
||||
_SE_FILE_OBJECT,
|
||||
_DACL_SECURITY_INFORMATION,
|
||||
None,
|
||||
None,
|
||||
ctypes.byref(dacl),
|
||||
None,
|
||||
ctypes.byref(sec_desc),
|
||||
)
|
||||
if rc != _ERROR_SUCCESS:
|
||||
return False
|
||||
try:
|
||||
size_info = _AclSizeInformation()
|
||||
if not _advapi32.GetAclInformation(
|
||||
dacl,
|
||||
ctypes.byref(size_info),
|
||||
ctypes.sizeof(size_info),
|
||||
2, # AclSizeInformation
|
||||
):
|
||||
return False
|
||||
if size_info.AceCount != 1:
|
||||
return False
|
||||
ace_ptr = ctypes.c_void_p()
|
||||
if not _advapi32.GetAce(dacl, 0, ctypes.byref(ace_ptr)):
|
||||
return False
|
||||
# ACCESS_ALLOWED_ACE lays out as ACE_HEADER, then a DWORD access mask,
|
||||
# then the SID -- the SID starts right after those two fixed fields.
|
||||
ace_addr = ace_ptr.value
|
||||
if ace_addr is None:
|
||||
return False
|
||||
sid_offset = ctypes.sizeof(_AceHeader) + ctypes.sizeof(wintypes.DWORD)
|
||||
ace_sid = ctypes.c_void_p(ace_addr + sid_offset)
|
||||
return bool(_advapi32.EqualSid(ace_sid, sid))
|
||||
finally:
|
||||
# sec_desc, not dacl: GetSecurityInfo returns pointers into one
|
||||
# LocalAlloc'd block: freeing dacl (an offset into it, not its start)
|
||||
# is an invalid free. See cpython ctypes issue discussions on
|
||||
# GetSecurityInfo for the same gotcha.
|
||||
_kernel32.LocalFree(sec_desc)
|
||||
@@ -173,7 +173,7 @@ _PROFILES: dict[str, AgentSavingsProfile] = {
|
||||
# Coding posture: defer non-core tool schemas, dedupe re-reads, extend
|
||||
# lossy coverage when lossless found nothing, and NEVER lossy-compress a
|
||||
# file read (the agent patches exact bytes). CCR stays ON (unset) so any
|
||||
# lossy loss is recoverable. Effort router off; low block floor so modest
|
||||
# lossy loss is recoverable. Low block floor so modest
|
||||
# deltas are eligible.
|
||||
tool_search=True,
|
||||
cross_turn_dedup=True,
|
||||
|
||||
@@ -21,6 +21,7 @@ from collections.abc import AsyncIterator
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from headroom.offline import pin_litellm_cost_map_local
|
||||
from headroom.proxy.public_errors import client_message
|
||||
from headroom.utils import format_exception_message
|
||||
|
||||
@@ -67,6 +68,7 @@ try:
|
||||
import os as _os
|
||||
|
||||
_env_snapshot = set(_os.environ)
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
from litellm import acompletion
|
||||
from litellm.utils import supports_prompt_caching
|
||||
@@ -536,6 +538,7 @@ def _caller_key_travels_to(model: str, key: str) -> bool:
|
||||
if not key.startswith("sk-ant-"):
|
||||
return True
|
||||
try:
|
||||
pin_litellm_cost_map_local()
|
||||
from litellm import get_llm_provider
|
||||
|
||||
provider = (get_llm_provider(model)[1] or "").lower()
|
||||
|
||||
Vendored
+6
-1
@@ -49,13 +49,18 @@ class CompressionStoreBackend(Protocol):
|
||||
"""
|
||||
...
|
||||
|
||||
def set(self, hash_key: str, entry: CompressionEntry) -> None:
|
||||
def set(self, hash_key: str, entry: CompressionEntry) -> bool | None:
|
||||
"""Store an entry with the given hash key.
|
||||
|
||||
Args:
|
||||
hash_key: The unique hash identifying the entry.
|
||||
entry: The CompressionEntry to store.
|
||||
|
||||
Returns:
|
||||
``False`` when a backend that absorbs its errors did not store it
|
||||
(``CompressionStore.store`` then raises ``StorageError``);
|
||||
``None`` (or ``True``) otherwise.
|
||||
|
||||
Note:
|
||||
Overwrites any existing entry with the same key.
|
||||
"""
|
||||
|
||||
Vendored
+117
@@ -0,0 +1,117 @@
|
||||
"""Redis storage backend for CompressionStore: one CCR store for every replica.
|
||||
|
||||
A ``<<ccr:hash>>`` marker points at an original kept by whichever replica
|
||||
compressed it; behind a gateway that spreads requests across replicas, the
|
||||
retrieval can land anywhere. With ``HEADROOM_CCR_BACKEND=redis`` and
|
||||
``HEADROOM_REDIS_URL``, every replica reads and writes one store.
|
||||
|
||||
Each entry is one key, ``<prefix>:ccr:<hash>``, holding the entry as JSON and
|
||||
expiring when the entry does (``created_at + ttl``). A Redis error is a miss
|
||||
(see :mod:`headroom.cache.redis_client`): a retrieval then fails as it would for
|
||||
an expired entry, and compression never waits on Redis.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import time
|
||||
from dataclasses import asdict, fields
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from ..redis_client import Guard, connect, key_prefix
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..compression_store import CompressionEntry
|
||||
|
||||
|
||||
class RedisBackend:
|
||||
"""CCR entries in Redis, shared by every replica that points at it."""
|
||||
|
||||
#: Redis expires each entry with its TTL: CompressionStore neither caps nor
|
||||
#: sweeps this store (a per-replica cap would evict other replicas' entries).
|
||||
expires_entries = True
|
||||
|
||||
def __init__(self, url: str, client: Any = None) -> None:
|
||||
self._client = client if client is not None else connect(url, setting="HEADROOM_REDIS_URL")
|
||||
self._prefix = f"{key_prefix()}:ccr:"
|
||||
self._guard = Guard("CCR store")
|
||||
|
||||
def _key(self, hash_key: str) -> str:
|
||||
return self._prefix + hash_key
|
||||
|
||||
def get(self, hash_key: str) -> CompressionEntry | None:
|
||||
raw = self._guard.call("read", lambda: self._client.get(self._key(hash_key)), None)
|
||||
return None if raw is None else _decode(raw)
|
||||
|
||||
def set(self, hash_key: str, entry: CompressionEntry) -> bool:
|
||||
"""Whether Redis took the entry (an error is logged, not raised)."""
|
||||
remaining_ms = int((entry.created_at + entry.ttl - time.time()) * 1000)
|
||||
if remaining_ms <= 0:
|
||||
return False
|
||||
blob = json.dumps(asdict(entry))
|
||||
return bool(
|
||||
self._guard.call(
|
||||
"write", lambda: self._client.set(self._key(hash_key), blob, px=remaining_ms), None
|
||||
)
|
||||
)
|
||||
|
||||
def delete(self, hash_key: str) -> bool:
|
||||
return bool(self._guard.call("delete", lambda: self._client.delete(self._key(hash_key)), 0))
|
||||
|
||||
def exists(self, hash_key: str) -> bool:
|
||||
return bool(self._guard.call("read", lambda: self._client.exists(self._key(hash_key)), 0))
|
||||
|
||||
def clear(self) -> None:
|
||||
keys = self._scan()
|
||||
if keys:
|
||||
self._guard.call("delete", lambda: self._client.delete(*keys), 0)
|
||||
|
||||
def count(self) -> int:
|
||||
return len(self._scan())
|
||||
|
||||
def keys(self) -> list[str]:
|
||||
return [k[len(self._prefix) :] for k in self._scan()]
|
||||
|
||||
def items(self) -> list[tuple[str, CompressionEntry]]:
|
||||
out = []
|
||||
for hash_key in self.keys():
|
||||
entry = self.get(hash_key)
|
||||
if entry is not None:
|
||||
out.append((hash_key, entry))
|
||||
return out
|
||||
|
||||
def purge_expired(self, now: float | None = None) -> int:
|
||||
"""Redis has already dropped them."""
|
||||
return 0
|
||||
|
||||
def get_stats(self) -> dict[str, Any]:
|
||||
return {"backend_type": "redis", "entry_count": self.count()}
|
||||
|
||||
def _scan(self) -> list[str]:
|
||||
def scan() -> list[str]:
|
||||
return [
|
||||
k.decode() if isinstance(k, bytes) else k
|
||||
for k in self._client.scan_iter(match=_glob_escape(self._prefix) + "*", count=500)
|
||||
]
|
||||
|
||||
return self._guard.call("scan", scan, [])
|
||||
|
||||
|
||||
def _decode(raw: Any) -> CompressionEntry | None:
|
||||
"""An entry from its JSON, or ``None`` when it is not one (a miss)."""
|
||||
from ..compression_store import CompressionEntry
|
||||
|
||||
try:
|
||||
data = json.loads(raw)
|
||||
known = {f.name for f in fields(CompressionEntry)}
|
||||
entry = CompressionEntry(**{k: v for k, v in data.items() if k in known})
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
return None
|
||||
texts_ok = isinstance(entry.original_content, str) and isinstance(entry.compressed_content, str)
|
||||
times_ok = isinstance(entry.created_at, (int, float)) and isinstance(entry.ttl, int)
|
||||
return entry if texts_ok and times_ok else None
|
||||
|
||||
|
||||
def _glob_escape(text: str) -> str:
|
||||
"""``text`` matched literally in a SCAN pattern."""
|
||||
return "".join("\\" + c if c in "*?[]\\" else c for c in text)
|
||||
Vendored
+28
-5
@@ -76,6 +76,22 @@ def _extract_tool_result_content(msg: dict) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _carries_tool_result_text(msg: dict) -> bool:
|
||||
"""Whether any tool result in ``msg`` holds text (both formats)."""
|
||||
if msg.get("role") == "tool":
|
||||
results = [msg.get("content")]
|
||||
else:
|
||||
results = [
|
||||
b.get("content")
|
||||
for b in msg.get("content") or []
|
||||
if isinstance(b, dict) and b.get("type") == "tool_result"
|
||||
]
|
||||
return any(
|
||||
isinstance(c, str) or (isinstance(c, list) and _extract_text_from_blocks(c) is not None)
|
||||
for c in results
|
||||
)
|
||||
|
||||
|
||||
def _swap_tool_result_content(msg: dict, new_content: str) -> dict:
|
||||
"""Deep copy msg and replace tool result content with new_content."""
|
||||
new_msg = copy.deepcopy(msg)
|
||||
@@ -294,9 +310,10 @@ class CompressionCache:
|
||||
"""Count consecutive stable messages from the start.
|
||||
|
||||
A message is stable if it is a plain user/assistant/system message,
|
||||
an assistant message with tool_use blocks, or a tool_result whose
|
||||
content hash is already in the cache. The first unstable tool_result
|
||||
(cache miss) stops the count.
|
||||
an assistant message with tool_use blocks, a tool_result whose
|
||||
content hash is already in the cache, or a tool_result with no text
|
||||
(nothing to replay). The first unstable tool_result (cache miss)
|
||||
stops the count.
|
||||
|
||||
The trailing message is *always* excluded from the frozen prefix
|
||||
(cap of ``len(messages) - 1``). The trailing message represents
|
||||
@@ -319,9 +336,15 @@ class CompressionCache:
|
||||
h = self.content_hash(content)
|
||||
if h not in self._cache and h not in self._stable_hashes:
|
||||
break
|
||||
else:
|
||||
# tool_result with non-string content; treat as unstable
|
||||
elif _carries_tool_result_text(msg):
|
||||
# Text after a textless first tool_result: the cache
|
||||
# keys a message by its first one, so this text was
|
||||
# never stored and cannot be byte-replayed.
|
||||
break
|
||||
# A tool_result with no text at all (a ToolSearch
|
||||
# tool_reference list, an image) gives the cache nothing
|
||||
# to replay, so it is stable. As a miss it stopped the
|
||||
# count for the rest of the session.
|
||||
# Regular user/assistant/system messages and assistant+tool_use
|
||||
# are always stable — fall through.
|
||||
count += 1
|
||||
|
||||
Vendored
+89
-8
@@ -43,6 +43,7 @@ from contextvars import ContextVar
|
||||
from dataclasses import asdict, dataclass, field, replace
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from ..exceptions import StorageError
|
||||
from ..log_safety import describe_exception, safe_id
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -279,6 +280,14 @@ class CompressionStore:
|
||||
self._heap_rebuild_threshold = 0.5
|
||||
external_revision = getattr(self._backend, "external_revision", None)
|
||||
self._backend_revision_reader = external_revision if callable(external_revision) else None
|
||||
# A backend that expires entries itself and is shared by replicas
|
||||
# (Redis) is bounded by TTL, not by this process's max_entries: counting
|
||||
# it on every store would scan the shared keyspace, and evicting would
|
||||
# remove other replicas' live entries.
|
||||
self._backend_expires_entries = bool(getattr(self._backend, "expires_entries", False))
|
||||
# A shared store's totals, as this process contributed them since it
|
||||
# started: [original tokens stored, compressed tokens stored, retrievals].
|
||||
self._own_totals = [0, 0, 0]
|
||||
self._backend_revision = self._read_backend_revision()
|
||||
|
||||
@property
|
||||
@@ -329,6 +338,11 @@ class CompressionStore:
|
||||
|
||||
Returns:
|
||||
Hash key for retrieving this content.
|
||||
|
||||
Raises:
|
||||
StorageError: The backend did not keep the entry (a shared store
|
||||
refused the write or was unreachable). No hash is issued for
|
||||
it: the caller must keep the original rather than emit a marker.
|
||||
"""
|
||||
# Generate hash from original content. Default: SHA-256[:24] of the
|
||||
# original. When the caller provides `explicit_hash`, use it
|
||||
@@ -424,7 +438,8 @@ class CompressionStore:
|
||||
# turn a marker is re-encountered, so duplicate stores are common.
|
||||
existing = self._backend.get(hash_key)
|
||||
if existing is None:
|
||||
self._evict_if_needed()
|
||||
if not self._backend_expires_entries:
|
||||
self._evict_if_needed()
|
||||
else:
|
||||
# Hash already present. Different content means a true (extremely
|
||||
# rare with SHA256[:24]) collision; same content is a duplicate
|
||||
@@ -445,7 +460,18 @@ class CompressionStore:
|
||||
# Mark old heap entry as stale since we're replacing it.
|
||||
self._mark_heap_entries_stale()
|
||||
|
||||
self._backend.set(hash_key, entry)
|
||||
if self._backend.set(hash_key, entry) is False:
|
||||
# Only a backend that absorbs its errors (Redis) returns False;
|
||||
# it has logged why. A hash here would be a marker that never
|
||||
# resolves, and producers drop the original once they hold one.
|
||||
raise StorageError(
|
||||
f"CCR store did not keep hash={hash_key}; keep the original content"
|
||||
)
|
||||
if self._backend_expires_entries:
|
||||
if existing is None:
|
||||
self._own_totals[0] += entry.original_tokens
|
||||
self._own_totals[1] += entry.compressed_tokens
|
||||
return hash_key # no local index: Redis expires it
|
||||
# MEDIUM FIX #16: Add to eviction heap for O(log n) eviction
|
||||
heapq.heappush(self._eviction_heap, (entry.created_at, hash_key))
|
||||
heapq.heappush(
|
||||
@@ -485,8 +511,13 @@ class CompressionStore:
|
||||
|
||||
# Track access for feedback
|
||||
entry.record_access(query)
|
||||
# Update the backend with the modified entry
|
||||
self._backend.set(hash_key, entry)
|
||||
# Update the backend with the modified entry. Not a shared store:
|
||||
# writing the whole entry back per read races other replicas and
|
||||
# resends the original; retrieval events below stay per process.
|
||||
if self._backend_expires_entries:
|
||||
self._own_totals[2] += 1
|
||||
else:
|
||||
self._backend.set(hash_key, entry)
|
||||
|
||||
# Log retrieval event
|
||||
if self._enable_feedback:
|
||||
@@ -654,6 +685,25 @@ class CompressionStore:
|
||||
|
||||
def get_stats(self) -> dict[str, Any]:
|
||||
"""Get store statistics for monitoring."""
|
||||
if self._backend_expires_entries:
|
||||
# Totals over the store would read every replica's entries (a GET
|
||||
# each) under the lock retrievals take: a shared store reports the
|
||||
# entry count across replicas, and the totals this replica added
|
||||
# since it started ("totals_scope").
|
||||
backend_stats = self._backend.get_stats()
|
||||
with self._lock:
|
||||
original, compressed, retrievals = self._own_totals
|
||||
return {
|
||||
"entry_count": backend_stats["entry_count"],
|
||||
"max_entries": self._max_entries,
|
||||
"default_ttl_seconds": self._default_ttl,
|
||||
"total_original_tokens": original,
|
||||
"total_compressed_tokens": compressed,
|
||||
"total_retrievals": retrievals,
|
||||
"totals_scope": "this_replica",
|
||||
"event_count": len(self._retrieval_events),
|
||||
"backend": backend_stats,
|
||||
}
|
||||
with self._lock:
|
||||
# Clean expired entries
|
||||
self._clean_expired()
|
||||
@@ -704,10 +754,15 @@ class CompressionStore:
|
||||
|
||||
return ComponentStats(
|
||||
name="compression_store",
|
||||
entry_count=self._backend.count(),
|
||||
entry_count=backend_stats.get("entry_count", 0)
|
||||
if self._backend_expires_entries
|
||||
else self._backend.count(),
|
||||
size_bytes=bytes_used,
|
||||
budget_bytes=None, # No budget set yet
|
||||
hits=sum(1 for _, e in self._backend.items() if e.retrieval_count > 0),
|
||||
# A shared store would be read whole to count these.
|
||||
hits=0
|
||||
if self._backend_expires_entries
|
||||
else sum(1 for _, e in self._backend.items() if e.retrieval_count > 0),
|
||||
misses=0, # CompressionStore doesn't track misses directly
|
||||
evictions=0, # Would need to track this separately
|
||||
)
|
||||
@@ -868,6 +923,8 @@ class CompressionStore:
|
||||
|
||||
def _mark_heap_entries_stale(self) -> None:
|
||||
"""Record lazy tuples invalidated by deleting or replacing an entry."""
|
||||
if self._backend_expires_entries:
|
||||
return # no index kept for a self-expiring backend
|
||||
self._stale_heap_entries += 1
|
||||
self._stale_expiration_heap_entries += 1
|
||||
|
||||
@@ -892,6 +949,8 @@ class CompressionStore:
|
||||
|
||||
def _rebuild_heap_if_needed(self) -> None:
|
||||
"""Rebuild both indexes when either stale ratio reaches the threshold."""
|
||||
if self._backend_expires_entries:
|
||||
return # rebuilding would scan the shared store
|
||||
heap_size = len(self._eviction_heap)
|
||||
expiration_heap_size = len(self._expiration_heap)
|
||||
stale_ratio = self._stale_heap_entries / heap_size if heap_size else 0
|
||||
@@ -1155,8 +1214,10 @@ def _create_default_ccr_backend() -> CompressionStoreBackend | None:
|
||||
Default (env unset or "sqlite"): SQLiteBackend at workspace_dir()/ccr_store.db
|
||||
— restart-safe and shared across worker processes, which the
|
||||
session-scale 30-minute TTL assumes.
|
||||
"memory" opts back into the in-process dict. Other values load
|
||||
adapters via setuptools entry point 'headroom.ccr_backend'.
|
||||
"memory" opts back into the in-process dict. "redis" shares one store
|
||||
across replicas (HEADROOM_REDIS_URL; headroom.cache.backends.redis) unless a
|
||||
plugin registers that name. Other values load adapters via setuptools entry
|
||||
point 'headroom.ccr_backend'.
|
||||
Returns None to use InMemoryBackend.
|
||||
|
||||
Stateless mode (``--stateless`` / ``HEADROOM_STATELESS``) never opens the
|
||||
@@ -1171,6 +1232,13 @@ def _create_default_ccr_backend() -> CompressionStoreBackend | None:
|
||||
from ..paths import persistence_allowed
|
||||
|
||||
backend_type = (os.environ.get("HEADROOM_CCR_BACKEND") or "").strip().lower()
|
||||
session_store = os.environ.get("HEADROOM_COMPRESS_SESSION_STORE", "").strip()
|
||||
if not backend_type and session_store:
|
||||
# Replicas sharing compress sessions share the CCR store too: a marker
|
||||
# in a replayed transcript must resolve on whichever replica serves it.
|
||||
from .backends.redis import RedisBackend
|
||||
|
||||
return RedisBackend(session_store)
|
||||
if backend_type == "memory":
|
||||
return None
|
||||
if not backend_type or backend_type == "sqlite":
|
||||
@@ -1193,6 +1261,19 @@ def _create_default_ccr_backend() -> CompressionStoreBackend | None:
|
||||
|
||||
all_eps = entry_points(group="headroom.ccr_backend")
|
||||
ep = next((e for e in all_eps if e.name == backend_type), None)
|
||||
if ep is None and backend_type == "redis":
|
||||
# Built in: one store for every replica behind a gateway. A plugin
|
||||
# registered as "redis" still wins, above.
|
||||
from .backends.redis import RedisBackend
|
||||
|
||||
url = os.environ.get("HEADROOM_REDIS_URL", "").strip() or session_store
|
||||
if not url:
|
||||
logger.error(
|
||||
"HEADROOM_CCR_BACKEND=redis needs HEADROOM_REDIS_URL; using the "
|
||||
"in-process store, so a marker resolves only on the replica that made it"
|
||||
)
|
||||
return None
|
||||
return RedisBackend(url)
|
||||
if ep is None:
|
||||
logger.warning(
|
||||
"HEADROOM_CCR_BACKEND=%s but no entry point headroom.ccr_backend[%s]",
|
||||
|
||||
Vendored
+4
-4
@@ -421,9 +421,7 @@ class OpenAICacheOptimizer(BaseCacheOptimizer):
|
||||
leading = len(line) - len(line.lstrip())
|
||||
# Collapse multiple spaces in content (not indentation)
|
||||
content_part = " ".join(stripped.split())
|
||||
normalized_lines.append(
|
||||
" " * leading + content_part[leading:] if leading else content_part
|
||||
)
|
||||
normalized_lines.append(line[:leading] + content_part)
|
||||
else:
|
||||
normalized_lines.append("")
|
||||
|
||||
@@ -434,7 +432,9 @@ class OpenAICacheOptimizer(BaseCacheOptimizer):
|
||||
while "\n\n\n" in result:
|
||||
result = result.replace("\n\n\n", "\n\n")
|
||||
|
||||
return result.strip()
|
||||
# Lines are already right-stripped and blank lines are empty, so only
|
||||
# surrounding newlines remain; keep the first line's indentation.
|
||||
return result.strip("\n")
|
||||
|
||||
def _format_dynamic_section(
|
||||
self,
|
||||
|
||||
Vendored
+94
-25
@@ -563,12 +563,30 @@ def classify_history_relation(
|
||||
return _classify_history_canonical(current, previous)
|
||||
|
||||
|
||||
def cache_key_tools(tools: Any) -> Any:
|
||||
"""The Anthropic ``tools`` that count toward the prompt-cache key.
|
||||
|
||||
A ``defer_loading`` tool is kept out of the prompt until the model loads
|
||||
it, so adding one to ``tools`` leaves the cached prefix readable. Claude
|
||||
Code appends every tool its ToolSearch loads to ``tools``, still marked
|
||||
deferred; counting those would start a new lineage at frozen=0 after each
|
||||
load and re-run the whole history. Every other tool, and a tool whose
|
||||
``defer_loading`` is cleared, still counts. The Anthropic handler decides
|
||||
when to apply this (first-party upstream, ``HEADROOM_DEFERRED_TOOL_AFFINITY``).
|
||||
"""
|
||||
if not isinstance(tools, list):
|
||||
return tools
|
||||
return [t for t in tools if not (isinstance(t, dict) and t.get("defer_loading"))]
|
||||
|
||||
|
||||
def segment_fingerprint(value: Any) -> str:
|
||||
"""Stable hash for non-message provider cache-key segments.
|
||||
|
||||
Cache-control placement and transport annotations are deliberately ignored;
|
||||
semantic tool/model/thinking changes remain visible. The hash is affinity
|
||||
metadata only and is never used to reconstruct or forward request content.
|
||||
semantic tool/model/thinking changes remain visible. It hashes what it is
|
||||
given, so callers pass only what the provider keys its cache on (for
|
||||
Anthropic tools, :func:`cache_key_tools`). The hash is affinity metadata
|
||||
only and is never used to reconstruct or forward request content.
|
||||
"""
|
||||
canonical = _lineage_snapshot(_canonicalize_for_prefix_compare(value))
|
||||
encoded = json.dumps(
|
||||
@@ -1206,6 +1224,11 @@ class PrefixCacheTracker:
|
||||
# builds the manager.
|
||||
self.restored_from_disk = False
|
||||
self.restored_maturation_state: dict[str, Any] | None = None
|
||||
# Shared-store state (headroom.cache.shared_sessions): the write token
|
||||
# this tracker matches ("" when never shared) and the digests of the
|
||||
# messages known to be stored with it.
|
||||
self.shared_token = ""
|
||||
self.shared_digests: frozenset[str] = frozenset()
|
||||
|
||||
# Stats
|
||||
self._busts_avoided: int = 0
|
||||
@@ -1509,16 +1532,20 @@ class PrefixCacheTracker:
|
||||
|
||||
def is_expired_for_cache_ttl(self, cache_ttl_seconds: int | None) -> bool:
|
||||
"""Check expiry including the longest configured or observed cache lifetime."""
|
||||
return (time.time() - self._last_activity) > self.retention_seconds(cache_ttl_seconds)
|
||||
|
||||
def retention_seconds(self, cache_ttl_seconds: int | None = None) -> float:
|
||||
"""How long this tracker is kept after its last activity: the session
|
||||
TTL, or the longest configured or observed cache lifetime plus a margin."""
|
||||
observed_ttl = max(
|
||||
self._cache_ttl_seconds or 0,
|
||||
self.config.cache_ttl_seconds or 0,
|
||||
cache_ttl_seconds or 0,
|
||||
)
|
||||
retention = max(
|
||||
return max(
|
||||
self.config.session_ttl_seconds,
|
||||
observed_ttl + _CACHE_TTL_CLEANUP_MARGIN_SECONDS if observed_ttl else 0,
|
||||
)
|
||||
return (time.time() - self._last_activity) > retention
|
||||
|
||||
def observe_cache_ttl(self, cache_ttl_seconds: int | None) -> None:
|
||||
"""Remember the longest provider cache lifetime observed for this lineage."""
|
||||
@@ -2144,6 +2171,14 @@ class SessionTrackerStore:
|
||||
pairs mostly repeat the same messages, so this keeps the file near one
|
||||
copy of each conversation instead of up to eleven.
|
||||
"""
|
||||
meta, table = self._tracker_parts(key, tracker, session_id)
|
||||
return f'{{"meta":{json.dumps(meta)},"messages":[{",".join(table)}]}}'
|
||||
|
||||
def _tracker_parts(
|
||||
self, key: str, tracker: PrefixCacheTracker, session_id: str | None
|
||||
) -> tuple[dict[str, Any], list[str]]:
|
||||
"""A tracker as its metadata, whose message lists are indexes into the
|
||||
table, and the table: each distinct message once, as JSON."""
|
||||
index: dict[str, int] = {}
|
||||
memo: dict[int, list[int]] = {}
|
||||
|
||||
@@ -2172,7 +2207,7 @@ class SessionTrackerStore:
|
||||
"history": [[ref(snap), t] for snap, t in self._lineage_history.get(key, ())],
|
||||
"maturation": None if maturation is None else maturation.export_state(),
|
||||
}
|
||||
return f'{{"meta":{json.dumps(meta)},"messages":[{",".join(index)}]}}'
|
||||
return meta, list(index)
|
||||
|
||||
def load_state(self, path: str) -> int:
|
||||
"""Resume the trackers :meth:`save_state` wrote, before serving.
|
||||
@@ -2213,6 +2248,58 @@ class SessionTrackerStore:
|
||||
)
|
||||
return restored
|
||||
|
||||
def _decode_tracker(self, entry: Any, now: float) -> PrefixCacheTracker | None:
|
||||
"""One :meth:`_encode_tracker` entry as a tracker marked restored, or
|
||||
``None`` when it has expired. Raises on a malformed entry."""
|
||||
meta, table = entry["meta"], entry["messages"]
|
||||
tracker = PrefixCacheTracker(str(meta["provider"]), self._default_config)
|
||||
tracker._last_activity = float(meta["last_activity"])
|
||||
tracker.observe_cache_ttl(meta["cache_ttl"])
|
||||
# NaN or a future stamp would never expire.
|
||||
if tracker.is_expired or not tracker._last_activity <= now:
|
||||
return None
|
||||
(
|
||||
tracker._turn_number,
|
||||
tracker._cached_token_count,
|
||||
tracker._cached_message_count,
|
||||
tracker._last_original_messages,
|
||||
tracker._last_forwarded_messages,
|
||||
) = _decode_turn_state(table, meta["state"])
|
||||
tracker._turn_states = {int(t): _decode_turn_state(table, s) for t, s in meta["turns"]}
|
||||
tracker.restored_from_disk = True
|
||||
if meta["maturation"] is not None:
|
||||
from headroom.transforms.read_maturation import ReadMaturationManager
|
||||
|
||||
tracker.restored_maturation_state = ReadMaturationManager.validate_state(
|
||||
meta["maturation"]
|
||||
)
|
||||
return tracker
|
||||
|
||||
def encode_shared(
|
||||
self, key: str, tracker: PrefixCacheTracker
|
||||
) -> tuple[dict[str, Any], list[str]]:
|
||||
"""``tracker`` for another process (headroom.cache.shared_sessions): its
|
||||
metadata and its message table, each distinct message once, as JSON.
|
||||
Raises when its messages are not JSON."""
|
||||
return self._tracker_parts(key, tracker, None)
|
||||
|
||||
def decode_shared(self, meta: Any, messages: list[Any]) -> PrefixCacheTracker | None:
|
||||
"""The tracker :meth:`encode_shared` described, marked restored so its
|
||||
next turn seeds the compression cache from it; ``None`` when it has
|
||||
expired. Raises on malformed input. Does not install it."""
|
||||
if not isinstance(meta, dict):
|
||||
raise ValueError("tracker metadata is not an object")
|
||||
now = time.time()
|
||||
# Written on another host: a clock ahead of ours is not a future stamp.
|
||||
meta = {**meta, "last_activity": min(float(meta["last_activity"]), now)}
|
||||
return self._decode_tracker({"meta": meta, "messages": messages}, now)
|
||||
|
||||
def install(self, key: str, tracker: PrefixCacheTracker) -> None:
|
||||
"""Make ``tracker`` the one under ``key``. Call on the event loop, or
|
||||
from a worker thread only for a key already present (replacing a value
|
||||
does not resize the dict the loop may be iterating)."""
|
||||
self._trackers[key] = tracker
|
||||
|
||||
def _decode_state(self, data: Any) -> int:
|
||||
"""Validate the whole file first, then install it; a bad file installs nothing."""
|
||||
from headroom.cache.compression_store import CompressionEntry, get_compression_store
|
||||
@@ -2228,27 +2315,9 @@ class SessionTrackerStore:
|
||||
# Oldest first, so each family keeps its lineages in creation order.
|
||||
for entry in reversed(data["trackers"]):
|
||||
meta, table = entry["meta"], entry["messages"]
|
||||
tracker = PrefixCacheTracker(str(meta["provider"]), self._default_config)
|
||||
tracker._last_activity = float(meta["last_activity"])
|
||||
tracker.observe_cache_ttl(meta["cache_ttl"])
|
||||
# NaN or a future stamp would never expire.
|
||||
if tracker.is_expired or not tracker._last_activity <= now:
|
||||
tracker = self._decode_tracker(entry, now)
|
||||
if tracker is None:
|
||||
continue
|
||||
(
|
||||
tracker._turn_number,
|
||||
tracker._cached_token_count,
|
||||
tracker._cached_message_count,
|
||||
tracker._last_original_messages,
|
||||
tracker._last_forwarded_messages,
|
||||
) = _decode_turn_state(table, meta["state"])
|
||||
tracker._turn_states = {int(t): _decode_turn_state(table, s) for t, s in meta["turns"]}
|
||||
tracker.restored_from_disk = True
|
||||
if meta["maturation"] is not None:
|
||||
from headroom.transforms.read_maturation import ReadMaturationManager
|
||||
|
||||
tracker.restored_maturation_state = ReadMaturationManager.validate_state(
|
||||
meta["maturation"]
|
||||
)
|
||||
key = str(meta["key"])
|
||||
trackers[key] = tracker
|
||||
history = deque(
|
||||
|
||||
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
"""Redis connections for state that several Headroom replicas share.
|
||||
|
||||
The CCR store (``HEADROOM_CCR_BACKEND=redis``) and shared ``/v1/compress``
|
||||
sessions keep their keys under ``HEADROOM_REDIS_KEY_PREFIX`` (default
|
||||
``headroom``), so two deployments can share one Redis without sharing state.
|
||||
|
||||
Redis holds tool output and transcripts verbatim: it must be private to the
|
||||
deployment, with authentication and TLS (``rediss://``). Plain ``redis://`` to a
|
||||
host other than this machine is accepted with a warning.
|
||||
|
||||
Shared state is an optimisation of a request, never a condition for it: a Redis
|
||||
error is a miss, logged when it starts and when Redis is back, and Redis is not
|
||||
asked again for :data:`BACKOFF_SECONDS` after a connection failure, so an outage
|
||||
costs requests nothing but the sharing.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from typing import Any, TypeVar
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from headroom.exceptions import ConfigurationError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PREFIX_ENV = "HEADROOM_REDIS_KEY_PREFIX"
|
||||
#: Seconds Redis is skipped after a connection error.
|
||||
BACKOFF_SECONDS = 5.0
|
||||
#: Seconds a command may take. Commands carry small values (an entry, a few
|
||||
#: messages), so a slow one is an outage, not a large transfer.
|
||||
TIMEOUT_SECONDS = 1.0
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def key_prefix() -> str:
|
||||
return os.environ.get(PREFIX_ENV, "").strip() or "headroom"
|
||||
|
||||
|
||||
def connect(url: str, *, setting: str) -> Any:
|
||||
"""A client for ``url``. Raises :class:`ConfigurationError`, naming
|
||||
``setting``, when the URL is not Redis or the client is not installed.
|
||||
Does not connect: an unreachable Redis does not stop startup."""
|
||||
scheme = urlsplit(url).scheme
|
||||
if scheme not in ("redis", "rediss", "unix"):
|
||||
raise ConfigurationError(f"{setting} must be a redis://, rediss:// or unix:// URL")
|
||||
try:
|
||||
import redis
|
||||
except ImportError as exc:
|
||||
raise ConfigurationError(
|
||||
f"{setting} names Redis but the client is not installed: "
|
||||
"pip install 'headroom-ai[redis]'"
|
||||
) from exc
|
||||
from headroom.proxy.loopback_guard import is_loopback_host
|
||||
|
||||
host = urlsplit(url).hostname
|
||||
if scheme == "redis" and not is_loopback_host(host):
|
||||
logger.warning(
|
||||
"%s: plain redis:// to %s; Redis will hold tool output and transcripts, "
|
||||
"so use rediss:// with authentication on a private network",
|
||||
setting,
|
||||
host,
|
||||
)
|
||||
return redis.Redis.from_url(
|
||||
url, socket_timeout=TIMEOUT_SECONDS, socket_connect_timeout=TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
|
||||
class Guard:
|
||||
"""Runs Redis calls for one feature: an error is a miss, logged when that
|
||||
kind of call (``what``: read, write, ...) starts failing and when it works
|
||||
again; after a connection error Redis is skipped for :data:`BACKOFF_SECONDS`.
|
||||
Tracking each kind apart keeps a Redis that serves reads but refuses writes
|
||||
(``maxmemory`` with ``noeviction``) from logging on every request."""
|
||||
|
||||
def __init__(self, feature: str) -> None:
|
||||
import redis
|
||||
|
||||
self._feature = feature
|
||||
self._errors: tuple[type[BaseException], ...] = (redis.RedisError,)
|
||||
self._connection_errors = (redis.ConnectionError, redis.TimeoutError)
|
||||
self._lock = threading.Lock()
|
||||
self._skip_until = 0.0
|
||||
self._failing: set[str] = set()
|
||||
|
||||
def call(self, what: str, fn: Callable[[], T], default: T) -> T:
|
||||
if time.monotonic() < self._skip_until:
|
||||
return default
|
||||
try:
|
||||
result = fn()
|
||||
except self._errors as exc:
|
||||
with self._lock:
|
||||
if isinstance(exc, self._connection_errors):
|
||||
self._skip_until = time.monotonic() + BACKOFF_SECONDS
|
||||
if what not in self._failing:
|
||||
self._failing.add(what)
|
||||
logger.warning(
|
||||
"%s: Redis %s failed (%s: %s); carrying on without shared state",
|
||||
self._feature,
|
||||
what,
|
||||
type(exc).__name__,
|
||||
_redact(str(exc)),
|
||||
)
|
||||
return default
|
||||
if what in self._failing:
|
||||
with self._lock:
|
||||
if what in self._failing:
|
||||
self._failing.discard(what)
|
||||
logger.info("%s: Redis %s works again", self._feature, what)
|
||||
return result
|
||||
|
||||
|
||||
def _redact(message: str) -> str:
|
||||
"""``message`` with any URL credentials (``//user:password@``) masked."""
|
||||
return re.sub(r"//[^/@\s]*@", "//***@", message)
|
||||
Vendored
+12
-5
@@ -31,7 +31,14 @@ class CacheOptimizerRegistry:
|
||||
"""
|
||||
|
||||
_optimizers: dict[str, type[BaseCacheOptimizer]] = {}
|
||||
_instances: dict[str, BaseCacheOptimizer] = {}
|
||||
_instances: dict[tuple[str, int | None], BaseCacheOptimizer] = {}
|
||||
|
||||
@classmethod
|
||||
def _invalidate_instances(cls, name: str) -> None:
|
||||
"""Discard every configuration cached for this exact registration."""
|
||||
for key in list(cls._instances):
|
||||
if key[0] == name:
|
||||
del cls._instances[key]
|
||||
|
||||
@classmethod
|
||||
def register(
|
||||
@@ -57,8 +64,8 @@ class CacheOptimizerRegistry:
|
||||
f"Optimizer '{name}' already registered. Use override=True to replace."
|
||||
)
|
||||
cls._optimizers[name] = optimizer_class
|
||||
# Clear cached instance if exists
|
||||
cls._instances.pop(name, None)
|
||||
# Configured instances must not outlive their registered implementation.
|
||||
cls._invalidate_instances(name)
|
||||
|
||||
@classmethod
|
||||
def unregister(cls, name: str) -> None:
|
||||
@@ -69,7 +76,7 @@ class CacheOptimizerRegistry:
|
||||
name: Name to unregister
|
||||
"""
|
||||
cls._optimizers.pop(name, None)
|
||||
cls._instances.pop(name, None)
|
||||
cls._invalidate_instances(name)
|
||||
|
||||
@classmethod
|
||||
def get(
|
||||
@@ -109,7 +116,7 @@ class CacheOptimizerRegistry:
|
||||
raise KeyError(f"No optimizer registered for '{key}'. Available: {available}")
|
||||
|
||||
# Return cached instance if requested
|
||||
cache_key = f"{key}:{id(config)}" if config else key
|
||||
cache_key = (key, id(config) if config is not None else None)
|
||||
if cached and cache_key in cls._instances:
|
||||
return cls._instances[cache_key]
|
||||
|
||||
|
||||
Vendored
+159
@@ -0,0 +1,159 @@
|
||||
"""SQLite tier behind the content router's in-memory compression cache.
|
||||
|
||||
The router keeps recent results in a byte-budgeted LRU; this file holds the rest,
|
||||
so an entry the budget evicted comes back from disk instead of being compressed
|
||||
again (which costs a Kompress pass and can give different bytes, rewriting a
|
||||
cached prompt prefix). It also survives a restart and is shared by worker
|
||||
processes (WAL), like the CCR store; WAL needs a local filesystem.
|
||||
|
||||
Each router reads and writes under its own namespace (a digest of its config and
|
||||
the headroom version), so routers configured differently, or a restart with
|
||||
other settings, never serve each other's output. Results carrying a CCR marker
|
||||
are not written here: their originals live in the CCR store, on its own clock.
|
||||
|
||||
The file holds compressed tool output, so it follows the CCR store's rules:
|
||||
owner-only, ``workspace_dir()/compression_cache.db`` (``HEADROOM_COMPRESSION_CACHE_PATH``
|
||||
to move it), expired rows deleted on open, never opened in stateless mode, and
|
||||
``HEADROOM_COMPRESSION_CACHE_DISK=0`` keeps the cache in memory only. A database
|
||||
error is a miss, never a failed request.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from ..fileperms import connect_private_sqlite
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_SCHEMA = """
|
||||
CREATE TABLE IF NOT EXISTS results (
|
||||
k TEXT PRIMARY KEY,
|
||||
text TEXT NOT NULL,
|
||||
ratio REAL NOT NULL,
|
||||
strategy TEXT NOT NULL,
|
||||
expires REAL NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_results_expires ON results (expires);
|
||||
"""
|
||||
#: Expired rows are deleted every this many writes, and on open.
|
||||
_PURGE_EVERY = 1000
|
||||
|
||||
|
||||
class ResultStore:
|
||||
"""Compressed results by key; an entry expires ``ttl_seconds`` after it was
|
||||
last read or written. Thread-safe; several processes may share the file."""
|
||||
|
||||
def __init__(self, path: Path, ttl_seconds: float) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self._path = path
|
||||
self._ttl = ttl_seconds
|
||||
self._lock = threading.Lock()
|
||||
self._writes = 0
|
||||
self._warned = False
|
||||
self._db = connect_private_sqlite(
|
||||
path, what="compression cache", check_same_thread=False, isolation_level=None
|
||||
)
|
||||
self._db.execute("PRAGMA busy_timeout=5000")
|
||||
self._db.execute("PRAGMA journal_mode=WAL")
|
||||
self._db.execute("PRAGMA synchronous=NORMAL")
|
||||
self._db.executescript(_SCHEMA)
|
||||
# Sessions that ended while the proxy was down go now.
|
||||
self._db.execute("DELETE FROM results WHERE expires <= ?", (time.time(),))
|
||||
|
||||
def get(self, key: str) -> tuple[str, float, str] | None:
|
||||
now = time.time()
|
||||
try:
|
||||
with self._lock:
|
||||
row = self._db.execute(
|
||||
"SELECT text, ratio, strategy, expires FROM results "
|
||||
"WHERE k = ? AND expires > ?",
|
||||
(key, now),
|
||||
).fetchone()
|
||||
# Keep what a live session still reads; refresh at most every half ttl.
|
||||
if row is not None and row[3] - now < self._ttl / 2:
|
||||
self._db.execute(
|
||||
"UPDATE results SET expires = ? WHERE k = ?", (now + self._ttl, key)
|
||||
)
|
||||
except sqlite3.Error as exc:
|
||||
self._failed("read", exc)
|
||||
return None
|
||||
return None if row is None else (row[0], row[1], row[2])
|
||||
|
||||
def put(self, key: str, text: str, ratio: float, strategy: str) -> None:
|
||||
now = time.time()
|
||||
try:
|
||||
with self._lock:
|
||||
self._db.execute(
|
||||
"INSERT OR REPLACE INTO results (k, text, ratio, strategy, expires) "
|
||||
"VALUES (?, ?, ?, ?, ?)",
|
||||
(key, text, ratio, strategy, now + self._ttl),
|
||||
)
|
||||
self._writes += 1
|
||||
if self._writes % _PURGE_EVERY == 0:
|
||||
self._db.execute("DELETE FROM results WHERE expires <= ?", (now,))
|
||||
except sqlite3.Error as exc:
|
||||
self._failed("write", exc)
|
||||
|
||||
def touch(self, key: str) -> None:
|
||||
"""Keep ``key`` for another ttl (it is in use from memory)."""
|
||||
self._run("UPDATE results SET expires = ? WHERE k = ?", (time.time() + self._ttl, key))
|
||||
|
||||
def delete(self, key: str) -> None:
|
||||
self._run("DELETE FROM results WHERE k = ?", (key,))
|
||||
|
||||
def clear_prefix(self, prefix: str) -> None:
|
||||
"""Delete every row whose key starts with ``prefix`` (a router's namespace)."""
|
||||
self._run("DELETE FROM results WHERE substr(k, 1, ?) = ?", (len(prefix), prefix))
|
||||
|
||||
def _run(self, sql: str, args: tuple[object, ...]) -> None:
|
||||
try:
|
||||
with self._lock:
|
||||
self._db.execute(sql, args)
|
||||
except sqlite3.Error as exc:
|
||||
self._failed("write", exc)
|
||||
|
||||
def _failed(self, what: str, exc: sqlite3.Error) -> None:
|
||||
if not self._warned:
|
||||
self._warned = True
|
||||
logger.warning(
|
||||
"compression cache: %s of %s failed (%s); treating it as a miss. "
|
||||
"Check the disk, or set HEADROOM_COMPRESSION_CACHE_DISK=0.",
|
||||
what,
|
||||
self._path,
|
||||
exc,
|
||||
)
|
||||
|
||||
|
||||
def open_result_store(ttl_seconds: float) -> ResultStore | None:
|
||||
"""The disk tier, or ``None`` (memory only) in stateless mode, with
|
||||
``HEADROOM_COMPRESSION_CACHE_DISK=0``, or when the file cannot be opened."""
|
||||
from ..paths import persistence_allowed, workspace_dir
|
||||
|
||||
if os.environ.get("HEADROOM_COMPRESSION_CACHE_DISK", "1").strip().lower() in (
|
||||
"0",
|
||||
"false",
|
||||
"no",
|
||||
"off",
|
||||
):
|
||||
return None
|
||||
if not persistence_allowed("compression result cache (compression_cache.db)"):
|
||||
return None
|
||||
configured = os.environ.get("HEADROOM_COMPRESSION_CACHE_PATH", "").strip()
|
||||
path = Path(configured).expanduser() if configured else workspace_dir() / "compression_cache.db"
|
||||
try:
|
||||
return ResultStore(path, ttl_seconds)
|
||||
except (OSError, sqlite3.Error) as exc:
|
||||
logger.warning(
|
||||
"compression cache: cannot open %s (%s); keeping results in memory only. "
|
||||
"Set HEADROOM_COMPRESSION_CACHE_PATH to a writable file or "
|
||||
"HEADROOM_COMPRESSION_CACHE_DISK=0.",
|
||||
path,
|
||||
exc,
|
||||
)
|
||||
return None
|
||||
Vendored
+82
-19
@@ -36,6 +36,7 @@ Usage:
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Callable
|
||||
@@ -74,6 +75,10 @@ class CacheEntry:
|
||||
# Hash of the full messages for exact matching
|
||||
messages_hash: str = ""
|
||||
|
||||
# Cache namespace (provider, model, metadata) so entries never replay
|
||||
# across different provider/model/metadata contexts
|
||||
namespace: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class SemanticCacheConfig:
|
||||
@@ -122,7 +127,7 @@ class SemanticCache:
|
||||
# LRU cache: key -> CacheEntry
|
||||
self._cache: OrderedDict[str, CacheEntry] = OrderedDict()
|
||||
|
||||
# Exact hash index: messages_hash -> key
|
||||
# Exact hash index: namespace-scoped hash -> key
|
||||
self._hash_index: dict[str, str] = {}
|
||||
|
||||
# Statistics
|
||||
@@ -134,6 +139,7 @@ class SemanticCache:
|
||||
self,
|
||||
query: str,
|
||||
messages_hash: str | None = None,
|
||||
namespace: str = "",
|
||||
) -> CacheEntry | None:
|
||||
"""
|
||||
Look up a cached entry.
|
||||
@@ -141,6 +147,8 @@ class SemanticCache:
|
||||
Args:
|
||||
query: Query text to search for
|
||||
messages_hash: Optional exact hash for fast lookup
|
||||
namespace: Cache namespace (provider, model, metadata); entries are
|
||||
never returned outside their own namespace
|
||||
|
||||
Returns:
|
||||
CacheEntry if found, None otherwise
|
||||
@@ -149,13 +157,16 @@ class SemanticCache:
|
||||
|
||||
# Try exact hash match first
|
||||
if messages_hash and self.config.use_exact_matching:
|
||||
key = self._hash_index.get(messages_hash)
|
||||
index_key = self._combined_key(namespace, messages_hash)
|
||||
key = self._hash_index.get(index_key)
|
||||
if key and key in self._cache:
|
||||
entry = self._cache[key]
|
||||
# Verify the stored entry really belongs to this request. Guards
|
||||
# against a stale index mapping ever pointing at an entry that was
|
||||
# overwritten by a different conversation sharing the same key.
|
||||
if entry.messages_hash == messages_hash:
|
||||
# Verify the stored entry really belongs to this request and
|
||||
# namespace. Guards against a stale index mapping ever pointing
|
||||
# at an entry that was overwritten by a different conversation
|
||||
# sharing the same key, and against replaying a cached response
|
||||
# across provider/model/metadata contexts.
|
||||
if entry.messages_hash == messages_hash and entry.namespace == namespace:
|
||||
self._touch(key)
|
||||
self._hits += 1
|
||||
return entry
|
||||
@@ -173,7 +184,7 @@ class SemanticCache:
|
||||
# messages_hash above, which is context-complete and safe.
|
||||
if self._embedding_fn and query.strip():
|
||||
query_embedding = self._embedding_fn(query)
|
||||
best_match, best_similarity = self._find_similar(query_embedding)
|
||||
best_match, best_similarity = self._find_similar(query_embedding, namespace)
|
||||
|
||||
if best_similarity >= self.config.similarity_threshold:
|
||||
self._touch(best_match)
|
||||
@@ -188,6 +199,7 @@ class SemanticCache:
|
||||
query: str,
|
||||
response: Any,
|
||||
messages_hash: str | None = None,
|
||||
namespace: str = "",
|
||||
) -> str:
|
||||
"""
|
||||
Store a response in the cache.
|
||||
@@ -196,6 +208,7 @@ class SemanticCache:
|
||||
query: Query text
|
||||
response: Response to cache
|
||||
messages_hash: Optional exact hash for fast lookup
|
||||
namespace: Cache namespace (provider, model, metadata)
|
||||
|
||||
Returns:
|
||||
Cache key for the entry
|
||||
@@ -206,8 +219,11 @@ class SemanticCache:
|
||||
# a trailing user message ("continue", "yes", "run the tests") but differ
|
||||
# in earlier context must NOT collide on one query-derived slot and
|
||||
# overwrite each other. Fall back to the query hash only when no
|
||||
# messages_hash is supplied (e.g. embedding-only usage).
|
||||
key = messages_hash or self._generate_key(query)
|
||||
# messages_hash is supplied (e.g. embedding-only usage). The key always
|
||||
# includes the namespace so entries from different provider/model/
|
||||
# metadata contexts never share a slot.
|
||||
base = messages_hash or self._generate_key(query)
|
||||
key = self._combined_key(namespace, base)
|
||||
|
||||
# Evict if adding a NEW key would exceed capacity. Overwriting a key that
|
||||
# is already present is an in-place update that does not grow the map, so
|
||||
@@ -235,13 +251,14 @@ class SemanticCache:
|
||||
created_at=now,
|
||||
last_accessed=now,
|
||||
messages_hash=messages_hash or "",
|
||||
namespace=namespace,
|
||||
)
|
||||
|
||||
self._cache[key] = entry
|
||||
|
||||
# Index by hash for fast exact matching
|
||||
if messages_hash:
|
||||
self._hash_index[messages_hash] = key
|
||||
self._hash_index[self._combined_key(namespace, messages_hash)] = key
|
||||
|
||||
return key
|
||||
|
||||
@@ -250,7 +267,7 @@ class SemanticCache:
|
||||
if key in self._cache:
|
||||
entry = self._cache.pop(key)
|
||||
if entry.messages_hash:
|
||||
self._hash_index.pop(entry.messages_hash, None)
|
||||
self._hash_index.pop(self._combined_key(entry.namespace, entry.messages_hash), None)
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -276,12 +293,15 @@ class SemanticCache:
|
||||
def _find_similar(
|
||||
self,
|
||||
query_embedding: list[float],
|
||||
namespace: str = "",
|
||||
) -> tuple[str, float]:
|
||||
"""Find the most similar cached entry."""
|
||||
"""Find the most similar cached entry within the same namespace."""
|
||||
best_key = ""
|
||||
best_similarity = -1.0
|
||||
|
||||
for key, entry in self._cache.items():
|
||||
if entry.namespace != namespace:
|
||||
continue
|
||||
if not entry.embedding:
|
||||
continue
|
||||
|
||||
@@ -325,7 +345,7 @@ class SemanticCache:
|
||||
if self._cache:
|
||||
key, entry = self._cache.popitem(last=False)
|
||||
if entry.messages_hash:
|
||||
self._hash_index.pop(entry.messages_hash, None)
|
||||
self._hash_index.pop(self._combined_key(entry.namespace, entry.messages_hash), None)
|
||||
self._evictions += 1
|
||||
|
||||
def _cleanup_expired(self) -> None:
|
||||
@@ -343,7 +363,15 @@ class SemanticCache:
|
||||
for key in expired:
|
||||
entry = self._cache.pop(key)
|
||||
if entry.messages_hash:
|
||||
self._hash_index.pop(entry.messages_hash, None)
|
||||
self._hash_index.pop(self._combined_key(entry.namespace, entry.messages_hash), None)
|
||||
|
||||
def _combined_key(self, namespace: str, base: str) -> str:
|
||||
"""Hash a namespace with an exact messages_hash or query-derived key.
|
||||
|
||||
Combining namespace + base (separated by a NUL so a namespace can't be
|
||||
confused with a hash prefix) truncates like the existing hashes.
|
||||
"""
|
||||
return hashlib.sha256((namespace + "\0" + base).encode()).hexdigest()[:24]
|
||||
|
||||
def _generate_key(self, query: str) -> str:
|
||||
"""Generate a cache key for a query."""
|
||||
@@ -405,9 +433,15 @@ class SemanticCacheLayer:
|
||||
# Extract query for semantic matching
|
||||
query = context.query or self._extract_query(messages)
|
||||
messages_hash = self._compute_messages_hash(messages)
|
||||
namespace = self._compute_namespace(context)
|
||||
|
||||
# Unserializable context: never share cached responses across contexts,
|
||||
# so skip the cache and just delegate to the provider optimizer.
|
||||
if namespace is None:
|
||||
return self.provider_optimizer.optimize(messages, context, config)
|
||||
|
||||
# Check semantic cache
|
||||
cached = self.cache.get(query, messages_hash)
|
||||
cached = self.cache.get(query, messages_hash, namespace)
|
||||
if cached:
|
||||
return CacheResult(
|
||||
messages=messages,
|
||||
@@ -440,15 +474,24 @@ class SemanticCacheLayer:
|
||||
Args:
|
||||
messages: Original messages
|
||||
response: Response from LLM
|
||||
context: Optional context with query
|
||||
context: Optional context with query. Pass the same OptimizationContext
|
||||
used for `process`; omitting it stores under the unscoped
|
||||
namespace, which only matches lookups whose context also has
|
||||
empty provider, model and metadata.
|
||||
|
||||
Returns:
|
||||
Cache key
|
||||
"""
|
||||
query = (context.query if context else None) or self._extract_query(messages)
|
||||
messages_hash = self._compute_messages_hash(messages)
|
||||
namespace = self._compute_namespace(context)
|
||||
|
||||
return self.cache.put(query, response, messages_hash)
|
||||
# Unserializable context: don't store anything that could be replayed
|
||||
# for a different provider/model/metadata.
|
||||
if namespace is None:
|
||||
return ""
|
||||
|
||||
return self.cache.put(query, response, messages_hash, namespace)
|
||||
|
||||
def get_stats(self) -> dict[str, Any]:
|
||||
"""Get combined statistics."""
|
||||
@@ -457,6 +500,28 @@ class SemanticCacheLayer:
|
||||
"provider_optimizer": self.provider_optimizer.name,
|
||||
}
|
||||
|
||||
def _compute_namespace(self, context: OptimizationContext | None) -> str | None:
|
||||
"""Compute the cache namespace from provider, model, and metadata.
|
||||
|
||||
request_id and timestamp are deliberately excluded so they never affect
|
||||
matching. Returns None when the context isn't JSON-serializable (e.g.
|
||||
unserializable metadata), so callers skip lookup/storage rather than
|
||||
replaying entries across contexts.
|
||||
"""
|
||||
if context is None:
|
||||
context = OptimizationContext()
|
||||
try:
|
||||
return json.dumps(
|
||||
{
|
||||
"provider": context.provider,
|
||||
"model": context.model,
|
||||
"metadata": context.metadata,
|
||||
},
|
||||
sort_keys=True,
|
||||
)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
def _extract_query(self, messages: list[dict[str, Any]]) -> str:
|
||||
"""Extract the last user query from messages."""
|
||||
for msg in reversed(messages):
|
||||
@@ -473,8 +538,6 @@ class SemanticCacheLayer:
|
||||
|
||||
def _compute_messages_hash(self, messages: list[dict[str, Any]]) -> str:
|
||||
"""Compute a hash of all messages."""
|
||||
import json
|
||||
|
||||
try:
|
||||
content = json.dumps(messages, sort_keys=True)
|
||||
return hashlib.sha256(content.encode()).hexdigest()[:24]
|
||||
|
||||
Vendored
+276
@@ -0,0 +1,276 @@
|
||||
"""Session-aware ``/v1/compress`` state shared by several Headroom replicas.
|
||||
|
||||
A compress session's state is its prefix tracker: the transcript it was last
|
||||
given and the one it returned, which every later turn must replay byte for byte
|
||||
so the provider's prompt cache holds. In memory, only the replica that served
|
||||
the last turn has it, so a gateway running several replicas must pin each
|
||||
session to one (``session_affinity``).
|
||||
|
||||
With ``HEADROOM_COMPRESS_SESSION_STORE=redis://...`` every replica also keeps
|
||||
each session in Redis, and any replica can serve its next turn. Per session:
|
||||
|
||||
* ``<prefix>:session:{<digest>}:msgs``, a hash of message digest to message
|
||||
JSON. The original and returned transcripts mostly share messages, and each
|
||||
turn mostly repeats the last one's, so each message is stored once and a turn
|
||||
writes only the messages Redis does not have yet: what the turn added, and
|
||||
any message whose bytes changed (a moved cache marker, an edit, a compaction);
|
||||
* ``<prefix>:session:{<digest>}:meta``, the tracker's counters and its
|
||||
transcripts as lists of digests (``m``), and a write token (``t``).
|
||||
|
||||
Before a turn a replica reads the token (one small ``HGET``). When another
|
||||
replica has written since, it reads the metadata and only the messages it does
|
||||
not already hold, and the turn seeds its compression cache from that tracker as
|
||||
after a restart (:func:`~headroom.cache.prefix_tracker.seed_restored_compression_cache`).
|
||||
After the turn it writes the new messages, then the metadata if the token is
|
||||
still the one it read and every message it references is stored, checked in
|
||||
one script (compare-and-set): a random token, so a lost key or a failover
|
||||
cannot leave a replica believing stale state is current. A missing key
|
||||
resets the replica, whose next write stores the session whole again. Fetched
|
||||
messages are checked against their digests. Both keys expire with the tracker.
|
||||
|
||||
A Redis error never fails a turn (:mod:`headroom.cache.redis_client`): the
|
||||
replica serves from its own memory, as without the store. CCR originals behind
|
||||
the markers in these transcripts live in the shared CCR store, which this
|
||||
setting selects too unless ``HEADROOM_CCR_BACKEND`` names another. Requires the
|
||||
``redis`` extra.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from .redis_client import Guard, connect, key_prefix
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .prefix_tracker import PrefixCacheTracker, SessionTrackerStore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
STORE_ENV = "HEADROOM_COMPRESS_SESSION_STORE"
|
||||
#: Messages per HSET/HMGET, so no single command carries a whole transcript.
|
||||
_CHUNK = 256
|
||||
|
||||
# Install ARGV[2] as the token and ARGV[3] as the metadata if the token is still
|
||||
# ARGV[1] ("" when the key must not exist) and the messages hash (KEYS[2]) holds
|
||||
# every message the metadata references (ARGV[5:], including those this write
|
||||
# just sent: Redis can evict the hash between those writes and this script).
|
||||
# 1 on success, 0 when another replica wrote first, 2 when the messages hash
|
||||
# lost one.
|
||||
_CAS = """
|
||||
local t = redis.call('HGET', KEYS[1], 't') or ''
|
||||
if t ~= ARGV[1] then return 0 end
|
||||
for i = 5, #ARGV do
|
||||
if redis.call('HEXISTS', KEYS[2], ARGV[i]) == 0 then return 2 end
|
||||
end
|
||||
redis.call('HSET', KEYS[1], 't', ARGV[2], 'm', ARGV[3])
|
||||
redis.call('PEXPIRE', KEYS[1], ARGV[4])
|
||||
return 1
|
||||
"""
|
||||
|
||||
_FAILED = object()
|
||||
|
||||
|
||||
class SharedSessions:
|
||||
"""Compress-session trackers in Redis, beside the in-memory store."""
|
||||
|
||||
def __init__(self, client: Any) -> None:
|
||||
self._client = client
|
||||
self._cas = client.register_script(_CAS)
|
||||
self._guard = Guard("compress sessions")
|
||||
self._prefix = f"{key_prefix()}:session:"
|
||||
|
||||
def fetch(
|
||||
self, store: SessionTrackerStore, key: str, local: PrefixCacheTracker | None
|
||||
) -> PrefixCacheTracker | None:
|
||||
"""The session's tracker when another replica wrote a newer one than
|
||||
``local``, decoded but not installed; else ``None``."""
|
||||
meta_key, msgs_key = self._keys(key)
|
||||
token = self._guard.call("read", lambda: self._client.hget(meta_key, "t"), _FAILED)
|
||||
if token is _FAILED:
|
||||
return None
|
||||
if token is None:
|
||||
if local is not None: # lost or expired: the next write stores it whole
|
||||
local.shared_token, local.shared_digests = "", frozenset()
|
||||
return None
|
||||
try:
|
||||
if local is not None and _text(token) == local.shared_token:
|
||||
return None
|
||||
except UnicodeDecodeError:
|
||||
return self._drop(local, meta_key, msgs_key)
|
||||
row = self._guard.call("read", lambda: self._client.hmget(meta_key, "t", "m"), None)
|
||||
if row is None:
|
||||
return None
|
||||
if row[0] is None: # expired between the two reads
|
||||
return None
|
||||
try:
|
||||
token = _text(row[0])
|
||||
except UnicodeDecodeError:
|
||||
return self._drop(local, meta_key, msgs_key)
|
||||
try:
|
||||
meta = json.loads(_text(row[1]))
|
||||
digests = meta.pop("table")
|
||||
if not isinstance(digests, list) or not all(isinstance(d, str) for d in digests):
|
||||
raise ValueError("table is not a list of digests")
|
||||
except (TypeError, ValueError, KeyError, AttributeError, IndexError):
|
||||
return self._unusable(local, token, "metadata", meta_key)
|
||||
held = self._held(store, key, local)
|
||||
missing = [d for d in dict.fromkeys(digests) if d not in held]
|
||||
for start in range(0, len(missing), _CHUNK):
|
||||
part = missing[start : start + _CHUNK]
|
||||
values = self._guard.call(
|
||||
"read", functools.partial(self._client.hmget, msgs_key, part), None
|
||||
)
|
||||
if values is None:
|
||||
return None
|
||||
for digest, value in zip(part, values, strict=True):
|
||||
try:
|
||||
text = None if value is None else _text(value)
|
||||
except UnicodeDecodeError:
|
||||
text = None
|
||||
if text is None or _digest(text) != digest:
|
||||
return self._unusable(local, token, "messages", msgs_key)
|
||||
held[digest] = text
|
||||
try:
|
||||
tracker = store.decode_shared(meta, [json.loads(held[d]) for d in digests])
|
||||
except (TypeError, ValueError, KeyError, AttributeError, OverflowError):
|
||||
return self._unusable(local, token, "metadata", meta_key)
|
||||
if tracker is None:
|
||||
logger.info("compress sessions: shared state for %s has expired", meta_key)
|
||||
return None
|
||||
tracker.shared_token, tracker.shared_digests = token, frozenset(digests)
|
||||
return tracker
|
||||
|
||||
@staticmethod
|
||||
def _unusable(
|
||||
local: PrefixCacheTracker | None, token: str, what: str, name: str
|
||||
) -> PrefixCacheTracker | None:
|
||||
"""Shared state this replica cannot use (evicted, corrupt or altered):
|
||||
keep its own, and claim the current token with no messages known to be
|
||||
stored, so its next write replaces the session whole."""
|
||||
logger.warning("compress sessions: unusable %s in %s; this replica rewrites it", what, name)
|
||||
if local is not None:
|
||||
local.shared_token, local.shared_digests = token, frozenset()
|
||||
return None
|
||||
|
||||
def _drop(
|
||||
self, local: PrefixCacheTracker | None, meta_key: str, msgs_key: str
|
||||
) -> PrefixCacheTracker | None:
|
||||
"""A token that is not text cannot be claimed: delete the session, so
|
||||
the next write stores it whole."""
|
||||
logger.warning("compress sessions: corrupt token in %s; deleting the session", meta_key)
|
||||
self._guard.call("write", lambda: self._client.delete(meta_key, msgs_key), 0)
|
||||
if local is not None:
|
||||
local.shared_token, local.shared_digests = "", frozenset()
|
||||
return None
|
||||
|
||||
def publish(self, store: SessionTrackerStore, key: str, tracker: PrefixCacheTracker) -> None:
|
||||
"""Write the messages Redis lacks, then the metadata unless another
|
||||
replica wrote since ``tracker`` was read."""
|
||||
try:
|
||||
meta, table = store.encode_shared(key, tracker)
|
||||
except (TypeError, ValueError) as exc: # messages that are not JSON
|
||||
logger.debug("compress sessions: tracker not shareable (%s)", exc)
|
||||
return
|
||||
digests = [_digest(m) for m in table]
|
||||
meta["table"] = digests
|
||||
meta_json = json.dumps(meta)
|
||||
ttl_ms = max(1000, int(tracker.retention_seconds() * 1000))
|
||||
meta_key, msgs_key = self._keys(key)
|
||||
referenced = sorted(set(digests))
|
||||
|
||||
def write(known: frozenset[str]) -> tuple[int, str]:
|
||||
new = [(d, m) for d, m in zip(digests, table, strict=True) if d not in known]
|
||||
token = uuid.uuid4().hex
|
||||
pipe = self._client.pipeline(transaction=False)
|
||||
for start in range(0, len(new), _CHUNK):
|
||||
pipe.hset(msgs_key, mapping=dict(new[start : start + _CHUNK]))
|
||||
pipe.pexpire(msgs_key, ttl_ms)
|
||||
pipe.execute()
|
||||
args = [tracker.shared_token, token, meta_json, ttl_ms, *referenced]
|
||||
return int(self._cas(keys=[meta_key, msgs_key], args=args)), token
|
||||
|
||||
result = self._guard.call("write", lambda: write(tracker.shared_digests), None)
|
||||
if result is not None and result[0] == 2:
|
||||
# The messages hash lost entries (evicted on its own): store it whole.
|
||||
result = self._guard.call("write", lambda: write(frozenset()), None)
|
||||
if result is None:
|
||||
return
|
||||
written, token = result
|
||||
if written == 1:
|
||||
tracker.shared_token, tracker.shared_digests = token, frozenset(digests)
|
||||
self._prune(msgs_key, set(digests))
|
||||
elif written == 2:
|
||||
# Evicted again during the whole rewrite: publish nothing, so no
|
||||
# replica takes a session it cannot replay; the next turn retries.
|
||||
logger.warning("compress sessions: messages of %s evicted while writing", meta_key)
|
||||
elif written == 0:
|
||||
# Two replicas ran turns of one session at once, which the caller's
|
||||
# contract excludes; the next turn takes the state that won.
|
||||
logger.warning("compress sessions: another replica wrote %s first", meta_key)
|
||||
|
||||
def _prune(self, msgs_key: str, referenced: set[str]) -> None:
|
||||
"""Drop messages no transcript references (moved markers, edits,
|
||||
compactions) once they outnumber the referenced ones."""
|
||||
size = self._guard.call("write", lambda: int(self._client.hlen(msgs_key)), 0)
|
||||
if size <= 2 * len(referenced):
|
||||
return
|
||||
|
||||
def prune() -> None:
|
||||
stale = [k for k in map(_text, self._client.hkeys(msgs_key)) if k not in referenced]
|
||||
for start in range(0, len(stale), _CHUNK):
|
||||
self._client.hdel(msgs_key, *stale[start : start + _CHUNK])
|
||||
|
||||
self._guard.call("write", prune, None)
|
||||
|
||||
def _keys(self, key: str) -> tuple[str, str]:
|
||||
# One hash tag: the compare-and-set script names both keys, which Redis
|
||||
# Cluster allows only within one slot.
|
||||
base = f"{self._prefix}{{{hashlib.blake2b(key.encode(), digest_size=16).hexdigest()}}}"
|
||||
return f"{base}:meta", f"{base}:msgs"
|
||||
|
||||
@staticmethod
|
||||
def _held(
|
||||
store: SessionTrackerStore, key: str, local: PrefixCacheTracker | None
|
||||
) -> dict[str, str]:
|
||||
"""The messages this replica already holds for the session, by digest."""
|
||||
if local is None:
|
||||
return {}
|
||||
try:
|
||||
_, table = store.encode_shared(key, local)
|
||||
except (TypeError, ValueError):
|
||||
return {}
|
||||
return {_digest(m): m for m in table}
|
||||
|
||||
|
||||
def _digest(message_json: str) -> str:
|
||||
return hashlib.blake2b(message_json.encode(), digest_size=16).hexdigest()
|
||||
|
||||
|
||||
def _text(value: Any) -> str:
|
||||
return value.decode() if isinstance(value, bytes) else str(value)
|
||||
|
||||
|
||||
def open_shared_sessions() -> SharedSessions | None:
|
||||
"""The shared store ``HEADROOM_COMPRESS_SESSION_STORE`` names, or ``None``.
|
||||
|
||||
Raises :class:`~headroom.exceptions.ConfigurationError` when it is set but
|
||||
unusable, so a replica meant to share sessions never starts without it."""
|
||||
url = os.environ.get(STORE_ENV, "").strip()
|
||||
if not url:
|
||||
return None
|
||||
client = connect(url, setting=STORE_ENV)
|
||||
ccr = (os.environ.get("HEADROOM_CCR_BACKEND") or "").strip().lower()
|
||||
if ccr not in ("", "redis"):
|
||||
logger.warning(
|
||||
"%s is set but HEADROOM_CCR_BACKEND=%s: CCR markers in a session's "
|
||||
"transcript resolve only on the replica that made them",
|
||||
STORE_ENV,
|
||||
ccr,
|
||||
)
|
||||
return SharedSessions(client)
|
||||
Vendored
+14
-5
@@ -101,6 +101,8 @@ def resolve_learned_ttl(provider: str, model: str) -> int | None:
|
||||
``"provider/model"`` first, then ``"provider"``. Cached by mtime so a hot-path
|
||||
call is a dict lookup. Best-effort: returns None on any error, so the caller
|
||||
falls back to its own default (config TTL for CC, static default elsewhere).
|
||||
Invalid table shapes are ignored; invalid model values fall through to the
|
||||
provider fallback. Only positive, finite TTLs (not booleans) are accepted.
|
||||
"""
|
||||
global _learned_cache, _learned_mtime
|
||||
path = _learned_path()
|
||||
@@ -108,17 +110,24 @@ def resolve_learned_ttl(provider: str, model: str) -> int | None:
|
||||
mt = os.path.getmtime(path)
|
||||
if _learned_cache is None or mt != _learned_mtime:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
_learned_cache = json.load(f)
|
||||
loaded = json.load(f)
|
||||
_learned_cache = loaded if isinstance(loaded, dict) else {}
|
||||
_learned_mtime = mt
|
||||
except Exception:
|
||||
return None
|
||||
table = _learned_cache or {}
|
||||
for key in (f"{provider}/{model}", provider):
|
||||
v = table.get(key)
|
||||
if isinstance(v, dict) and isinstance(v.get("ttl_seconds"), int | float):
|
||||
return int(v["ttl_seconds"])
|
||||
if isinstance(v, int | float):
|
||||
return int(v)
|
||||
if isinstance(v, dict):
|
||||
v = v.get("ttl_seconds")
|
||||
if isinstance(v, bool) or not isinstance(v, int | float):
|
||||
continue
|
||||
try:
|
||||
ttl = int(v)
|
||||
except (ValueError, OverflowError):
|
||||
continue # JSON may decode NaN/Infinity; never fail a live request.
|
||||
if ttl > 0:
|
||||
return ttl
|
||||
return None
|
||||
|
||||
|
||||
|
||||
+41
-20
@@ -36,6 +36,7 @@ from typing import TYPE_CHECKING, Any
|
||||
from headroom import paths as _paths
|
||||
from headroom import savings_ledger
|
||||
from headroom.cache.compression_store import format_retrieval_miss_detail
|
||||
from headroom.exceptions import StorageError
|
||||
from headroom.log_safety import describe_exception, redact_url, safe_id
|
||||
from headroom.telemetry import session as telemetry_session
|
||||
|
||||
@@ -460,16 +461,31 @@ class HeadroomMCPServer:
|
||||
|
||||
# Store original in local store for later retrieval
|
||||
store = self._get_local_store()
|
||||
hash_key = store.store(
|
||||
original=content,
|
||||
compressed=compressed_content
|
||||
if isinstance(compressed_content, str)
|
||||
else json.dumps(compressed_content),
|
||||
original_tokens=input_tokens,
|
||||
compressed_tokens=output_tokens,
|
||||
compression_strategy="mcp_compress",
|
||||
ttl=MCP_SESSION_TTL,
|
||||
)
|
||||
try:
|
||||
hash_key = store.store(
|
||||
original=content,
|
||||
compressed=compressed_content
|
||||
if isinstance(compressed_content, str)
|
||||
else json.dumps(compressed_content),
|
||||
original_tokens=input_tokens,
|
||||
compressed_tokens=output_tokens,
|
||||
compression_strategy="mcp_compress",
|
||||
ttl=MCP_SESSION_TTL,
|
||||
)
|
||||
except StorageError as e:
|
||||
# No stored original: hand back the content itself, which also
|
||||
# keeps out any marker the pipeline put in the compressed text.
|
||||
logger.warning("headroom_compress: returning the original, CCR store refused it: %s", e)
|
||||
return {
|
||||
"compressed": content,
|
||||
"hash": None,
|
||||
"original_tokens": input_tokens,
|
||||
"compressed_tokens": input_tokens,
|
||||
"tokens_saved": 0,
|
||||
"savings_percent": 0,
|
||||
"transforms": [],
|
||||
"note": "Not compressed: the CCR store could not keep the original.",
|
||||
}
|
||||
|
||||
# Track stats
|
||||
strategy = (
|
||||
@@ -1085,16 +1101,21 @@ class HeadroomMCPServer:
|
||||
# Fresh read: store in CCR and cache the hash
|
||||
store = self._get_local_store()
|
||||
token_estimate = self._estimate_tokens(content)
|
||||
ccr_hash = store.store(
|
||||
original=content,
|
||||
compressed=f"[File: {path.name}, {line_count} lines]",
|
||||
original_tokens=token_estimate,
|
||||
compressed_tokens=5,
|
||||
tool_name="headroom_read",
|
||||
ttl=MCP_SESSION_TTL,
|
||||
)
|
||||
|
||||
self._file_cache[str_path] = (content_hash, ccr_hash, line_count, token_estimate)
|
||||
try:
|
||||
ccr_hash = store.store(
|
||||
original=content,
|
||||
compressed=f"[File: {path.name}, {line_count} lines]",
|
||||
original_tokens=token_estimate,
|
||||
compressed_tokens=5,
|
||||
tool_name="headroom_read",
|
||||
ttl=MCP_SESSION_TTL,
|
||||
)
|
||||
except StorageError as e:
|
||||
# The full content is returned below either way; without a stored
|
||||
# original, a re-read must not answer with a hash.
|
||||
logger.warning("headroom_read: not cached, the CCR store refused it: %s", e)
|
||||
else:
|
||||
self._file_cache[str_path] = (content_hash, ccr_hash, line_count, token_estimate)
|
||||
|
||||
# Return full content with line numbers (like Claude Code's Read tool)
|
||||
numbered_lines = []
|
||||
|
||||
@@ -5,8 +5,18 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from headroom.proxy.tool_name_policy import extract_tool_name
|
||||
|
||||
from .tool_injection import CCR_TOOL_NAME, parse_tool_call
|
||||
|
||||
_CLIENT_CCR_TOOL_ALIASES = frozenset(
|
||||
{
|
||||
"headroom_headroom_retrieve",
|
||||
"mcp__headroom__headroom_retrieve",
|
||||
"mcp_headroom_headroom_retrieve",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CCRToolCall:
|
||||
@@ -128,6 +138,18 @@ def has_ccr_retrieve_tool(tools: Any) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def client_retrieval_tool_name(tools: list[dict[str, Any]] | None) -> str | None:
|
||||
"""Select the canonical retrieval tool, or a default Headroom MCP alias."""
|
||||
alias = None
|
||||
for tool in tools or ():
|
||||
name = extract_tool_name(tool)
|
||||
if name == CCR_TOOL_NAME:
|
||||
return name
|
||||
if alias is None and isinstance(name, str) and name.lower() in _CLIENT_CCR_TOOL_ALIASES:
|
||||
alias = name
|
||||
return alias
|
||||
|
||||
|
||||
def has_ccr_tool_calls(response: dict[str, Any], provider: str) -> bool:
|
||||
"""Return true when ``response`` contains at least one CCR tool call."""
|
||||
return any(is_ccr_tool_call(tool_call) for tool_call in extract_tool_calls(response, provider))
|
||||
|
||||
@@ -154,6 +154,8 @@ def create_ccr_tool_definition(
|
||||
def create_system_instructions(
|
||||
hashes: list[str],
|
||||
retrieval_endpoint: str = "/v1/retrieve",
|
||||
*,
|
||||
retrieval_tool_name: str = CCR_TOOL_NAME,
|
||||
) -> str:
|
||||
"""Create system message instructions for CCR retrieval.
|
||||
|
||||
@@ -163,6 +165,7 @@ def create_system_instructions(
|
||||
Args:
|
||||
hashes: List of hash keys for compressed content in this context.
|
||||
retrieval_endpoint: The endpoint path for retrieval.
|
||||
retrieval_tool_name: Executable tool name from the client's registry.
|
||||
|
||||
Returns:
|
||||
Instruction text to append to system message.
|
||||
@@ -173,10 +176,10 @@ def create_system_instructions(
|
||||
## Compressed Context Available
|
||||
|
||||
Some tool outputs have been compressed to reduce context size. If you need
|
||||
the full uncompressed data, you can retrieve it using the `{CCR_TOOL_NAME}` tool.
|
||||
the full uncompressed data, you can retrieve it using the `{retrieval_tool_name}` tool.
|
||||
|
||||
**How to retrieve:**
|
||||
- Call `{CCR_TOOL_NAME}(hash="<hash>")` to get the full original content back
|
||||
- Call `{retrieval_tool_name}(hash="<hash>")` to get the full original content back
|
||||
|
||||
**Available hashes:** {hash_list}
|
||||
|
||||
@@ -456,11 +459,10 @@ class CCRToolInjector:
|
||||
|
||||
tools = tools or []
|
||||
|
||||
# Check if already present (e.g., from MCP server)
|
||||
for tool in tools:
|
||||
tool_name = tool.get("name") or tool.get("function", {}).get("name")
|
||||
if tool_name == CCR_TOOL_NAME:
|
||||
return tools, False # Already present, skip injection
|
||||
from .tool_calls import client_retrieval_tool_name
|
||||
|
||||
if client_retrieval_tool_name(tools):
|
||||
return tools, False # Already present, skip injection
|
||||
|
||||
# Add CCR tool
|
||||
ccr_tool = create_ccr_tool_definition(self.provider)
|
||||
@@ -469,11 +471,13 @@ class CCRToolInjector:
|
||||
def inject_into_system_message(
|
||||
self,
|
||||
messages: list[dict[str, Any]],
|
||||
tools: list[dict[str, Any]] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Inject retrieval instructions into system message.
|
||||
|
||||
Args:
|
||||
messages: List of messages.
|
||||
tools: Available tool definitions for selecting an executable retrieval name.
|
||||
|
||||
Returns:
|
||||
Updated messages with instructions added to system message.
|
||||
@@ -481,9 +485,12 @@ class CCRToolInjector:
|
||||
if not self.inject_system_instructions or not self.has_compressed_content:
|
||||
return messages
|
||||
|
||||
from .tool_calls import client_retrieval_tool_name
|
||||
|
||||
instructions = create_system_instructions(
|
||||
self._detected_hashes,
|
||||
self.retrieval_endpoint,
|
||||
retrieval_tool_name=client_retrieval_tool_name(tools) or CCR_TOOL_NAME,
|
||||
)
|
||||
|
||||
# Find and update system message
|
||||
@@ -567,7 +574,7 @@ class CCRToolInjector:
|
||||
updated_tools, was_injected = self.inject_tool_definition(
|
||||
tools, session_has_done_ccr=session_has_done_ccr
|
||||
)
|
||||
updated_messages = self.inject_into_system_message(messages)
|
||||
updated_messages = self.inject_into_system_message(messages, tools=updated_tools)
|
||||
|
||||
return updated_messages, updated_tools if updated_tools else None, was_injected
|
||||
|
||||
|
||||
+41
-5
@@ -46,7 +46,7 @@ from headroom.providers.claude import (
|
||||
)
|
||||
|
||||
from .main import get_version, main
|
||||
from .port_discovery import find_live_proxy_elsewhere, is_headroom_livez
|
||||
from .port_discovery import find_live_proxy_elsewhere, is_headroom_livez, loopback_port
|
||||
from .wrap import _read_wrap_marker, _wrap_marker_is_stale
|
||||
|
||||
PASS = "pass"
|
||||
@@ -59,6 +59,7 @@ DEFAULT_PROXY_PORT = 8787
|
||||
_LOOPBACK_URL_RE = re.compile(r"https?://(?:127\.0\.0\.1|localhost):(\d+)")
|
||||
_CODEX_BASE_URL_RE = re.compile(r'(?m)^[ \t]*base_url\s*=\s*"([^"\r\n]+)"')
|
||||
_CODEX_MODEL_PROVIDER_RE = re.compile(r'(?m)^[ \t]*model_provider\s*=\s*"([^"\r\n]+)"')
|
||||
_CODEX_OPENAI_BASE_URL_RE = re.compile(r'(?m)^[ \t]*openai_base_url\s*=\s*"([^"\r\n]+)"')
|
||||
|
||||
# Ollama's fixed default port. `ollama launch claude` writes
|
||||
# ``ANTHROPIC_BASE_URL=http://127.0.0.1:11434`` into the launched Claude Code
|
||||
@@ -573,7 +574,19 @@ def check_wrap_marker_staleness(settings_path: Path) -> CheckResult:
|
||||
|
||||
def codex_active_base_url(text: str) -> tuple[str, str | None]:
|
||||
"""Return ``(provider_id, base_url)`` for the active Codex provider in ``text``."""
|
||||
active_match = _CODEX_MODEL_PROVIDER_RE.search(text)
|
||||
first_table = re.search(r"(?m)^[ \t]*\[", text)
|
||||
root = text[: first_table.start()] if first_table is not None else text
|
||||
# Only a root `model_provider` picks the default session's provider; one
|
||||
# under `[profiles.*]` applies only when that profile is selected.
|
||||
active_match = _CODEX_MODEL_PROVIDER_RE.search(root)
|
||||
if active_match is None or active_match.group(1) == "openai":
|
||||
# A root `openai_base_url` re-points Codex's built-in `openai` provider
|
||||
# (the default when `model_provider` is unset), so it beats an inactive
|
||||
# `[model_providers.headroom]` table. Headroom Desktop routes this way
|
||||
# because the ChatGPT app hides features for any other provider.
|
||||
root_url = _CODEX_OPENAI_BASE_URL_RE.search(root)
|
||||
if root_url is not None:
|
||||
return "openai", root_url.group(1)
|
||||
provider_id = active_match.group(1) if active_match else "headroom"
|
||||
return provider_id, _codex_provider_base_url(text, provider_id)
|
||||
|
||||
@@ -661,6 +674,24 @@ def _codex_provider_base_url(text: str, provider_id: str) -> str | None:
|
||||
return base_url_match.group(1) if base_url_match else None
|
||||
|
||||
|
||||
def _configured_client_ports(
|
||||
claude_paths: Sequence[Path], codex_paths: Sequence[Path]
|
||||
) -> list[int]:
|
||||
"""Loopback ports the Claude Code and Codex configs (project and user) send traffic to.
|
||||
|
||||
Headroom Desktop (port 6767) and ``wrap --port N`` leave no deployment
|
||||
manifest, so without these a bare ``doctor`` only ever finds 8787.
|
||||
"""
|
||||
urls = [_claude_base_url_in(path)[0] for path in claude_paths]
|
||||
for path in codex_paths:
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8", errors="replace")
|
||||
except OSError:
|
||||
continue
|
||||
urls.append(codex_active_base_url(text)[1] or "")
|
||||
return [port for port in map(loopback_port, urls) if port is not None]
|
||||
|
||||
|
||||
def _codex_block_missing_openai_auth(
|
||||
text: str, config_path: Path, provider_id: str = "headroom"
|
||||
) -> bool:
|
||||
@@ -1211,20 +1242,25 @@ def doctor(
|
||||
health = probe_json(f"{base_url}/health", timeout=5.0) if livez else None
|
||||
stats = probe_json(f"{base_url}/stats", timeout=5.0) if livez else None
|
||||
installed = get_version()
|
||||
project_claude_settings = Path.cwd() / ".claude" / "settings.json"
|
||||
project_local_claude_settings = Path.cwd() / ".claude" / "settings.local.json"
|
||||
live_elsewhere = None
|
||||
if livez is None:
|
||||
# Cheap, bounded: only ports Headroom recorded (HEADROOM_PORT, 8787,
|
||||
# deployment manifests, the project's wrap marker), probed in parallel.
|
||||
# deployment manifests, the project's wrap marker) and the ports the
|
||||
# agents are configured for, probed in parallel.
|
||||
live_elsewhere = find_live_proxy_elsewhere(
|
||||
port,
|
||||
manifests=manifests,
|
||||
extra=_configured_client_ports(
|
||||
[project_local_claude_settings, project_claude_settings, claude_settings_path()],
|
||||
[codex_project_config_path(), codex_config_path()],
|
||||
),
|
||||
probe=lambda p: is_headroom_livez(
|
||||
probe_json(f"http://127.0.0.1:{p}/livez", timeout=0.5)
|
||||
),
|
||||
)
|
||||
|
||||
project_claude_settings = Path.cwd() / ".claude" / "settings.json"
|
||||
project_local_claude_settings = Path.cwd() / ".claude" / "settings.local.json"
|
||||
checks = [
|
||||
note_live_proxy_elsewhere(check_proxy_liveness(livez, base_url), live_elsewhere),
|
||||
check_proxy_readiness(livez, readyz, base_url),
|
||||
|
||||
@@ -7,6 +7,8 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from headroom.offline import pin_litellm_cost_map_local
|
||||
|
||||
from .main import main
|
||||
|
||||
|
||||
@@ -480,6 +482,7 @@ def _run_memory_eval(
|
||||
answer_fn = None
|
||||
if answer_model:
|
||||
try:
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
|
||||
def answer_fn(question: str, memories: list[str]) -> str:
|
||||
|
||||
+21
-13
@@ -58,6 +58,11 @@ from headroom.install.state import ManifestError, load_manifest, save_manifest
|
||||
from headroom.install.supervisors import start_supervisor
|
||||
from headroom.providers.claude import TOOL_SEARCH_DEFAULT, TOOL_SEARCH_ENV
|
||||
from headroom.providers.claude.runtime import TOOL_SEARCH_FOUNDRY_DEFAULT
|
||||
from headroom.providers.codex.config_toml import (
|
||||
loads_codex_config,
|
||||
root_assignment_lines,
|
||||
split_toml_lines,
|
||||
)
|
||||
from headroom.providers.codex.install import (
|
||||
CodexAuthConfigError,
|
||||
build_codex_auth_config,
|
||||
@@ -91,6 +96,7 @@ _STARTUP_READY_TIMEOUT_SECONDS = 15
|
||||
# report ready, and every session is permanently cold.
|
||||
_HOOK_ENSURE_TIMEOUT_SECONDS = 60
|
||||
_TOML_TABLE_HEADER_RE = re.compile(r"^[ \t]*(?:\[\[[^\]\r\n]+\]\]|\[[^\]\r\n]+\])[ \t]*(?:#.*)?$")
|
||||
_ROOT_PROVIDER_KEY_RE = re.compile(r"[ \t]*(?:model_provider|openai_base_url)[ \t]*=")
|
||||
_TOML_FEATURES_NAME_RE = r"(?:features|\"features\"|'features')"
|
||||
_TOML_CODEX_HOOKS_NAME_RE = r"(?:codex_hooks|\"codex_hooks\"|'codex_hooks')"
|
||||
_CODEX_FEATURES_TABLE_RE = re.compile(
|
||||
@@ -298,7 +304,7 @@ def _replace_marker_block(
|
||||
# The block carries top-level keys, so it must sit above the first table
|
||||
# header; appended after a table (e.g. [features]) TOML scopes those keys
|
||||
# into that table and Codex rejects the config (#260).
|
||||
lines = content.splitlines()
|
||||
lines = split_toml_lines(content)
|
||||
for index, line in enumerate(lines):
|
||||
if _TOML_TABLE_HEADER_RE.search(line):
|
||||
head = "\n".join(lines[:index]).rstrip()
|
||||
@@ -347,7 +353,7 @@ def _codex_init_provider_snapshot(content: str) -> str | None:
|
||||
snapshot = json.loads(match.group(1))
|
||||
if not isinstance(snapshot, str):
|
||||
raise ValueError("Invalid Headroom init provider snapshot")
|
||||
tomllib.loads(snapshot)
|
||||
loads_codex_config(snapshot)
|
||||
return snapshot
|
||||
|
||||
|
||||
@@ -470,19 +476,21 @@ def _ensure_codex_provider(path: Path, port: int) -> None:
|
||||
# first table header) -- these keys also appear legitimately inside
|
||||
# [profiles.*] tables as per-profile overrides, and stripping them there
|
||||
# silently reroutes the user's profiles to the injected "headroom" default.
|
||||
_first_table = re.search(r"(?m)^[ \t]*\[", content)
|
||||
_split = _first_table.start() if _first_table else len(content)
|
||||
root, rest = content[:_split], content[_split:]
|
||||
root = re.sub(r"(?m)^[ \t]*model_provider[ \t]*=.*\r?\n", "", root)
|
||||
root = re.sub(r"(?m)^[ \t]*openai_base_url[ \t]*=.*\r?\n", "", root)
|
||||
content = root + rest
|
||||
# Lines nested in a multi-line inline table (e.g. ``profiles = {``) are
|
||||
# profile overrides too, so only true root assignments are dropped.
|
||||
_root_lines = root_assignment_lines(content)
|
||||
content = "".join(
|
||||
line
|
||||
for index, line in enumerate(split_toml_lines(content, keepends=True))
|
||||
if index not in _root_lines or not _ROOT_PROVIDER_KEY_RE.match(line)
|
||||
)
|
||||
# The provider block carries top-level keys (model_provider, openai_base_url),
|
||||
# so it must land at the document root rather than after a trailing table (#260).
|
||||
content = _replace_marker_block(
|
||||
content, _CODEX_PROVIDER_MARKER_START, _CODEX_PROVIDER_MARKER_END, block, at_root=True
|
||||
)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tomllib.loads(content)
|
||||
loads_codex_config(content)
|
||||
fsutil.write_text(path, content)
|
||||
# Codex filters its history menu by the active model_provider, so existing
|
||||
# native threads vanish once we switch to "headroom". Retag them to match the
|
||||
@@ -511,7 +519,7 @@ def _codex_features(content: str) -> dict[str, Any] | None:
|
||||
if not content.strip():
|
||||
return None
|
||||
try:
|
||||
parsed = tomllib.loads(content)
|
||||
parsed = loads_codex_config(content)
|
||||
except tomllib.TOMLDecodeError:
|
||||
return None
|
||||
features = parsed.get("features")
|
||||
@@ -523,7 +531,7 @@ def _codex_features_has_hooks(content: str) -> bool:
|
||||
if features is None:
|
||||
# Keep init resilient for already-invalid user configs; this fallback
|
||||
# only needs to avoid adding a second obvious hooks line.
|
||||
lines = content.splitlines()
|
||||
lines = split_toml_lines(content)
|
||||
features_index = _codex_features_table_index(lines)
|
||||
if features_index is None:
|
||||
return False
|
||||
@@ -538,7 +546,7 @@ def _codex_features_has_hooks(content: str) -> bool:
|
||||
|
||||
|
||||
def _strip_codex_legacy_feature_flag(content: str) -> str:
|
||||
lines = content.splitlines(keepends=True)
|
||||
lines = split_toml_lines(content, keepends=True)
|
||||
retained: list[str] = []
|
||||
in_features = False
|
||||
in_root = True
|
||||
@@ -588,7 +596,7 @@ def _ensure_codex_feature_flag(path: Path) -> None:
|
||||
# the only work.
|
||||
pass
|
||||
else:
|
||||
lines = content.splitlines()
|
||||
lines = split_toml_lines(content)
|
||||
features_index = _codex_features_table_index(lines)
|
||||
if features_index is not None:
|
||||
# Leading blank line matches the normalisation _replace_marker_block
|
||||
|
||||
@@ -943,7 +943,10 @@ def _echo_installed(manifest: DeploymentManifest, *, prefix: str = "Installed pe
|
||||
"--env HEADROOM_WORKSPACE_DIR=/path. Supervisors (launchd, systemd, cron) "
|
||||
"start with a bare environment and do not inherit the interactive shell's "
|
||||
"exports, so anything the runtime needs beyond the flags above must be set "
|
||||
"here. Repeatable."
|
||||
"here. Repeatable. Values are stored in cleartext in the profile's "
|
||||
"manifest and runner scripts under ~/.headroom/deploy/<profile>/ "
|
||||
"(owner-only, not encrypted); see SECURITY.md before passing a provider "
|
||||
"API key this way."
|
||||
),
|
||||
)
|
||||
def install_apply(
|
||||
|
||||
@@ -7,6 +7,8 @@ from typing import TYPE_CHECKING, Any, NamedTuple
|
||||
|
||||
import click
|
||||
|
||||
from headroom.offline import pin_litellm_cost_map_local
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..learn.base import LearnPlugin
|
||||
|
||||
@@ -390,6 +392,7 @@ def _make_llm_judge(model: str) -> Any:
|
||||
try:
|
||||
import json
|
||||
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
@@ -598,7 +598,7 @@ def show_memory(
|
||||
# If not found with exact ID, try partial match
|
||||
if mem is None:
|
||||
# Query all and filter by prefix
|
||||
all_memories = asyncio.run(store.query(MemoryFilter(limit=1000)))
|
||||
all_memories = asyncio.run(store.query(MemoryFilter()))
|
||||
matches = [m for m in all_memories if m.id.startswith(memory_id)]
|
||||
|
||||
if len(matches) == 0:
|
||||
|
||||
+35
-16
@@ -41,10 +41,7 @@ from functools import wraps
|
||||
from pathlib import Path
|
||||
from typing import Any, NamedTuple, cast
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except ModuleNotFoundError: # pragma: no cover - Python < 3.11
|
||||
import tomli as tomllib
|
||||
import tomllib
|
||||
|
||||
from headroom._subprocess import identity_mismatch as _shared_identity_mismatch
|
||||
from headroom._subprocess import pid_alive, proc_identity, run
|
||||
@@ -113,6 +110,11 @@ from headroom.providers.claude import (
|
||||
)
|
||||
from headroom.providers.claude.runtime import TOOL_SEARCH_FOUNDRY_DEFAULT
|
||||
from headroom.providers.codex import build_launch_env as _build_codex_launch_env
|
||||
from headroom.providers.codex.config_toml import (
|
||||
loads_codex_config,
|
||||
root_assignment_lines,
|
||||
split_toml_lines,
|
||||
)
|
||||
from headroom.providers.codex.install import (
|
||||
CodexAuthConfigError,
|
||||
build_codex_auth_config,
|
||||
@@ -3086,7 +3088,7 @@ def _codex_session_launch_settings(
|
||||
"""Build process-local routing while preserving the selected provider id."""
|
||||
config_file, _ = _codex_config_paths()
|
||||
try:
|
||||
config = tomllib.loads(_read_text(config_file)) if config_file.exists() else {}
|
||||
config = loads_codex_config(_read_text(config_file)) if config_file.exists() else {}
|
||||
except (OSError, tomllib.TOMLDecodeError) as exc:
|
||||
raise click.ClickException(
|
||||
f"could not read Codex config for session routing: {exc}"
|
||||
@@ -3347,19 +3349,28 @@ def _redirect_existing_top_level_keys(content: str, port: int) -> str:
|
||||
|
||||
return _replace
|
||||
|
||||
redirected = content
|
||||
# Only root assignments: the same keys inside [profiles.*] tables or a
|
||||
# multi-line inline ``profiles = {`` table are the user's per-profile routing.
|
||||
lines = split_toml_lines(content, keepends=True)
|
||||
root_lines = sorted(root_assignment_lines(content))
|
||||
for key in _REDIRECTABLE_KEYS:
|
||||
pattern = re.compile(rf'(?m)^[ \t]*{re.escape(key)}[ \t]*=[ \t]*"(?P<value>[^"\n]*)"[^\n]*')
|
||||
redirected = pattern.sub(_make_replacer(key, port), redirected, count=1)
|
||||
return redirected
|
||||
pattern = re.compile(rf'[ \t]*{re.escape(key)}[ \t]*=[ \t]*"(?P<value>[^"\n]*)"[^\n]*')
|
||||
replace = _make_replacer(key, port)
|
||||
for index in root_lines:
|
||||
match = pattern.match(lines[index])
|
||||
if match:
|
||||
lines[index] = replace(match) + lines[index][match.end() :]
|
||||
break
|
||||
return "".join(lines)
|
||||
|
||||
|
||||
def _has_redirectable_top_level_key(content: str, key: str) -> bool:
|
||||
"""Return True if ``content`` declares ``key = "..."`` as a top-level key."""
|
||||
import re # local import to match the module's existing convention
|
||||
|
||||
pattern = re.compile(rf'(?m)^[ \t]*{key}[ \t]*=[ \t]*"[^"\n]*"')
|
||||
return pattern.search(content) is not None
|
||||
pattern = re.compile(rf'[ \t]*{key}[ \t]*=[ \t]*"[^"\n]*"')
|
||||
lines = split_toml_lines(content, keepends=True)
|
||||
return any(pattern.match(lines[index]) for index in root_assignment_lines(content))
|
||||
|
||||
|
||||
def _codex_config_has_headroom_markers(content: str) -> bool:
|
||||
@@ -3718,10 +3729,10 @@ def _inject_codex_provider_config(port: int) -> str | None:
|
||||
# name a line the user never wrote. Only the user's part has to
|
||||
# parse: stripping a stale Headroom block may be what repairs it.
|
||||
try:
|
||||
tomllib.loads(content)
|
||||
loads_codex_config(content)
|
||||
except tomllib.TOMLDecodeError:
|
||||
try:
|
||||
tomllib.loads(original)
|
||||
loads_codex_config(original)
|
||||
reason = "it is no longer valid TOML once Headroom's block is removed"
|
||||
except tomllib.TOMLDecodeError as exc:
|
||||
reason = f"it is not valid TOML ({exc})"
|
||||
@@ -3769,7 +3780,7 @@ def _inject_codex_provider_config(port: int) -> str | None:
|
||||
)
|
||||
|
||||
# Never replace a usable config with a malformed generated candidate.
|
||||
tomllib.loads(content)
|
||||
loads_codex_config(content)
|
||||
_write_text(config_file, content)
|
||||
click.echo(f" Codex config: injected Headroom provider (WS + HTTP) into {config_file}")
|
||||
if custom_upstream_base_url:
|
||||
@@ -4066,7 +4077,7 @@ def _inject_memory_mcp_config(user_id: str) -> None:
|
||||
content = mcp_section
|
||||
|
||||
# Never replace a usable config with a malformed generated candidate.
|
||||
tomllib.loads(content)
|
||||
loads_codex_config(content)
|
||||
_write_text(config_file, content)
|
||||
click.echo(f" Memory MCP: registered in {config_file}")
|
||||
except Exception as e:
|
||||
@@ -8110,7 +8121,15 @@ def zcode(
|
||||
if prepare_only:
|
||||
return
|
||||
|
||||
upstream = _detect_zcode_upstream()
|
||||
# _ensure_proxy moves to another port when the requested one is held by a
|
||||
# non-Headroom service. Resolve that port first so the upstream is chosen
|
||||
# against the port the proxy will actually bind.
|
||||
if not no_proxy and not (_check_proxy(port) and not _foreign_listener(port)):
|
||||
try:
|
||||
port = _find_available_port(port)
|
||||
except (OSError, RuntimeError):
|
||||
pass # _ensure_proxy reports the same error
|
||||
upstream = _detect_zcode_upstream(proxy_port=port)
|
||||
anthropic_url, openai_url = _zcode_upstream_to_urls(upstream)
|
||||
|
||||
def _print_zcode_setup(actual_port: int = port) -> None:
|
||||
|
||||
+76
-13
@@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from collections.abc import Iterator
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
@@ -38,6 +38,74 @@ from .utils import (
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class _OwnedStream(Iterator[Any]):
|
||||
"""Iterator that owns and closes an upstream response stream."""
|
||||
|
||||
def __init__(self, stream: Iterable[Any], save_metrics: Callable[[], None]) -> None:
|
||||
self._source: Iterable[Any] | None = stream
|
||||
self._stream: Iterator[Any] | None = None
|
||||
self._save_metrics: Callable[[], None] | None = save_metrics
|
||||
self._finished = False
|
||||
|
||||
def __iter__(self) -> _OwnedStream:
|
||||
return self
|
||||
|
||||
def __next__(self) -> Any:
|
||||
if self._finished:
|
||||
raise StopIteration
|
||||
try:
|
||||
if self._stream is None:
|
||||
source = self._source
|
||||
if source is None:
|
||||
raise StopIteration
|
||||
self._stream = iter(source)
|
||||
return next(self._stream)
|
||||
except BaseException:
|
||||
self.close()
|
||||
raise
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close the upstream stream and save metrics exactly once."""
|
||||
if self._finished:
|
||||
return
|
||||
self._finished = True
|
||||
source = self._source
|
||||
stream = self._stream
|
||||
save_metrics = self._save_metrics
|
||||
try:
|
||||
candidates = (source,) if source is stream else (source, stream)
|
||||
for candidate in candidates:
|
||||
if candidate is None:
|
||||
continue
|
||||
close = getattr(candidate, "close", None)
|
||||
if close is not None:
|
||||
try:
|
||||
close()
|
||||
except Exception:
|
||||
logger.warning("Failed to close upstream response stream", exc_info=True)
|
||||
finally:
|
||||
self._source = None
|
||||
self._stream = None
|
||||
self._save_metrics = None
|
||||
if save_metrics is not None:
|
||||
save_metrics()
|
||||
|
||||
def __enter__(self) -> _OwnedStream:
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
||||
self.close()
|
||||
|
||||
def __del__(self) -> None:
|
||||
# The previous generator wrapper ran its finally block when abandoned
|
||||
# after iteration started. Preserve that cleanup for callers that do
|
||||
# not explicitly close a stream.
|
||||
try:
|
||||
self.close()
|
||||
except Exception:
|
||||
logger.debug("Failed to finalize abandoned response stream", exc_info=True)
|
||||
|
||||
|
||||
class ChatCompletions:
|
||||
"""Wrapper for chat.completions API (OpenAI-style)."""
|
||||
|
||||
@@ -307,11 +375,11 @@ class HeadroomClient:
|
||||
# Use provided config or build from individual parameters
|
||||
if config is not None:
|
||||
self._config = config
|
||||
# Override store_url and mode if explicitly provided in config
|
||||
# Override store_url and mode if explicitly provided in config.
|
||||
# The resolved URL is not written back: the caller may share this
|
||||
# config with other clients, which would then read it as explicit.
|
||||
if config.store_url:
|
||||
self._store_url = config.store_url
|
||||
else:
|
||||
self._config.store_url = store_url
|
||||
self._default_mode = config.default_mode
|
||||
else:
|
||||
# Build config from individual parameters
|
||||
@@ -325,7 +393,7 @@ class HeadroomClient:
|
||||
self._config.model_context_limits.update(model_context_limits)
|
||||
|
||||
# Initialize storage
|
||||
self._storage = create_storage(store_url)
|
||||
self._storage = create_storage(self._store_url)
|
||||
|
||||
# Initialize transform pipeline
|
||||
self._pipeline = TransformPipeline(self._config, provider=self._provider)
|
||||
@@ -644,16 +712,11 @@ class HeadroomClient:
|
||||
|
||||
def _wrap_stream(
|
||||
self,
|
||||
stream: Iterator[Any],
|
||||
stream: Iterable[Any],
|
||||
metrics: RequestMetrics,
|
||||
) -> Iterator[Any]:
|
||||
"""Wrap stream to pass through chunks and save metrics at end."""
|
||||
try:
|
||||
yield from stream
|
||||
finally:
|
||||
# Save metrics when stream completes
|
||||
# Note: output tokens unknown for streams
|
||||
self._storage.save(metrics)
|
||||
"""Wrap stream, closing the upstream and saving metrics exactly once."""
|
||||
return _OwnedStream(stream, lambda: self._storage.save(metrics))
|
||||
|
||||
def _extract_query(self, messages: list[dict[str, Any]]) -> str:
|
||||
"""Extract query from messages for semantic caching.
|
||||
|
||||
+3
-1
@@ -923,7 +923,9 @@ class PrefixFreezeConfig:
|
||||
class HeadroomConfig:
|
||||
"""Main configuration for HeadroomClient."""
|
||||
|
||||
store_url: str = "sqlite:///headroom.db"
|
||||
# None defers to HeadroomClient: its ``store_url`` argument, else a
|
||||
# headroom.db in the system temp directory.
|
||||
store_url: str | None = None
|
||||
default_mode: HeadroomMode = HeadroomMode.AUDIT
|
||||
model_context_limits: dict[str, int] = field(
|
||||
default_factory=lambda: DEFAULT_MODEL_CONTEXT_LIMITS.copy()
|
||||
|
||||
@@ -1069,6 +1069,14 @@ def _set_header_default(headers: dict[str, str], name: str, value: str) -> None:
|
||||
headers[name] = value
|
||||
|
||||
|
||||
def _remove_headers(headers: dict[str, str], *names: str) -> None:
|
||||
"""Remove every case variant of the named headers in place."""
|
||||
names_lower = {name.lower() for name in names}
|
||||
for key in list(headers):
|
||||
if key.lower() in names_lower:
|
||||
del headers[key]
|
||||
|
||||
|
||||
def _copilot_token_exchange_headers(
|
||||
oauth_token: str, *, integration_id: str | None = None
|
||||
) -> dict[str, str]:
|
||||
@@ -1695,7 +1703,7 @@ def _is_forwardable_copilot_bearer_token(token: str) -> bool:
|
||||
def _token_kind(token: str) -> str:
|
||||
"""Return a non-sensitive label for the token type, safe to log."""
|
||||
t = token.strip()
|
||||
for prefix in ("tid_", "gho_", "ghs_", "ghp_", "github_pat_"):
|
||||
for prefix in ("tid_", "ghu_", "gho_", "ghs_", "ghp_", "github_pat_"):
|
||||
if t.startswith(prefix):
|
||||
return prefix + "***"
|
||||
return "unknown" if t else "empty"
|
||||
@@ -1725,6 +1733,36 @@ async def apply_copilot_api_auth(headers: dict[str, str], *, url: str) -> dict[s
|
||||
if not is_copilot_upstream_url(url):
|
||||
return resolved
|
||||
|
||||
incoming_auth = next((v for k, v in resolved.items() if k.lower() == "authorization"), None)
|
||||
scheme, _, raw_token = incoming_auth.partition(" ") if incoming_auth else ("", "", "")
|
||||
# Inline completions accept the editor's own OAuth credential. Keep its
|
||||
# account and integration metadata rather than substituting the operator's
|
||||
# seat or adding chat-specific defaults (#3352).
|
||||
if (
|
||||
scheme.lower() == "bearer"
|
||||
and raw_token.startswith("ghu_")
|
||||
and is_copilot_completions_host(url)
|
||||
and not _is_managed_copilot_seeded_bearer(raw_token)
|
||||
):
|
||||
upstream = urlparse(url)
|
||||
base = urlparse(copilot_completions_base_url())
|
||||
path = upstream.path
|
||||
prefix = base.path.rstrip("/")
|
||||
if (
|
||||
prefix
|
||||
and upstream.scheme == base.scheme
|
||||
and upstream.netloc.lower() == base.netloc.lower()
|
||||
and path.startswith(prefix + "/")
|
||||
):
|
||||
path = path[len(prefix) :]
|
||||
if is_copilot_completions_path(path):
|
||||
logger.info(
|
||||
"apply_copilot_api_auth: passing through inline editor token kind=%s",
|
||||
_token_kind(raw_token),
|
||||
)
|
||||
_remove_headers(resolved, "x-api-key")
|
||||
return resolved
|
||||
|
||||
# Read the CLIENT's integration ID before any default is applied, so the
|
||||
# credential we mint below can be bound to the surface that actually made
|
||||
# the call rather than to whatever this proxy happens to default to.
|
||||
@@ -1734,9 +1772,7 @@ async def apply_copilot_api_auth(headers: dict[str, str], *, url: str) -> dict[s
|
||||
for name, value in _copilot_chat_header_defaults(integration_id).items():
|
||||
_set_header_default(resolved, name, value)
|
||||
|
||||
incoming_auth = next((v for k, v in resolved.items() if k.lower() == "authorization"), None)
|
||||
if incoming_auth:
|
||||
scheme, _, raw_token = incoming_auth.partition(" ")
|
||||
if (
|
||||
scheme.lower() == "bearer"
|
||||
and raw_token
|
||||
@@ -1752,9 +1788,7 @@ async def apply_copilot_api_auth(headers: dict[str, str], *, url: str) -> dict[s
|
||||
"apply_copilot_api_auth: passing through client token kind=%s",
|
||||
_token_kind(raw_token),
|
||||
)
|
||||
for key in list(resolved):
|
||||
if key.lower() == "x-api-key":
|
||||
resolved.pop(key)
|
||||
_remove_headers(resolved, "x-api-key")
|
||||
return resolved
|
||||
logger.info(
|
||||
"apply_copilot_api_auth: incoming token not suitable (kind=%s), will replace",
|
||||
@@ -1762,9 +1796,7 @@ async def apply_copilot_api_auth(headers: dict[str, str], *, url: str) -> dict[s
|
||||
)
|
||||
|
||||
token = await get_copilot_token_provider().get_api_token(integration_id=integration_id)
|
||||
for key in list(resolved):
|
||||
if key.lower() in {"authorization", "x-api-key"}:
|
||||
resolved.pop(key)
|
||||
_remove_headers(resolved, "authorization", "x-api-key")
|
||||
resolved["Authorization"] = f"Bearer {token.token}"
|
||||
# The credential and the integration ID must leave together. Until now the
|
||||
# ID was applied with set-default semantics BEFORE this branch was chosen,
|
||||
|
||||
@@ -219,13 +219,13 @@
|
||||
<p class="text-sm text-gray-300">
|
||||
<span class="font-medium text-accent">Headroom for Teams</span>
|
||||
<span x-text="(stats.summary?.cost?.total_saved_usd || 0) >= 1
|
||||
? ' · You have saved $' + formatCurrency(stats.summary.cost.total_saved_usd) + ' on this machine. Get the same savings across your team, with 3 months free on a 12-month plan.'
|
||||
: ' · Bring these savings to your whole team, with 3 months free on a 12-month plan.'"></span>
|
||||
? ' · You have saved $' + formatCurrency(stats.summary.cost.total_saved_usd) + ' on this machine. Want more? Headroom Enterprise saves more, across your whole team. Talk to us at hello@headroomlabs.ai.'
|
||||
: ' · Want more savings? Headroom Enterprise saves more, across your whole team. Talk to us at hello@headroomlabs.ai.'"></span>
|
||||
</p>
|
||||
<div class="flex items-center gap-3 shrink-0">
|
||||
<a href="https://headroom-perks.vercel.app/?source=github&utm_source=headroom&utm_medium=dashboard&utm_content=banner"
|
||||
<a href="https://headroomlabs.ai"
|
||||
target="_blank" rel="noopener noreferrer"
|
||||
class="px-3 py-1.5 text-sm font-medium rounded-md bg-accent text-black hover:opacity-90">Claim 3 months free →</a>
|
||||
class="px-3 py-1.5 text-sm font-medium rounded-md bg-accent text-black hover:opacity-90">Talk to us →</a>
|
||||
<button type="button" @click="dismissTeamsPerk()" aria-label="Dismiss Headroom for Teams offer"
|
||||
class="text-sm text-gray-500 hover:text-gray-200">✕</button>
|
||||
</div>
|
||||
@@ -2056,12 +2056,12 @@
|
||||
return {
|
||||
stats: {},
|
||||
teamsPerkDismissed: (() => {
|
||||
try { return localStorage.getItem('headroom-teams-perk-dismissed') === '1'; }
|
||||
try { return localStorage.getItem('headroom-teams-contact-dismissed') === '1'; }
|
||||
catch (e) { return false; }
|
||||
})(),
|
||||
dismissTeamsPerk() {
|
||||
this.teamsPerkDismissed = true;
|
||||
try { localStorage.setItem('headroom-teams-perk-dismissed', '1'); } catch (e) {}
|
||||
try { localStorage.setItem('headroom-teams-contact-dismissed', '1'); } catch (e) {}
|
||||
},
|
||||
lifetimeStats: {},
|
||||
historyStats: {},
|
||||
|
||||
@@ -15,7 +15,7 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from headroom.offline import guard_egress
|
||||
from headroom.offline import guard_egress, pin_litellm_cost_map_local
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from headroom.transforms.html_extractor import HTMLExtractor
|
||||
@@ -316,6 +316,7 @@ class HTMLExtractionEvaluator:
|
||||
|
||||
else:
|
||||
try:
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
|
||||
def judge(question: str, ground_truth: str, prediction: str) -> tuple[float, str]:
|
||||
@@ -396,6 +397,7 @@ Answer concisely and factually based only on the content provided."""
|
||||
)
|
||||
|
||||
else:
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
|
||||
litellm_response = litellm.completion(
|
||||
|
||||
@@ -17,7 +17,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from collections.abc import Callable
|
||||
|
||||
from headroom.offline import guard_egress
|
||||
from headroom.offline import guard_egress, pin_litellm_cost_map_local
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -169,6 +169,7 @@ def create_litellm_judge(
|
||||
score, reasoning = judge_fn(question, ground_truth, prediction)
|
||||
"""
|
||||
try:
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
|
||||
@@ -30,6 +30,7 @@ from headroom.evals.memory.locomo import (
|
||||
)
|
||||
from headroom.evals.metrics import compute_exact_match, compute_f1
|
||||
from headroom.memory import HierarchicalMemory, MemoryConfig
|
||||
from headroom.offline import pin_litellm_cost_map_local
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -277,6 +278,7 @@ class LoCoMoEvaluator:
|
||||
List of extracted memory dicts with 'content' and 'category'.
|
||||
"""
|
||||
try:
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
except ImportError:
|
||||
logger.warning("litellm not available, falling back to raw dialogue storage")
|
||||
|
||||
@@ -24,8 +24,6 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import litellm
|
||||
|
||||
from headroom.evals.memory.locomo import (
|
||||
LOCOMO_CATEGORIES,
|
||||
LoCoMoCase,
|
||||
@@ -37,6 +35,12 @@ from headroom.memory.backends.local import LocalBackend, LocalBackendConfig
|
||||
from headroom.memory.models import Memory
|
||||
from headroom.memory.system import MemoryBackend
|
||||
from headroom.memory.tools import MEMORY_TOOLS
|
||||
from headroom.offline import pin_litellm_cost_map_local
|
||||
|
||||
# Before the import: litellm fetches its pricing table at import time unless
|
||||
# told not to, and HEADROOM_OFFLINE forbids that fetch.
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm # noqa: E402
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
+114
-40
@@ -28,21 +28,41 @@ Scope of the guarantee — read this before citing it in a threat model:
|
||||
the wrong inode by a path that changed underneath us. ``O_NOFOLLOW`` means a
|
||||
symlink planted at the path fails the open outright rather than redirecting
|
||||
the write.
|
||||
* **Windows**: *not* enforced, and deliberately not claimed. Who may read an
|
||||
NTFS file is decided by its ACL. ``os.chmod`` on Windows only toggles the
|
||||
read-only attribute and leaves the ACL untouched, so ``chmod(0o600)`` returns
|
||||
successfully while ``stat.S_IMODE`` still reports ``0666`` and the file stays
|
||||
readable per the inherited ACL. Python ships no ACL API, so Headroom does not
|
||||
pretend to set one: on Windows the log inherits the ACL of its parent
|
||||
directory and :data:`OWNER_ONLY_SUPPORTED` is ``False``. Callers that create
|
||||
sensitive files say so once in the log (see
|
||||
``headroom.proxy.helpers._setup_file_logging``), and operators should treat
|
||||
the log directory itself as the access-control boundary — keep it under the
|
||||
user profile, and do not put it on a share.
|
||||
* **Windows**: mode bits do not control read access there — who may read an
|
||||
NTFS file is decided by its ACL, and ``os.chmod`` only toggles the
|
||||
read-only attribute and leaves the ACL untouched, so ``chmod(0o600)``
|
||||
returns successfully while ``stat.S_IMODE`` still reports ``0666``. That is
|
||||
why :data:`OWNER_ONLY_SUPPORTED` — "mode bits enforce this" — is ``False``
|
||||
on Windows and stays that way regardless of the rest of this paragraph.
|
||||
:func:`restrict_fd_to_owner` and :func:`restrict_path_to_owner` nonetheless
|
||||
restrict the log, its rotated backups, and the JSONL request log there too,
|
||||
through :mod:`headroom._fileperms_windows`: a DACL with exactly one entry
|
||||
(the calling user, full control), built fresh rather than merged with the
|
||||
inherited entries that made the file readable in the first place, and
|
||||
applied with ``PROTECTED_DACL_SECURITY_INFORMATION`` so those inherited
|
||||
entries are dropped rather than left alongside it. Unlike the POSIX path
|
||||
this can fail per-call (a non-NTFS volume, a missing privilege), so callers
|
||||
that need to know whether it actually took effect call
|
||||
:func:`verify_owner_only` rather than trusting the static flag — see
|
||||
``headroom.proxy.helpers._warn_once_if_not_protected``, which warns only
|
||||
when verification fails rather than unconditionally on Windows. Not
|
||||
extended (yet) to the sqlite-backed memory/CCR stores
|
||||
(:func:`ensure_private_file`/:func:`connect_private_sqlite`) or
|
||||
:func:`private_dir` — those remain unenforced on Windows, same as before.
|
||||
|
||||
``O_NOFOLLOW`` does not exist on Windows either, so the symlink protection
|
||||
there is the explicit :func:`is_symlink` check callers make before opening, not
|
||||
a kernel-enforced one.
|
||||
``O_NOFOLLOW`` does not exist on Windows, so the CRT ``os.open`` underneath
|
||||
Python's own ``open()`` has no way to refuse a symlink/junction there — it
|
||||
silently follows one to whatever it points at. :func:`open_owner_only` does
|
||||
not route through that on Windows for this reason: it opens via
|
||||
``headroom._fileperms_windows.open_no_follow``, which uses
|
||||
``FILE_FLAG_OPEN_REPARSE_POINT`` to open the reparse point itself regardless
|
||||
of create-or-open disposition, and refuses it outright if the resulting
|
||||
handle's own attributes show it is one — closing the same gap ``O_NOFOLLOW``
|
||||
closes on POSIX, checked on the handle rather than the path so there is
|
||||
nothing for a race to redirect. :func:`restrict_path_to_owner` uses the same
|
||||
flag for the same reason when narrowing a file it did not open itself
|
||||
(rotated backups): because that path only ever touches the reparse point's
|
||||
own DACL, never a target's, it is safe even without the attribute check.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -62,9 +82,14 @@ OWNER_ONLY_MODE = 0o600
|
||||
OWNER_ONLY_DIR_MODE = 0o700
|
||||
|
||||
#: ``True`` only where the mode bits above actually decide who can read the
|
||||
#: file. See the module docstring for why Windows is excluded.
|
||||
#: file. See the module docstring for why Windows is excluded -- it has its
|
||||
#: own, separately-verified mechanism instead, not reflected in this flag.
|
||||
OWNER_ONLY_SUPPORTED = os.name == "posix"
|
||||
|
||||
_win: Any = None
|
||||
if os.name == "nt":
|
||||
from . import _fileperms_windows as _win
|
||||
|
||||
|
||||
def _open_flags(*, truncate: bool = False) -> int:
|
||||
flags = os.O_CREAT | os.O_WRONLY | (os.O_TRUNC if truncate else os.O_APPEND)
|
||||
@@ -83,14 +108,17 @@ def restrict_fd_to_owner(fd: int) -> bool:
|
||||
|
||||
Acts on the descriptor, not the path, so there is no window in which the
|
||||
mode could land on a different file, and no way for a symlink to move it.
|
||||
Returns ``False`` on platforms where the mode bits do not carry the
|
||||
guarantee rather than reporting a protection that was not established.
|
||||
On Windows this goes through :mod:`headroom._fileperms_windows` instead
|
||||
of mode bits (see the module docstring); returns ``False`` if that fails
|
||||
too, rather than reporting a protection that was not established.
|
||||
"""
|
||||
if not OWNER_ONLY_SUPPORTED:
|
||||
return False
|
||||
if stat.S_IMODE(os.fstat(fd).st_mode) != OWNER_ONLY_MODE:
|
||||
os.fchmod(fd, OWNER_ONLY_MODE)
|
||||
return True
|
||||
if OWNER_ONLY_SUPPORTED:
|
||||
if stat.S_IMODE(os.fstat(fd).st_mode) != OWNER_ONLY_MODE:
|
||||
os.fchmod(fd, OWNER_ONLY_MODE)
|
||||
return True
|
||||
if _win is not None:
|
||||
return bool(_win.restrict_handle(fd))
|
||||
return False
|
||||
|
||||
|
||||
def restrict_path_to_owner(path: str | os.PathLike[str]) -> bool:
|
||||
@@ -98,18 +126,43 @@ def restrict_path_to_owner(path: str | os.PathLike[str]) -> bool:
|
||||
|
||||
For files Headroom did not open itself — rotated log backups, and backups
|
||||
left behind by an older unhardened run. A path that is a symlink is left
|
||||
alone: the target is not ours to re-permission.
|
||||
alone on every platform: the target is not ours to re-permission. On
|
||||
Windows the ACL path (see the module docstring) adds
|
||||
``FILE_FLAG_OPEN_REPARSE_POINT`` underneath that check as a second guard.
|
||||
"""
|
||||
if not OWNER_ONLY_SUPPORTED:
|
||||
return False
|
||||
try:
|
||||
if os.path.islink(path) or not os.path.exists(path):
|
||||
return False
|
||||
if stat.S_IMODE(os.stat(path).st_mode) != OWNER_ONLY_MODE:
|
||||
os.chmod(path, OWNER_ONLY_MODE)
|
||||
if OWNER_ONLY_SUPPORTED:
|
||||
if stat.S_IMODE(os.stat(path).st_mode) != OWNER_ONLY_MODE:
|
||||
os.chmod(path, OWNER_ONLY_MODE)
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
if _win is not None:
|
||||
return bool(_win.restrict_path(os.fspath(path)))
|
||||
return False
|
||||
|
||||
|
||||
def verify_owner_only(path: str | os.PathLike[str]) -> bool:
|
||||
"""Confirm *path* is restricted to its current owner right now.
|
||||
|
||||
Unlike :data:`OWNER_ONLY_SUPPORTED` (a static per-platform flag) or the
|
||||
return value of :func:`restrict_fd_to_owner`/:func:`restrict_path_to_owner`
|
||||
(whether the API calls *reported* success), this re-reads the file's
|
||||
actual permissions. On Windows the ACL call can fail for reasons that
|
||||
have nothing to do with Headroom's code -- a non-NTFS volume, a missing
|
||||
privilege -- so a caller deciding whether to warn an operator should ask
|
||||
what happened to *this* file, not assume from the platform.
|
||||
"""
|
||||
if OWNER_ONLY_SUPPORTED:
|
||||
try:
|
||||
return stat.S_IMODE(os.stat(path).st_mode) == OWNER_ONLY_MODE
|
||||
except OSError:
|
||||
return False
|
||||
if _win is not None:
|
||||
return bool(_win.verify_path(os.fspath(path)))
|
||||
return False
|
||||
|
||||
|
||||
def open_owner_only(
|
||||
@@ -124,22 +177,43 @@ def open_owner_only(
|
||||
|
||||
Raises ``OSError`` — which every caller already treats as "logging is
|
||||
unavailable, carry on" — if the path cannot be opened, including when it is
|
||||
a symlink on a platform with ``O_NOFOLLOW``. Failing closed is deliberate:
|
||||
a redirected sensitive log is worse than no log.
|
||||
a symlink or junction. Failing closed is deliberate: a redirected sensitive
|
||||
log is worse than no log.
|
||||
|
||||
On POSIX, ``O_NOFOLLOW`` makes the ``os.open`` below refuse a symlink at
|
||||
the kernel level. Windows has no such flag -- plain ``os.open`` there
|
||||
silently follows a planted symlink/junction to whatever it points at, so
|
||||
a DACL applied afterward lands on the target, not the intended file; this
|
||||
goes through :func:`headroom._fileperms_windows.open_no_follow` instead,
|
||||
which opens the reparse point itself and verifies that before touching
|
||||
anything, closing the one path/open gap ``O_NOFOLLOW`` closes on POSIX.
|
||||
"""
|
||||
if mode[:1] not in ("a", "w"):
|
||||
raise ValueError(f"open_owner_only: mode must start with 'a' or 'w', got {mode!r}")
|
||||
fd = os.open(path, _open_flags(truncate=mode.startswith("w")), OWNER_ONLY_MODE)
|
||||
try:
|
||||
restrict_fd_to_owner(fd)
|
||||
return open(fd, mode, encoding=encoding, errors=errors, newline=newline, closefd=True)
|
||||
except BaseException:
|
||||
truncate = mode.startswith("w")
|
||||
if OWNER_ONLY_SUPPORTED:
|
||||
fd = os.open(path, _open_flags(truncate=truncate), OWNER_ONLY_MODE)
|
||||
try:
|
||||
os.close(fd)
|
||||
except OSError:
|
||||
# open() can have taken and closed the descriptor on its way out.
|
||||
pass
|
||||
raise
|
||||
restrict_fd_to_owner(fd)
|
||||
return open(fd, mode, encoding=encoding, errors=errors, newline=newline, closefd=True)
|
||||
except BaseException:
|
||||
try:
|
||||
os.close(fd)
|
||||
except OSError:
|
||||
# open() can have taken and closed the descriptor on its way out.
|
||||
pass
|
||||
raise
|
||||
if _win is not None:
|
||||
fd = _win.open_no_follow(os.fspath(path), truncate=truncate)
|
||||
try:
|
||||
return open(fd, mode, encoding=encoding, errors=errors, newline=newline, closefd=True)
|
||||
except BaseException:
|
||||
try:
|
||||
os.close(fd)
|
||||
except OSError:
|
||||
pass
|
||||
raise
|
||||
return open(path, mode, encoding=encoding, errors=errors, newline=newline)
|
||||
|
||||
|
||||
def ensure_private_file(path: str | os.PathLike[str], *, what: str = "file") -> None:
|
||||
|
||||
@@ -36,6 +36,7 @@ if TYPE_CHECKING:
|
||||
# Import the enum from the dependency-free module so importing the compressor
|
||||
# does not eagerly import trained_router (and thus torch/transformers) — that
|
||||
# eager import crashed on Python 3.13+ (#2513).
|
||||
from .decoder_guard import pillow_is_safe
|
||||
from .image_types import ImageMemo, Technique
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -333,13 +334,11 @@ class ImageCompressor:
|
||||
# Resize
|
||||
resized = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
||||
|
||||
# Convert to RGB if needed (for JPEG)
|
||||
if resized.mode in ("RGBA", "P"):
|
||||
resized = resized.convert("RGB")
|
||||
|
||||
# Save as JPEG for best compression
|
||||
from .tile_optimizer import _jpeg_ready
|
||||
|
||||
buf = io.BytesIO()
|
||||
resized.save(buf, format="JPEG", quality=quality, optimize=True)
|
||||
_jpeg_ready(resized).save(buf, format="JPEG", quality=quality, optimize=True)
|
||||
return buf.getvalue(), "image/jpeg"
|
||||
|
||||
def _estimate_tokens(self, image_data: bytes, detail: str = "high") -> int:
|
||||
@@ -702,7 +701,12 @@ class ImageCompressor:
|
||||
Returns:
|
||||
Messages with compressed images
|
||||
"""
|
||||
if not self.has_images(messages):
|
||||
# Reset first: the per-worker singleton (proxy/image_isolation.py) keeps
|
||||
# one ImageCompressor for every request and reports last_result whenever
|
||||
# it is not None, so a request we return early on below must not inherit
|
||||
# the previous request's technique and token numbers.
|
||||
self.last_result = None
|
||||
if not self.has_images(messages) or not pillow_is_safe():
|
||||
return messages
|
||||
|
||||
# Step 1: Tile-boundary optimization (always safe, pure math)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
"""Never decode untrusted images with a Pillow that has known decoder bugs.
|
||||
|
||||
Pillow 13.0.0 is the only fix for ten decoder CVEs on untrusted images
|
||||
(CVE-2026-112395, -112895 and others). uv.lock and the release image take 13, but the published
|
||||
package metadata cannot require it: fastembed caps ``pillow<13``, so
|
||||
``pip install headroom-ai[all]`` resolves 12.x, and Python 3.10 has no Pillow 13
|
||||
at all. On those installs Headroom forwards images unchanged instead of opening
|
||||
them. Remove this once fastembed allows Pillow 13 and the image extra requires it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
FIXED_PILLOW_MAJOR = 13
|
||||
|
||||
|
||||
@functools.cache
|
||||
def pillow_is_safe() -> bool:
|
||||
"""True when the imported Pillow has the decoder fixes; warns once if not."""
|
||||
try:
|
||||
import PIL
|
||||
except ImportError:
|
||||
return False # Nothing can decode; the image paths already skip.
|
||||
installed = PIL.__version__
|
||||
if int(installed.split(".")[0]) >= FIXED_PILLOW_MAJOR:
|
||||
return True
|
||||
logger.warning(
|
||||
"Headroom will not decode images: Pillow %s has decoder vulnerabilities "
|
||||
"fixed only in Pillow %d, so images are forwarded unchanged and not "
|
||||
"compressed. Install pillow>=%d (Python 3.11+) to turn image compression on.",
|
||||
installed,
|
||||
FIXED_PILLOW_MAJOR,
|
||||
FIXED_PILLOW_MAJOR,
|
||||
)
|
||||
return False
|
||||
@@ -167,6 +167,29 @@ def find_optimal_anthropic_dimensions(width: int, height: int) -> tuple[int, int
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _jpeg_ready(img: Any) -> Any:
|
||||
"""Return ``img`` in a mode JPEG can store.
|
||||
|
||||
JPEG has no alpha, and ``convert("RGB")`` simply drops it, so transparent
|
||||
pixels show their hidden colour (usually black). Composite them onto
|
||||
white instead: alpha bands, palette transparency and PNG ``tRNS`` on RGB
|
||||
or grayscale images alike. Palette, bilevel and CMYK/YCbCr images convert
|
||||
to RGB. High-bit-depth modes (``I;16``, ``I``, ``F``) have no faithful
|
||||
8-bit form, so they are returned as-is and the JPEG save fails as before,
|
||||
which makes callers keep the original image.
|
||||
"""
|
||||
from PIL import Image
|
||||
|
||||
if img.has_transparency_data:
|
||||
rgba = img.convert("RGBA")
|
||||
flat = Image.new("RGB", rgba.size, (255, 255, 255))
|
||||
flat.paste(rgba, mask=rgba.getchannel("A"))
|
||||
return flat
|
||||
if img.mode in ("1", "P", "CMYK", "YCbCr"):
|
||||
return img.convert("RGB")
|
||||
return img
|
||||
|
||||
|
||||
def _resize_image_bytes(
|
||||
image_data: bytes, target_width: int, target_height: int
|
||||
) -> tuple[bytes, str]:
|
||||
@@ -182,12 +205,8 @@ def _resize_image_bytes(
|
||||
|
||||
resized = img.resize((target_width, target_height), Image.Resampling.LANCZOS)
|
||||
|
||||
# Convert RGBA to RGB for JPEG
|
||||
if resized.mode in ("RGBA", "P"):
|
||||
resized = resized.convert("RGB")
|
||||
|
||||
buf = io.BytesIO()
|
||||
resized.save(buf, format="JPEG", quality=85, optimize=True)
|
||||
_jpeg_ready(resized).save(buf, format="JPEG", quality=85, optimize=True)
|
||||
return buf.getvalue(), "image/jpeg"
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -11,8 +13,88 @@ import click
|
||||
|
||||
from headroom import paths as _paths
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_PROFILE_RE = re.compile(r"^[A-Za-z0-9._-]+$")
|
||||
|
||||
# A deployment profile directory holds secrets. `headroom install --env
|
||||
# KEY=VALUE` is the supported way to give a supervised proxy a provider API key
|
||||
# — supervisors (launchd, systemd, Task Scheduler, cron) start from a bare
|
||||
# environment, so nothing else reaches the process — and every such value is
|
||||
# persisted verbatim, both into `manifest.json` and into the generated runner
|
||||
# scripts that `export` it before the exec. Those files are therefore written
|
||||
# owner-only rather than at the process umask (which leaves them world-readable
|
||||
# at the common 022). The supervisor always runs them as the installing user
|
||||
# (user scope) or as root (system scope), and neither needs the group/other
|
||||
# bits, so this is not a functional restriction.
|
||||
#
|
||||
# SECURITY.md documents these modes; `tests/test_packaging_extras_and_security_docs.py`
|
||||
# reads the octal values back out of that document and compares them with what
|
||||
# an install actually writes, so the policy and the code cannot drift apart.
|
||||
# Named for what they ARE -- a permission mode -- not for what the files they
|
||||
# protect contain. The previous SECRET_* spelling read as a credential to
|
||||
# CodeQL's sensitive-data heuristic, so `logger.warning("... 0o%o", mode)`
|
||||
# tripped py/clear-text-logging-sensitive-data on a diagnostic that logs a
|
||||
# permission bitmask and no secret at all.
|
||||
OWNER_ONLY_FILE_MODE = 0o600
|
||||
OWNER_ONLY_SCRIPT_MODE = 0o700
|
||||
OWNER_ONLY_DIR_MODE = 0o700
|
||||
|
||||
|
||||
#: Whether this platform actually enforces POSIX permission bits. On Windows
|
||||
#: access is governed by ACLs and ``chmod`` only toggles the read-only flag, so
|
||||
#: it SUCCEEDS without establishing the requested mode — which is why the check
|
||||
#: below reads the mode back rather than trusting the call not to raise.
|
||||
POSIX_MODES_ENFORCED = os.name == "posix"
|
||||
|
||||
|
||||
def chmod_owner_only(path: Path, mode: int) -> bool:
|
||||
"""Narrow ``path`` to an owner-only ``mode``. Returns whether that took.
|
||||
|
||||
This used to swallow every ``OSError`` and return nothing, so a caller had
|
||||
no way to tell a restricted file from an unrestricted one and continued as
|
||||
if the documented mode had been established. That is the wrong default for
|
||||
the two places it matters, because both NARROW A PRE-EXISTING INODE rather
|
||||
than create one: a profile directory made before these modes existed is
|
||||
0755, and a runner script rewritten through ``O_TRUNC`` keeps whatever mode
|
||||
it already had. In both cases this chmod is the only thing standing between
|
||||
a provider API key and every local user, and a silent failure left the
|
||||
caller asserting a guarantee it did not have.
|
||||
|
||||
The result is verified with ``stat`` instead of inferred from ``chmod`` not
|
||||
raising, because on Windows it does not raise and does not work either.
|
||||
|
||||
Returns ``True`` only when the mode is now exactly ``mode``. A caller
|
||||
holding secret-bearing content must act on ``False``; see
|
||||
:func:`headroom.install.supervisors._write_private_text`, which refuses to
|
||||
leave the file behind.
|
||||
"""
|
||||
try:
|
||||
path.chmod(mode)
|
||||
actual = stat.S_IMODE(path.stat().st_mode)
|
||||
except OSError as exc:
|
||||
logger.warning(
|
||||
"Could not restrict %s to mode 0o%o (%s); it may be readable by other local users.",
|
||||
path,
|
||||
mode,
|
||||
exc,
|
||||
)
|
||||
return False
|
||||
if actual != mode:
|
||||
# Expected on Windows, where the bits are advisory -- noise there, a
|
||||
# real finding on POSIX.
|
||||
logger.log(
|
||||
logging.WARNING if POSIX_MODES_ENFORCED else logging.DEBUG,
|
||||
"%s is mode 0o%o after asking for 0o%o; this platform does not "
|
||||
"enforce POSIX permission bits, so the file's protection comes "
|
||||
"from its directory and the system ACLs instead.",
|
||||
path,
|
||||
actual,
|
||||
mode,
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validate_profile_name(profile: str) -> str:
|
||||
"""Validate and normalize a deployment profile name."""
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
@@ -32,7 +33,8 @@ def _merge_marker_block(file_path: Path, block: str, pattern: re.Pattern[str], m
|
||||
if file_path.exists():
|
||||
existing = fsutil.read_text(file_path)
|
||||
if marker in existing:
|
||||
return pattern.sub(block, existing)
|
||||
# A callable replacement: the block is literal text, not a template.
|
||||
return pattern.sub(lambda _match: block, existing)
|
||||
return existing.rstrip() + "\n\n" + block + "\n"
|
||||
return block + "\n"
|
||||
|
||||
@@ -40,7 +42,8 @@ def _merge_marker_block(file_path: Path, block: str, pattern: re.Pattern[str], m
|
||||
def _env_block(values: dict[str, str]) -> str:
|
||||
lines = [_ENV_MARKER_START]
|
||||
for name, value in values.items():
|
||||
lines.append(f'export {name}="{value}"')
|
||||
# shlex.quote so `$`, `"` and backticks reach the shell verbatim.
|
||||
lines.append(f"export {name}={shlex.quote(value)}")
|
||||
lines.append(_ENV_MARKER_END)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
@@ -160,6 +160,18 @@ def build_runtime_command(manifest: DeploymentManifest) -> list[str]:
|
||||
container_home,
|
||||
"--env",
|
||||
f"HOME={container_home}",
|
||||
# Docker creates the parent of every bind mount as root:root when it is
|
||||
# absent from the image, so $HOME itself is NOT writable by the
|
||||
# --user <host-uid> process (issue #4207). Anything that writes under
|
||||
# $HOME outside the mounts then fails, which is what breaks the
|
||||
# HuggingFace download of the Kompress model. Point the HuggingFace and
|
||||
# XDG caches at the bind-mounted workspace instead: that directory
|
||||
# belongs to the host user the container runs as, so it is writable,
|
||||
# and it survives `docker rm` of the container.
|
||||
"--env",
|
||||
f"HF_HOME={container_home}/.headroom/cache/huggingface",
|
||||
"--env",
|
||||
f"XDG_CACHE_HOME={container_home}/.headroom/cache",
|
||||
"--env",
|
||||
"PYTHONUNBUFFERED=1",
|
||||
# Canonical Headroom filesystem contract (issue #175).
|
||||
|
||||
@@ -12,7 +12,16 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .models import ArtifactRecord, DeploymentManifest, ManagedMutation, iso_utc_now
|
||||
from .paths import deploy_root, manifest_path, profile_root, recovery_manifest_path
|
||||
from .paths import (
|
||||
OWNER_ONLY_DIR_MODE,
|
||||
OWNER_ONLY_FILE_MODE,
|
||||
POSIX_MODES_ENFORCED,
|
||||
chmod_owner_only,
|
||||
deploy_root,
|
||||
manifest_path,
|
||||
profile_root,
|
||||
recovery_manifest_path,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -29,6 +38,15 @@ def _atomic_write_text(path: Path, data: str) -> None:
|
||||
both POSIX and Windows). A crash between truncate and full write therefore
|
||||
leaves either the previous file or the complete new one on disk, never a
|
||||
truncated manifest.
|
||||
|
||||
The file is owner-only. ``manifest.base_env`` holds whatever
|
||||
``headroom install --env KEY=VALUE`` was given, and that is the supported
|
||||
way to hand a provider API key to a supervised proxy (supervisors start
|
||||
from a bare environment), so the manifest must be assumed to contain
|
||||
secrets. :func:`tempfile.mkstemp` already creates the temporary file 0600
|
||||
and :func:`os.replace` carries that mode across, but the chmod is explicit
|
||||
so the guarantee survives a future rewrite of this function and is pinned
|
||||
by a test rather than inherited by accident.
|
||||
"""
|
||||
directory = path.parent
|
||||
fd, tmp_name = tempfile.mkstemp(dir=directory, prefix=f".{path.name}.", suffix=".tmp")
|
||||
@@ -38,6 +56,7 @@ def _atomic_write_text(path: Path, data: str) -> None:
|
||||
handle.write(data)
|
||||
handle.flush()
|
||||
os.fsync(handle.fileno())
|
||||
chmod_owner_only(tmp_path, OWNER_ONLY_FILE_MODE)
|
||||
os.replace(tmp_path, path)
|
||||
except BaseException:
|
||||
tmp_path.unlink(missing_ok=True)
|
||||
@@ -48,9 +67,39 @@ def _manifest_json(manifest: DeploymentManifest) -> str:
|
||||
return json.dumps(asdict(manifest), indent=2) + "\n"
|
||||
|
||||
|
||||
def _save_manifest_at(path: Path, manifest: DeploymentManifest, *, strict: bool) -> None:
|
||||
def _narrow_profile_root(root: Path) -> None:
|
||||
"""Make a deployment profile directory owner-only.
|
||||
|
||||
``exist_ok=True`` leaves a pre-existing directory's mode alone, and a
|
||||
profile created before owner-only modes is 0755, so narrow it on every save
|
||||
rather than only at creation.
|
||||
|
||||
Not fatal, unlike the runner script: the manifest itself is created through
|
||||
``mkstemp``, which is 0600 from birth, so a directory that could not be
|
||||
narrowed weakens the outer layer without exposing the file. Warn rather
|
||||
than abandon a deployment over it.
|
||||
"""
|
||||
if not chmod_owner_only(root, OWNER_ONLY_DIR_MODE) and POSIX_MODES_ENFORCED:
|
||||
logger.warning(
|
||||
"Deployment profile directory %s is not owner-only; the "
|
||||
"manifest inside it is still 0o%o, but other local users can "
|
||||
"list the directory.",
|
||||
root,
|
||||
OWNER_ONLY_FILE_MODE,
|
||||
)
|
||||
|
||||
|
||||
def _save_manifest_at(
|
||||
path: Path,
|
||||
manifest: DeploymentManifest,
|
||||
*,
|
||||
strict: bool,
|
||||
owner_only_dir: bool = False,
|
||||
) -> None:
|
||||
root = path.parent
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
if owner_only_dir:
|
||||
_narrow_profile_root(root)
|
||||
manifest.updated_at = iso_utc_now()
|
||||
try:
|
||||
_atomic_write_text(path, _manifest_json(manifest))
|
||||
@@ -66,9 +115,16 @@ def save_manifest(manifest: DeploymentManifest) -> None:
|
||||
The write is atomic so an interrupted save (SIGKILL, system restart, OOM)
|
||||
cannot leave a truncated ``manifest.json`` behind. Gracefully handles
|
||||
read-only filesystems by logging a warning instead of crashing.
|
||||
|
||||
The profile directory and the manifest are owner-only: ``base_env`` carries
|
||||
whatever ``headroom install --env`` was given, which is the supported way to
|
||||
hand a provider API key to a supervised proxy. See
|
||||
:data:`headroom.install.paths.OWNER_ONLY_DIR_MODE`.
|
||||
"""
|
||||
try:
|
||||
_save_manifest_at(manifest_path(manifest.profile), manifest, strict=False)
|
||||
_save_manifest_at(
|
||||
manifest_path(manifest.profile), manifest, strict=False, owner_only_dir=True
|
||||
)
|
||||
except OSError as e:
|
||||
logger.warning("Cannot save deployment manifest: %s — continuing without persistence", e)
|
||||
|
||||
@@ -76,7 +132,7 @@ def save_manifest(manifest: DeploymentManifest) -> None:
|
||||
def save_manifest_strict(manifest: DeploymentManifest) -> None:
|
||||
"""Persist a manifest and propagate errors when recovery depends on it."""
|
||||
|
||||
_save_manifest_at(manifest_path(manifest.profile), manifest, strict=True)
|
||||
_save_manifest_at(manifest_path(manifest.profile), manifest, strict=True, owner_only_dir=True)
|
||||
|
||||
|
||||
def save_recovery_manifest(manifest: DeploymentManifest) -> None:
|
||||
|
||||
@@ -21,6 +21,10 @@ from headroom._subprocess import run
|
||||
|
||||
from .models import ArtifactRecord, DeploymentManifest, SupervisorKind
|
||||
from .paths import (
|
||||
OWNER_ONLY_FILE_MODE,
|
||||
OWNER_ONLY_SCRIPT_MODE,
|
||||
POSIX_MODES_ENFORCED,
|
||||
chmod_owner_only,
|
||||
unix_ensure_script_path,
|
||||
unix_run_script_path,
|
||||
windows_ensure_cmd_path,
|
||||
@@ -47,6 +51,32 @@ def _is_windows() -> bool:
|
||||
return sys.platform.startswith("win")
|
||||
|
||||
|
||||
def _write_private_text(path: Path, data: str, mode: int) -> None:
|
||||
"""Atomically replace a secret-bearing runner with a private new inode.
|
||||
|
||||
Creating the temporary file exclusively avoids following a replacement
|
||||
hard link. Restrict it before publishing; a failed write, restriction or
|
||||
replacement leaves the previous runner and unrelated files untouched.
|
||||
"""
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
fd, name = tempfile.mkstemp(prefix=f".{path.name}.", suffix=".tmp", dir=path.parent)
|
||||
temporary = Path(name)
|
||||
try:
|
||||
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
||||
if hasattr(os, "fchmod"):
|
||||
os.fchmod(handle.fileno(), mode)
|
||||
handle.write(data)
|
||||
if not chmod_owner_only(temporary, mode) and POSIX_MODES_ENFORCED:
|
||||
raise click.ClickException(
|
||||
f"Refusing to write {path}: permissions could not be restricted "
|
||||
f"to {oct(mode)}, and the file carries any API key passed via "
|
||||
f"`headroom install --env`. Fix directory permissions and re-run."
|
||||
)
|
||||
os.replace(temporary, path)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def _validated_env_items(env: dict[str, str] | None) -> list[tuple[str, str]]:
|
||||
items = list((env or {}).items())
|
||||
for name, _value in items:
|
||||
@@ -101,14 +131,19 @@ def _render_unix_runner(
|
||||
export_lines = "".join(
|
||||
f"export {name}={shlex.quote(value)}\n" for name, value in _validated_env_items(env)
|
||||
)
|
||||
path.write_text(
|
||||
# 0700, not 0755: `export_lines` can contain a provider API key in
|
||||
# cleartext (see `_write_private_text`). The supervisor runs this script as
|
||||
# the installing user for a user-scope install and as root for a
|
||||
# system-scope one, so dropping group/other loses nothing.
|
||||
_write_private_text(
|
||||
path,
|
||||
"#!/usr/bin/env bash\nset -euo pipefail\n"
|
||||
+ export_lines
|
||||
+ "exec "
|
||||
+ " ".join(shlex.quote(x) for x in command)
|
||||
+ "\n"
|
||||
+ "\n",
|
||||
OWNER_ONLY_SCRIPT_MODE,
|
||||
)
|
||||
path.chmod(0o755)
|
||||
return ArtifactRecord(kind="script", path=str(path))
|
||||
|
||||
|
||||
@@ -124,9 +159,17 @@ def _render_windows_runner(
|
||||
env_lines = "".join(
|
||||
f"$env:{name} = {_powershell_literal(value)}\n" for name, value in _validated_env_items(env)
|
||||
)
|
||||
ps1_path.write_text(
|
||||
f"$ErrorActionPreference = 'Stop'\n{env_lines}& {escaped}\nexit $LASTEXITCODE\n"
|
||||
# The .ps1 carries `$env:` assignments that can include a provider API key,
|
||||
# so it is owner-only like its POSIX counterpart. Windows resolves access
|
||||
# by ACL rather than by these bits, but the mode still matters when the
|
||||
# profile directory is read from WSL, a backup, or a synced home.
|
||||
_write_private_text(
|
||||
ps1_path,
|
||||
f"$ErrorActionPreference = 'Stop'\n{env_lines}& {escaped}\nexit $LASTEXITCODE\n",
|
||||
OWNER_ONLY_FILE_MODE,
|
||||
)
|
||||
# The .cmd shim holds no secrets — it only invokes the .ps1 — so it keeps a
|
||||
# conventional mode.
|
||||
cmd_path.write_text(
|
||||
'@echo off\r\npowershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0'
|
||||
+ ps1_path.name
|
||||
@@ -651,6 +694,11 @@ def start_supervisor(manifest: DeploymentManifest) -> None:
|
||||
subprocess.run(["schtasks", "/Run", "/TN", f"{manifest.service_name}-startup"], check=True)
|
||||
|
||||
|
||||
# `/End` and `/Delete` report a missing task as "cannot find the file specified";
|
||||
# `/Change` reports it as "does not exist in the system".
|
||||
_SCHTASKS_ABSENT_TEXT = ("cannot find the file specified", "does not exist in the system")
|
||||
|
||||
|
||||
def stop_supervisor(manifest: DeploymentManifest) -> None:
|
||||
"""Stop the installed supervisor for a deployment."""
|
||||
|
||||
@@ -687,10 +735,32 @@ def stop_supervisor(manifest: DeploymentManifest) -> None:
|
||||
)
|
||||
return
|
||||
if _is_windows():
|
||||
# Session-scoped fallback installs never create the `-startup` task,
|
||||
# and the health task may already be absent, so tolerate missing
|
||||
# tasks (schtasks reports "cannot find the file specified") while
|
||||
# still surfacing real failures such as access denied.
|
||||
health = f"{manifest.service_name}-health"
|
||||
subprocess.run(["schtasks", "/Change", "/TN", health, "/DISABLE"], check=True)
|
||||
result = run(
|
||||
["schtasks", "/Change", "/TN", health, "/DISABLE"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
_require_removal_success(
|
||||
result,
|
||||
"schtasks health disable",
|
||||
absent_text=_SCHTASKS_ABSENT_TEXT,
|
||||
)
|
||||
subprocess.run(["schtasks", "/End", "/TN", health], check=False)
|
||||
subprocess.run(["schtasks", "/End", "/TN", f"{manifest.service_name}-startup"], check=True)
|
||||
result = run(
|
||||
["schtasks", "/End", "/TN", f"{manifest.service_name}-startup"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
_require_removal_success(
|
||||
result,
|
||||
"schtasks startup end",
|
||||
absent_text=_SCHTASKS_ABSENT_TEXT,
|
||||
)
|
||||
|
||||
|
||||
def remove_supervisor(manifest: DeploymentManifest) -> None:
|
||||
@@ -785,7 +855,7 @@ def remove_supervisor(manifest: DeploymentManifest) -> None:
|
||||
_require_removal_success(
|
||||
result,
|
||||
f"schtasks {suffix} delete",
|
||||
absent_text="cannot find the file specified",
|
||||
absent_text=_SCHTASKS_ABSENT_TEXT,
|
||||
)
|
||||
|
||||
|
||||
@@ -800,7 +870,7 @@ def _require_removal_success(
|
||||
operation: str,
|
||||
*,
|
||||
absent_codes: set[int] | None = None,
|
||||
absent_text: str | None = None,
|
||||
absent_text: str | tuple[str, ...] | None = None,
|
||||
) -> None:
|
||||
returncode = int(getattr(result, "returncode", 0))
|
||||
detail = _result_text(result)
|
||||
@@ -808,6 +878,7 @@ def _require_removal_success(
|
||||
return
|
||||
if absent_codes and returncode in absent_codes:
|
||||
return
|
||||
if absent_text and absent_text in detail.lower():
|
||||
texts = (absent_text,) if isinstance(absent_text, str) else absent_text or ()
|
||||
if any(text in detail.lower() for text in texts):
|
||||
return
|
||||
raise click.ClickException(f"{operation} failed: {detail}")
|
||||
|
||||
@@ -27,7 +27,10 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from headroom.offline import pin_crewai_telemetry_off
|
||||
|
||||
try:
|
||||
pin_crewai_telemetry_off()
|
||||
from crewai.tools.base_tool import BaseTool
|
||||
|
||||
CREWAI_AVAILABLE = True
|
||||
|
||||
@@ -24,12 +24,13 @@ from headroom.integrations._compress_backend import ( # noqa: F401
|
||||
_DEFAULT_CLOUD_URL,
|
||||
CompressBackend,
|
||||
)
|
||||
from headroom.offline import guard_egress # noqa: F401
|
||||
from headroom.offline import guard_egress, pin_litellm_cost_map_local # noqa: F401
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
try:
|
||||
pin_litellm_cost_map_local()
|
||||
from litellm.integrations.custom_logger import CustomLogger as _CustomLogger
|
||||
except ImportError: # litellm not installed — fall back to plain object
|
||||
_CustomLogger = object # type: ignore[assignment,misc]
|
||||
|
||||
@@ -25,6 +25,7 @@ import time
|
||||
import typing
|
||||
|
||||
from headroom._subprocess import Popen, run
|
||||
from headroom.offline import pin_litellm_cost_map_local
|
||||
|
||||
from .loops import LoopPattern, apply_loop_weighting, detect_loops, format_loops_for_digest
|
||||
from .models import (
|
||||
@@ -1095,6 +1096,7 @@ def _call_llm(
|
||||
if model in _CLI_MODEL_IDS:
|
||||
return _call_cli_llm(digest, model, on_progress=on_progress)
|
||||
|
||||
pin_litellm_cost_map_local()
|
||||
import litellm
|
||||
|
||||
# Suppress LiteLLM's verbose logging
|
||||
|
||||
+51
-12
@@ -16,7 +16,7 @@ from pathlib import Path
|
||||
|
||||
from headroom._subprocess import run
|
||||
|
||||
from ..managed_block import block_pattern, sanitize_block_text
|
||||
from ..managed_block import sanitize_block_text
|
||||
from ._shared import claude_config_dir
|
||||
from .models import (
|
||||
ProjectInfo,
|
||||
@@ -29,7 +29,40 @@ from .models import (
|
||||
# cannot close the block early (see headroom.managed_block).
|
||||
_MARKER_START = "<!-- headroom:learn:start -->"
|
||||
_MARKER_END = "<!-- headroom:learn:end -->"
|
||||
_MARKER_PATTERN = block_pattern(_MARKER_START, _MARKER_END)
|
||||
|
||||
|
||||
def _find_managed_block(text: str) -> tuple[int, int] | None:
|
||||
"""Return the ``(start, end)`` offsets of the managed block, or None.
|
||||
|
||||
The block is a line that is exactly the start marker through the next line
|
||||
that is exactly the end marker -- the shape ``_build_section`` writes. A
|
||||
marker quoted inside prose (sharing its line with other text, or indented)
|
||||
or inside a fenced code block (a Markdown example) is not a block
|
||||
boundary, and a start marker with no end marker before the next start
|
||||
marker is not a block. Every reader and writer of the block in
|
||||
this module uses this one span, so the block that is parsed is the block
|
||||
that is replaced (#4339). ``end`` stops after the end marker, before its
|
||||
line break.
|
||||
"""
|
||||
offset = 0
|
||||
start: int | None = None
|
||||
fence: str | None = None # the open fence's run, e.g. "```" or "~~~~"
|
||||
for line in text.splitlines(keepends=True):
|
||||
bare = line.rstrip()
|
||||
stripped = bare.lstrip(" ")
|
||||
if len(bare) - len(stripped) <= 3 and stripped[:3] in ("```", "~~~"):
|
||||
run = len(stripped) - len(stripped.lstrip(stripped[0]))
|
||||
if fence is None:
|
||||
fence = stripped[0] * run
|
||||
elif stripped[0] == fence[0] and run >= len(fence) and not stripped[run:]:
|
||||
fence = None
|
||||
elif fence is None:
|
||||
if bare == _MARKER_START:
|
||||
start = offset
|
||||
elif bare == _MARKER_END and start is not None:
|
||||
return start, offset + len(bare)
|
||||
offset += len(line)
|
||||
return None
|
||||
|
||||
|
||||
def _read_text_tolerant(file_path: Path) -> str:
|
||||
@@ -258,8 +291,8 @@ def extract_marker_block(file_content: str) -> str | None:
|
||||
(including the start/end markers) so it can be fed back to an LLM as
|
||||
context without losing formatting. Returns None if no block is present.
|
||||
"""
|
||||
match = _MARKER_PATTERN.search(file_content)
|
||||
return match.group(0) if match else None
|
||||
span = _find_managed_block(file_content)
|
||||
return file_content[span[0] : span[1]] if span else None
|
||||
|
||||
|
||||
def _parse_prior_recommendations(existing: str) -> list[Recommendation]:
|
||||
@@ -270,10 +303,10 @@ def _parse_prior_recommendations(existing: str) -> list[Recommendation]:
|
||||
_build_section — target is set to a placeholder since the marker block
|
||||
itself doesn't record it (blocks are always per-file and per-target).
|
||||
"""
|
||||
match = _MARKER_PATTERN.search(existing)
|
||||
if not match:
|
||||
span = _find_managed_block(existing)
|
||||
if not span:
|
||||
return []
|
||||
inner = match.group(0)[len(_MARKER_START) : -len(_MARKER_END)]
|
||||
inner = existing[span[0] + len(_MARKER_START) : span[1] - len(_MARKER_END)]
|
||||
|
||||
recs: list[Recommendation] = []
|
||||
for part in re.split(r"\n### ", "\n" + inner)[1:]:
|
||||
@@ -364,8 +397,12 @@ def _merge_into_file(file_path: Path, new_recommendations: list[Recommendation])
|
||||
section = _build_section(merged)
|
||||
if file_path.exists():
|
||||
existing = _read_text_tolerant(file_path)
|
||||
if _MARKER_START in existing:
|
||||
return _MARKER_PATTERN.sub(lambda _match: section, existing)
|
||||
# Replace only the managed block itself; marker strings quoted in
|
||||
# prose on either side are hand-written text. No block (including a
|
||||
# start marker without its end marker) -> append a fresh one (#4339).
|
||||
span = _find_managed_block(existing)
|
||||
if span:
|
||||
return existing[: span[0]] + section + existing[span[1] :]
|
||||
return existing.rstrip() + "\n\n" + section + "\n"
|
||||
return section + "\n"
|
||||
|
||||
@@ -376,7 +413,9 @@ def _strip_marker_block(content: str) -> str:
|
||||
Used when migrating a stale block out of the team-shared CLAUDE.md into the
|
||||
personal CLAUDE.local.md. Returns "" if nothing but the block remained.
|
||||
"""
|
||||
cleaned = _MARKER_PATTERN.sub("", content)
|
||||
cleaned = content
|
||||
while span := _find_managed_block(cleaned):
|
||||
cleaned = cleaned[: span[0]] + cleaned[span[1] :]
|
||||
cleaned = re.sub(r"\n{3,}", "\n\n", cleaned).strip()
|
||||
return cleaned + "\n" if cleaned else ""
|
||||
|
||||
@@ -562,11 +601,11 @@ class ClaudeCodeWriter(ContextWriter):
|
||||
if target_path == legacy_path or not legacy_path.exists():
|
||||
return []
|
||||
legacy_text = _read_text_tolerant(legacy_path)
|
||||
if _MARKER_START not in legacy_text:
|
||||
if _find_managed_block(legacy_text) is None:
|
||||
return []
|
||||
# If the target already owns a block, it is the source of truth -- don't
|
||||
# double-migrate or clobber accumulated learnings.
|
||||
if target_path.exists() and _MARKER_START in _read_text_tolerant(target_path):
|
||||
if target_path.exists() and _find_managed_block(_read_text_tolerant(target_path)):
|
||||
return []
|
||||
|
||||
migrated = _parse_prior_recommendations(legacy_text)
|
||||
|
||||
@@ -18,6 +18,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from headroom import fsutil
|
||||
from headroom.providers.codex.config_toml import loads_codex_config, split_toml_lines
|
||||
|
||||
from .base import (
|
||||
MCPRegistrar,
|
||||
@@ -84,7 +85,7 @@ def _evict_foreign_tables(content: str, server_name: str, start: str, end: str)
|
||||
move, so a header-like line inside a multi-line string can split a table
|
||||
wrongly; callers must check the final result with ``_only_server_changed``.
|
||||
"""
|
||||
lines = content.splitlines(keepends=True)
|
||||
lines = split_toml_lines(content, keepends=True)
|
||||
try:
|
||||
i = next(n for n, line in enumerate(lines) if line.rstrip("\r\n") == start)
|
||||
j = next(n for n in range(i + 1, len(lines)) if lines[n].rstrip("\r\n") == end)
|
||||
@@ -121,7 +122,7 @@ def _only_server_changed(old: str, new: str, server_name: str) -> bool:
|
||||
makes this False and the rewrite is refused instead of written.
|
||||
"""
|
||||
try:
|
||||
before, after = tomllib.loads(old), tomllib.loads(new)
|
||||
before, after = loads_codex_config(old), loads_codex_config(new)
|
||||
except tomllib.TOMLDecodeError:
|
||||
return False
|
||||
return _without_server(before, server_name) == _without_server(after, server_name)
|
||||
@@ -255,7 +256,7 @@ class _TomlMarkerRegistrar(MCPRegistrar):
|
||||
# Read via fsutil (UTF-8 with locale fallback) so a config that a
|
||||
# tool wrote in the system locale (e.g. GBK) still parses instead
|
||||
# of failing tomllib's UTF-8 requirement. See #733.
|
||||
data = tomllib.loads(fsutil.read_text(self._config_file))
|
||||
data = loads_codex_config(fsutil.read_text(self._config_file))
|
||||
except (tomllib.TOMLDecodeError, OSError):
|
||||
return {}
|
||||
return data if isinstance(data, dict) else {}
|
||||
@@ -276,7 +277,7 @@ class _TomlMarkerRegistrar(MCPRegistrar):
|
||||
if not raw.strip():
|
||||
return None
|
||||
try:
|
||||
data = tomllib.loads(fsutil.read_text(self._config_file))
|
||||
data = loads_codex_config(fsutil.read_text(self._config_file))
|
||||
except (tomllib.TOMLDecodeError, OSError) as exc:
|
||||
return f"{self._config_file} is not valid TOML ({exc})"
|
||||
if not isinstance(data, dict):
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user