ctxcache 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. ctxcache-0.3.0/.githooks/pre-push +18 -0
  2. ctxcache-0.3.0/.github/workflows/bedrock-probe.yml +34 -0
  3. ctxcache-0.3.0/.github/workflows/ci.yml +22 -0
  4. ctxcache-0.3.0/.github/workflows/contract.yml +65 -0
  5. ctxcache-0.3.0/.github/workflows/live-session.yml +42 -0
  6. ctxcache-0.3.0/.github/workflows/release.yml +26 -0
  7. ctxcache-0.3.0/.gitignore +15 -0
  8. ctxcache-0.3.0/AGENTS.md +1 -0
  9. ctxcache-0.3.0/CLAUDE.md +85 -0
  10. ctxcache-0.3.0/DELIVERY.md +28 -0
  11. ctxcache-0.3.0/LICENSE +176 -0
  12. ctxcache-0.3.0/Makefile +32 -0
  13. ctxcache-0.3.0/PKG-INFO +218 -0
  14. ctxcache-0.3.0/README.md +186 -0
  15. ctxcache-0.3.0/bench/bedrock_probe.py +193 -0
  16. ctxcache-0.3.0/bench/live/2026-11-12-broad.json +361 -0
  17. ctxcache-0.3.0/bench/live/2026-11-12-tools.json +320 -0
  18. ctxcache-0.3.0/bench/live/2026-11-12.json +514 -0
  19. ctxcache-0.3.0/bench/live_broad.py +373 -0
  20. ctxcache-0.3.0/bench/live_session.py +435 -0
  21. ctxcache-0.3.0/bench/live_summary.py +60 -0
  22. ctxcache-0.3.0/bench/m0/__init__.py +6 -0
  23. ctxcache-0.3.0/bench/m0/arms.py +240 -0
  24. ctxcache-0.3.0/bench/m0/runner.py +155 -0
  25. ctxcache-0.3.0/bench/m2/compaction_study.py +90 -0
  26. ctxcache-0.3.0/bench/m2/runner.py +234 -0
  27. ctxcache-0.3.0/bench/m3/runner.py +153 -0
  28. ctxcache-0.3.0/bench/m4/freeze_report.py +343 -0
  29. ctxcache-0.3.0/bench/m4/runner.py +31 -0
  30. ctxcache-0.3.0/bench/m5/runner.py +184 -0
  31. ctxcache-0.3.0/bench/m6/runner.py +166 -0
  32. ctxcache-0.3.0/bench/render_live.py +125 -0
  33. ctxcache-0.3.0/bench/tasks/__init__.py +6 -0
  34. ctxcache-0.3.0/bench/tasks/base.py +22 -0
  35. ctxcache-0.3.0/bench/tasks/memory.py +83 -0
  36. ctxcache-0.3.0/bench/tasks/mixed.py +103 -0
  37. ctxcache-0.3.0/bench/tasks/registry.py +491 -0
  38. ctxcache-0.3.0/bench/templates/__init__.py +6 -0
  39. ctxcache-0.3.0/bench/templates/minimal.py +14 -0
  40. ctxcache-0.3.0/bench/templates/typical.py +25 -0
  41. ctxcache-0.3.0/ctxcache-live-session.html +131 -0
  42. ctxcache-0.3.0/ctxcache-scenarios.html +32 -0
  43. ctxcache-0.3.0/ctxcache-synthesis.html +503 -0
  44. ctxcache-0.3.0/ctxcache-v0.1-proof.html +1214 -0
  45. ctxcache-0.3.0/ctxcache-v0.1-proof.typescript +55 -0
  46. ctxcache-0.3.0/docs/BENCH.md +88 -0
  47. ctxcache-0.3.0/docs/BREAKS.md +117 -0
  48. ctxcache-0.3.0/docs/BUILD_HANDBOOK.md +577 -0
  49. ctxcache-0.3.0/docs/DECISIONS.md +43 -0
  50. ctxcache-0.3.0/docs/METRICS.md +52 -0
  51. ctxcache-0.3.0/docs/REPORT.md +63 -0
  52. ctxcache-0.3.0/docs/STATUS.md +383 -0
  53. ctxcache-0.3.0/docs/hdiagrams/g1_funnel.svg +1 -0
  54. ctxcache-0.3.0/docs/hdiagrams/g2_flywheel.svg +1 -0
  55. ctxcache-0.3.0/docs/hdiagrams/h1_arch.svg +1 -0
  56. ctxcache-0.3.0/docs/hdiagrams/h2_layout.svg +1 -0
  57. ctxcache-0.3.0/docs/hdiagrams/h3_call.svg +1 -0
  58. ctxcache-0.3.0/docs/hdiagrams/h4_plan.svg +1 -0
  59. ctxcache-0.3.0/docs/media/ctxcache-cost-proof.mp4 +0 -0
  60. ctxcache-0.3.0/gtm/CLAIMS.md +17 -0
  61. ctxcache-0.3.0/gtm/GTM_HANDBOOK.md +231 -0
  62. ctxcache-0.3.0/gtm/SCOREBOARD.md +7 -0
  63. ctxcache-0.3.0/gtm/hdiagrams/g1_funnel.svg +1 -0
  64. ctxcache-0.3.0/gtm/hdiagrams/g2_flywheel.svg +1 -0
  65. ctxcache-0.3.0/gtm/hdiagrams/h1_arch.svg +1 -0
  66. ctxcache-0.3.0/gtm/hdiagrams/h2_layout.svg +1 -0
  67. ctxcache-0.3.0/gtm/hdiagrams/h3_call.svg +1 -0
  68. ctxcache-0.3.0/gtm/hdiagrams/h4_plan.svg +1 -0
  69. ctxcache-0.3.0/prompts/BUILD_AGENT_PROMPT.md +71 -0
  70. ctxcache-0.3.0/prompts/GTM_AGENT_PROMPT.md +71 -0
  71. ctxcache-0.3.0/pyproject.toml +95 -0
  72. ctxcache-0.3.0/src/ctxcache/__init__.py +109 -0
  73. ctxcache-0.3.0/src/ctxcache/adapters/__init__.py +15 -0
  74. ctxcache-0.3.0/src/ctxcache/adapters/anthropic.py +34 -0
  75. ctxcache-0.3.0/src/ctxcache/adapters/base.py +25 -0
  76. ctxcache-0.3.0/src/ctxcache/adapters/bedrock.py +46 -0
  77. ctxcache-0.3.0/src/ctxcache/adapters/gemini.py +34 -0
  78. ctxcache-0.3.0/src/ctxcache/adapters/openai.py +42 -0
  79. ctxcache-0.3.0/src/ctxcache/bedrock_converse.py +67 -0
  80. ctxcache-0.3.0/src/ctxcache/bench/__init__.py +1 -0
  81. ctxcache-0.3.0/src/ctxcache/bench/runner.py +96 -0
  82. ctxcache-0.3.0/src/ctxcache/cli.py +326 -0
  83. ctxcache-0.3.0/src/ctxcache/compaction.py +102 -0
  84. ctxcache-0.3.0/src/ctxcache/cost.py +171 -0
  85. ctxcache-0.3.0/src/ctxcache/data/breaks.yaml +124 -0
  86. ctxcache-0.3.0/src/ctxcache/data/providers.toml +199 -0
  87. ctxcache-0.3.0/src/ctxcache/exceptions.py +23 -0
  88. ctxcache-0.3.0/src/ctxcache/fingerprint.py +68 -0
  89. ctxcache-0.3.0/src/ctxcache/guard.py +253 -0
  90. ctxcache-0.3.0/src/ctxcache/integrations/__init__.py +17 -0
  91. ctxcache-0.3.0/src/ctxcache/integrations/langchain.py +7 -0
  92. ctxcache-0.3.0/src/ctxcache/integrations/langgraph.py +144 -0
  93. ctxcache-0.3.0/src/ctxcache/integrations/openai_agents.py +42 -0
  94. ctxcache-0.3.0/src/ctxcache/integrations/pydantic_ai.py +44 -0
  95. ctxcache-0.3.0/src/ctxcache/layout.py +255 -0
  96. ctxcache-0.3.0/src/ctxcache/ledger.py +179 -0
  97. ctxcache-0.3.0/src/ctxcache/memory/__init__.py +25 -0
  98. ctxcache-0.3.0/src/ctxcache/memory/checks.py +53 -0
  99. ctxcache-0.3.0/src/ctxcache/memory/recall.py +50 -0
  100. ctxcache-0.3.0/src/ctxcache/memory/store.py +315 -0
  101. ctxcache-0.3.0/src/ctxcache/offload.py +134 -0
  102. ctxcache-0.3.0/src/ctxcache/openai_chat.py +61 -0
  103. ctxcache-0.3.0/src/ctxcache/otel.py +60 -0
  104. ctxcache-0.3.0/src/ctxcache/planner.py +167 -0
  105. ctxcache-0.3.0/src/ctxcache/policies/__init__.py +36 -0
  106. ctxcache-0.3.0/src/ctxcache/policies/route.py +179 -0
  107. ctxcache-0.3.0/src/ctxcache/replay.py +193 -0
  108. ctxcache-0.3.0/src/ctxcache/scenarios.py +250 -0
  109. ctxcache-0.3.0/src/ctxcache/segments.py +162 -0
  110. ctxcache-0.3.0/src/ctxcache/sim/__init__.py +13 -0
  111. ctxcache-0.3.0/src/ctxcache/sim/cache_sim.py +152 -0
  112. ctxcache-0.3.0/src/ctxcache/sim/tokens.py +56 -0
  113. ctxcache-0.3.0/src/ctxcache/testing.py +250 -0
  114. ctxcache-0.3.0/src/ctxcache/tools.py +49 -0
  115. ctxcache-0.3.0/src/ctxcache/trace.py +109 -0
  116. ctxcache-0.3.0/src/ctxcache/wrapper.py +609 -0
  117. ctxcache-0.3.0/tests/__init__.py +1 -0
  118. ctxcache-0.3.0/tests/test_bedrock_converse.py +160 -0
  119. ctxcache-0.3.0/tests/test_chat_optimize.py +233 -0
  120. ctxcache-0.3.0/tests/test_cli.py +154 -0
  121. ctxcache-0.3.0/tests/test_compaction.py +40 -0
  122. ctxcache-0.3.0/tests/test_contract.py +254 -0
  123. ctxcache-0.3.0/tests/test_guard.py +55 -0
  124. ctxcache-0.3.0/tests/test_integrations.py +143 -0
  125. ctxcache-0.3.0/tests/test_invariants.py +617 -0
  126. ctxcache-0.3.0/tests/test_live_summary.py +76 -0
  127. ctxcache-0.3.0/tests/test_memory.py +75 -0
  128. ctxcache-0.3.0/tests/test_named_tests_exist.py +50 -0
  129. ctxcache-0.3.0/tests/test_otel.py +51 -0
  130. ctxcache-0.3.0/tests/test_outbound.py +134 -0
  131. ctxcache-0.3.0/tests/test_perf.py +74 -0
  132. ctxcache-0.3.0/tests/test_planner.py +78 -0
  133. ctxcache-0.3.0/tests/test_routing.py +127 -0
  134. ctxcache-0.3.0/tests/test_scenarios.py +33 -0
  135. ctxcache-0.3.0/tests/test_sim.py +117 -0
  136. ctxcache-0.3.0/tests/test_stream.py +75 -0
  137. ctxcache-0.3.0/tests/test_testing.py +117 -0
  138. ctxcache-0.3.0/uv.lock +1808 -0
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # Reject pushing the local-only gtm branch (D-26). Allow deleting origin/gtm.
3
+ set -euo pipefail
4
+
5
+ zero="0000000000000000000000000000000000000000"
6
+
7
+ while read -r local_ref local_sha remote_ref remote_sha; do
8
+ if [[ "$remote_ref" == "refs/heads/gtm" && "$local_sha" == "$zero" ]]; then
9
+ continue
10
+ fi
11
+ if [[ "$local_ref" == "refs/heads/gtm" || "$remote_ref" == "refs/heads/gtm" ]]; then
12
+ echo "refusing to push gtm: D-26 keeps that branch local-only (not on origin)." >&2
13
+ echo "delete a stray remote with: git push origin --delete gtm" >&2
14
+ exit 1
15
+ fi
16
+ done
17
+
18
+ exit 0
@@ -0,0 +1,34 @@
1
+ name: bedrock-probe
2
+
3
+ # Manual only. Nova Micro, Nova Lite, and one cheap Claude Haiku.
4
+ # The script stops before the estimated bill reaches $1.
5
+ # gpt-oss is not called.
6
+ on:
7
+ workflow_dispatch:
8
+ inputs:
9
+ only:
10
+ description: "One model id. Leave empty for Nova plus one cheap Claude."
11
+ required: false
12
+ default: ""
13
+ type: string
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ probe:
20
+ runs-on: ubuntu-latest
21
+ timeout-minutes: 10
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: astral-sh/setup-uv@v5
25
+ with:
26
+ python-version: "3.12"
27
+ - name: Install
28
+ run: uv pip install -e .
29
+ - name: Probe
30
+ env:
31
+ BEDROCK_API_KEY: ${{ secrets.BEDROCK_API_KEY }}
32
+ BEDROCK_ENDPOINT: ${{ secrets.BEDROCK_ENDPOINT }}
33
+ PROBE_ONLY: ${{ inputs.only }}
34
+ run: python bench/bedrock_probe.py
@@ -0,0 +1,22 @@
1
+ name: check
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ check:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - name: Install
20
+ run: uv pip install -e ".[dev]"
21
+ - name: make check
22
+ run: make check
@@ -0,0 +1,65 @@
1
+ name: contract
2
+
3
+ # One live run per UTC day. Gemini if that key exists, Nova on Bedrock Converse
4
+ # if that key exists. A chat-completions URL in BEDROCK_ENDPOINT is ignored.
5
+ # Output length is capped in the tests. A second click the same day stops
6
+ # before any model is called, and that stop is a success. A failed model
7
+ # step does not block a retry the same day.
8
+ on:
9
+ schedule:
10
+ - cron: "0 15 * * *"
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+ actions: read
16
+
17
+ concurrency:
18
+ group: hearth-contract
19
+ cancel-in-progress: false
20
+
21
+ jobs:
22
+ contract:
23
+ runs-on: ubuntu-latest
24
+ timeout-minutes: 15
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: astral-sh/setup-uv@v5
28
+ with:
29
+ python-version: "3.12"
30
+ - name: Install
31
+ run: uv pip install -e ".[dev,gemini,openai]"
32
+ - name: Require a provider key
33
+ env:
34
+ GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
35
+ BEDROCK_API_KEY: ${{ secrets.BEDROCK_API_KEY }}
36
+ run: |
37
+ if [ -z "$GEMINI_API_KEY" ] && [ -z "$BEDROCK_API_KEY" ]; then
38
+ echo "Set GEMINI_API_KEY or BEDROCK_API_KEY as a repository secret."
39
+ exit 1
40
+ fi
41
+ - name: Stop a second live run today
42
+ id: spend
43
+ env:
44
+ GH_TOKEN: ${{ github.token }}
45
+ run: |
46
+ already=false
47
+ today=$(date -u +%Y-%m-%d)
48
+ ids=$(gh run list --workflow=contract.yml --created "$today" --limit 30 --json databaseId,status --jq '.[] | select(.status=="completed") | .databaseId')
49
+ for id in $ids; do
50
+ hit=$(gh run view "$id" --json jobs --jq '.jobs[].steps[]? | select(.name=="make contract" and .conclusion=="success") | .name')
51
+ if [ -n "$hit" ]; then
52
+ echo "Run $id already called a model today ($today UTC) and passed. Not starting another."
53
+ already=true
54
+ break
55
+ fi
56
+ done
57
+ echo "already=$already" >> "$GITHUB_OUTPUT"
58
+ - name: make contract
59
+ if: steps.spend.outputs.already != 'true'
60
+ env:
61
+ GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
62
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
63
+ BEDROCK_API_KEY: ${{ secrets.BEDROCK_API_KEY }}
64
+ BEDROCK_ENDPOINT: ${{ secrets.BEDROCK_ENDPOINT }}
65
+ run: make contract
@@ -0,0 +1,42 @@
1
+ name: live-session
2
+
3
+ # Manual. questions and tools stop before $1. broad stops before $5.
4
+ on:
5
+ workflow_dispatch:
6
+ inputs:
7
+ case:
8
+ description: "questions or tools stay under $1. broad tries more models under $5."
9
+ required: true
10
+ default: questions
11
+ type: choice
12
+ options:
13
+ - questions
14
+ - tools
15
+ - broad
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ session:
22
+ runs-on: ubuntu-latest
23
+ timeout-minutes: 25
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: astral-sh/setup-uv@v5
27
+ with:
28
+ python-version: "3.12"
29
+ - name: Install
30
+ run: uv pip install -e ".[gemini]"
31
+ - name: Live session
32
+ env:
33
+ GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
34
+ BEDROCK_API_KEY: ${{ secrets.BEDROCK_API_KEY }}
35
+ BEDROCK_ENDPOINT: ${{ secrets.BEDROCK_ENDPOINT }}
36
+ LIVE_CASE: ${{ inputs.case }}
37
+ run: |
38
+ if [ "$LIVE_CASE" = "broad" ]; then
39
+ python bench/live_broad.py
40
+ else
41
+ python bench/live_session.py
42
+ fi
@@ -0,0 +1,26 @@
1
+ name: publish
2
+
3
+ # Publishes ctxcache when a v* tag is pushed.
4
+ # PyPI must trust this repository (trusted publishing, environment name: pypi)
5
+ # before the first tag. Pushing the tag is the publish.
6
+ on:
7
+ push:
8
+ tags:
9
+ - "v*"
10
+
11
+ jobs:
12
+ pypi:
13
+ runs-on: ubuntu-latest
14
+ environment: pypi
15
+ permissions:
16
+ id-token: write
17
+ contents: read
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: astral-sh/setup-uv@v5
21
+ with:
22
+ python-version: "3.12"
23
+ - name: Build
24
+ run: uv build
25
+ - name: Publish
26
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,15 @@
1
+ .env
2
+ # GTM branch is local-only (D-26). Never push refs/heads/gtm to origin.
3
+ # .githooks/pre-push rejects that push. Private GTM files stay out of every branch:
4
+ gtm/private/
5
+ .venv/
6
+ __pycache__/
7
+ *.pyc
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+ *.egg-info/
12
+ dist/
13
+ build/
14
+ .coverage
15
+ .DS_Store
@@ -0,0 +1 @@
1
+ CLAUDE.md
@@ -0,0 +1,85 @@
1
+ # CLAUDE.md: rules for any coding agent in this repo
2
+
3
+ (Symlink `AGENTS.md` to this file.)
4
+
5
+ ## What this is
6
+
7
+ CtxCache is a Python library that keeps an AI agent's prompt cache warm. It is **not** an agent framework, gateway, hosted service or UI.
8
+
9
+ **Source of truth, in order:**
10
+ 1. `docs/BUILD_HANDBOOK.md` (spec, invariants, plan);
11
+ 2. the newest entry in `docs/STATUS.md`;
12
+ 3. `docs/DECISIONS.md`.
13
+
14
+ The GTM thread follows `gtm/GTM_HANDBOOK.md`.
15
+
16
+ ## Scope fence (hard)
17
+
18
+ - Build only the current milestone in BUILD_HANDBOOK §10. Anything in §7 "Not doing" needs Abhranshu's written OK, recorded in DECISIONS.
19
+ - The core package has **zero required dependencies**. New dependencies go into an extra, and only with a DECISIONS entry (reason, size, licence).
20
+ - No new top-level directories. No new docs except `docs/METRICS.md` (M1), `docs/BREAKS.md` (M2, generated from `breaks.yaml`), `docs/BENCH.md` (M0) and `docs/REPORT.md` (M4).
21
+ - Provider facts (prices, minimums, TTLs, limits) live only in `src/ctxcache/data/providers.toml`, each with a source URL and date. Never hard-code them.
22
+
23
+ ## How to work
24
+
25
+ 1. **Pick.** Take the next task in the current milestone. Write one line saying what "done" means.
26
+ 2. **Test first.** If it touches an invariant (§8), write the named test first. A missing named test fails CI.
27
+ 3. **Build small.** Use `uv`; `ruff`, `mypy --strict` (core) and `pytest` must pass before every commit (`make check`).
28
+ 4. **Commit.** Conventional commits, one logical change each.
29
+ 5. **Gate.** At each gate:
30
+ - run the gate commands;
31
+ - paste the output tails into STATUS (format below);
32
+ - have a fresh reviewer subagent on the strongest model review the milestone diff against the handbook;
33
+ - fix its findings or record why not.
34
+ 6. **Report.** Every Friday, add a STATUS entry at the top of the Log, even if mid-milestone.
35
+
36
+ ## Correctness rules that are easy to get wrong
37
+
38
+ - **`observe` is byte-identical.** Never "improve" a request in `observe` mode.
39
+ - **`safe` is content-equivalent.** Same messages, same tools, same text; only serialisation may change.
40
+ - **Append-only.** Never rewrite an already-sent message except through a recorded compaction event.
41
+ - **Fail-open.** Any internal exception sends the original request unchanged and records `ctxcache_error`.
42
+ - **Exact usage reconciliation.** Read + write + uncached must equal the provider's total input, per provider rules.
43
+ - **No content in the ledger, logs or spans** unless recording is explicitly enabled.
44
+ - **Cost arithmetic uses `Decimal`** or integer micro-units, never float.
45
+ - **Attribution.** A cache miss caused by TTL expiry, below-minimum length or the provider is never reported as the user's fault.
46
+
47
+ ## Spending money
48
+
49
+ - Live provider calls cost Abhranshu money. The M0 kill test and nightly contract tests run on the budget he approved (BUILD_HANDBOOK §10). Use the smallest suitable model.
50
+ - Log every live run's token totals in `docs/BENCH.md`.
51
+ - **Stop and ask before exceeding the approved budget.**
52
+
53
+ ## Stop and ask Abhranshu (otherwise keep going)
54
+
55
+ - **At M0 start:** approve the API budget (D-02); confirm the GitHub owner (`jishmisc28` or `ab-atnms`); confirm the PyPI name `ctxcache` is free (fallback `hearth-cache`).
56
+ - **At the M1 gate:** whether to make the repo public and tag `0.1.0a1` (D-09).
57
+ - **The M0 go/stop decision.** Write the memo and wait.
58
+ - **Public interfaces.** Anything that changes a documented interface: Python API, CLI flags, ledger schema, metric definitions.
59
+ - **Releases.** Before any release, PyPI upload, or making the repo public.
60
+ - **Failed gates.** A gate that fails after two genuine attempts: write the evidence and propose a cut from the cut line.
61
+
62
+ ## Never
63
+
64
+ - Post, email, DM or comment anywhere public; open issues or PRs in other projects; create accounts.
65
+ - Put real API keys, prompts or customer data in fixtures or commits.
66
+ - Read or edit anything outside this repo except `~/.ctxcache/`. `gtm/private/` is gitignored and never read by the build agent.
67
+ - Write marketing claims in code docs. Product claims live in `gtm/` and go through `gtm/CLAIMS.md`.
68
+
69
+ ## Parallel threads
70
+
71
+ - **The GTM thread** works in a local git worktree on branch `gtm` and edits only `gtm/`. Never push `gtm` to origin (D-26); delete `origin/gtm` if it appears.
72
+ - **The build thread** never edits `gtm/`. It reads GTM files with `git show gtm:<path>`, and merges local `gtm` into `main` at M7.
73
+ - **Subagents.** Use them on cheaper models for independent, well-specified work: adapters' boilerplate, task fixtures, CLI formatting, docs. Core layout, guard, planner and simulator logic is written or reviewed by the strongest model.
74
+
75
+ ## STATUS entry format
76
+
77
+ ```markdown
78
+ ## YYYY-MM-DD · M<k> <name>: VERIFIED | IN PROGRESS | BLOCKED | PENDING-HUMAN
79
+ Gate commands and output tails:
80
+ Numbers: tests passed · read share / cost ratio / TTFT p50 (if measured) · API spend this week
81
+ What changed (user-visible first): 3–6 bullets
82
+ Learned (for Abhranshu): 2–3 bullets explaining one real concept, with file:line pointers
83
+ GTM-ready: which claims or assets this unlocks (claim IDs)
84
+ Blocked on Abhranshu: the exact question, or "nothing"
85
+ ```
@@ -0,0 +1,28 @@
1
+ # Delivery State
2
+
3
+ ## 1. Shipping Goal
4
+ Ship CtxCache v0.1: an embeddable context engine that keeps an AI agent's prompt cache warm and proves it with measurements.
5
+
6
+ ## 2. Big Rocks
7
+
8
+ | Rock | State | Evidence Link | Blocker | Needs Founder |
9
+ |---|---|---|---|---|
10
+ | M0: Kill test proves stock frameworks waste ≥25% cache cost on real agent templates | Proven | docs/STATUS.md | — | No |
11
+ | M1: In-process `wrap()` with guard, planner, and ledger for Gemini, Anthropic, OpenAI | Proven | docs/STATUS.md | — | No |
12
+ | M2: Optimize policies: relocation, offloading, and planned compaction | Proven | docs/STATUS.md | — | No |
13
+ | M3: Framework integrations (Pydantic AI, Agents SDK, LangGraph) | Proven | docs/STATUS.md | — | No |
14
+ | M4: Replay CLI, simulator v1, and Cache Efficiency Report data freeze | Proven | docs/REPORT.md | — | No |
15
+ | M5: Memory v0 with temporal facts and write checks | Proven | docs/STATUS.md | — | No |
16
+ | M6: Switch-or-stay router and TTL optimizer | Proven | docs/STATUS.md | — | No |
17
+ | M7: Hardening, public benchmark reproduction, and v0.1 release | In progress | docs/STATUS.md | PyPI trusted publishing and a Gemini API key | YES (two account clicks, not a human trial) |
18
+
19
+ ## 3. Parked
20
+ - P2: Optional online token counting endpoint mode (`--online`) for provider APIs.
21
+ - P2: Expose memory FTS5 indexing configuration for custom schemas.
22
+
23
+ ## 4. Needs Founder
24
+ - PyPI: enable trusted publishing for `jishmisc28/ctxcache`, environment name `pypi`.
25
+ - GitHub: add secret `GEMINI_API_KEY` so the nightly contract can start. This does not hold the tag.
26
+
27
+ ## 5. Last Updated
28
+ 2026-10-23
ctxcache-0.3.0/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or exemplary damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,32 @@
1
+ .PHONY: check test contract bench report format install
2
+
3
+ VENV ?= .venv
4
+ PYTHON ?= $(VENV)/bin/python
5
+ RUFF ?= $(VENV)/bin/ruff
6
+ MYPY ?= $(VENV)/bin/mypy
7
+ PYTEST ?= $(VENV)/bin/pytest
8
+
9
+ install:
10
+ uv pip install -e ".[dev]"
11
+
12
+ format:
13
+ $(RUFF) format src tests bench
14
+ $(RUFF) check --fix src tests bench
15
+
16
+ check:
17
+ $(RUFF) check src tests bench
18
+ $(RUFF) format --check src tests bench
19
+ $(MYPY) --strict src/ctxcache
20
+ $(PYTEST) -m "not contract" tests/
21
+
22
+ test:
23
+ $(PYTEST) tests/
24
+
25
+ contract:
26
+ $(PYTEST) -m contract tests/
27
+
28
+ bench:
29
+ $(PYTHON) -m ctxcache.bench.runner --m0 --verify
30
+
31
+ report:
32
+ $(PYTHON) -m ctxcache.bench.report