agentcap-cli 0.5.1__tar.gz → 0.5.2__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 (117) hide show
  1. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/PKG-INFO +1 -1
  2. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/pyproject.toml +1 -1
  3. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/__init__.py +1 -1
  4. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/quota.py +5 -1
  5. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_cc_plugin.py +2 -1
  6. agentcap_cli-0.5.2/tests/test_prompt_block.py +219 -0
  7. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/.gitignore +0 -0
  8. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/LICENSE +0 -0
  9. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/README.md +0 -0
  10. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/codex-plugin/LICENSE +0 -0
  11. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/landing/v2/README.md +0 -0
  12. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/plugin/LICENSE +0 -0
  13. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/_lifeline_exec.py +0 -0
  14. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/_lifeline_watch.py +0 -0
  15. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/adapters.py +0 -0
  16. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/alerts.py +0 -0
  17. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/analytics.py +0 -0
  18. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/budget.py +0 -0
  19. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/clamp.py +0 -0
  20. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/cli.py +0 -0
  21. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/cli_history.py +0 -0
  22. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/data/pricing.json +0 -0
  23. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/demo.py +0 -0
  24. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/devtools/__init__.py +0 -0
  25. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/devtools/fake_upstream.py +0 -0
  26. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/estimate.py +0 -0
  27. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/eta.py +0 -0
  28. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/failsafe.py +0 -0
  29. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/harness.py +0 -0
  30. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/history.py +0 -0
  31. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/ledger.py +0 -0
  32. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/license.py +0 -0
  33. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/lifeline.py +0 -0
  34. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/live_quota.py +0 -0
  35. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/logschema.py +0 -0
  36. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/loop.py +0 -0
  37. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/plans.py +0 -0
  38. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/pricing.py +0 -0
  39. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/private.py +0 -0
  40. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/procstop.py +0 -0
  41. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/proxy.py +0 -0
  42. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/report.py +0 -0
  43. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/runner.py +0 -0
  44. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/upstreams.py +0 -0
  45. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/usage.py +0 -0
  46. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/src/agentcap/waste.py +0 -0
  47. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/conftest.py +0 -0
  48. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-a1b2c3.jsonl +0 -0
  49. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-d4e5f6.jsonl +0 -0
  50. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p.jsonl +0 -0
  51. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-00-thr-parent.jsonl +0 -0
  52. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-50-thr-child.jsonl +0 -0
  53. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-01-20-thr-fork.jsonl +0 -0
  54. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/harness_logs/agy-1.4.11-2026-10-30.jsonl +0 -0
  55. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/harness_logs/claude-2.1.316-pretooluse.json +0 -0
  56. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/harness_logs/claude-2.1.316-statusline.json +0 -0
  57. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/harness_logs/codex-rollout-2026-10-29.jsonl +0 -0
  58. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/harness_logs/opencode-2026-10-30.jsonl +0 -0
  59. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/history/claude/.credentials.json +0 -0
  60. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/history/claude/projects/-home-dev-shop/1f0c-sess-a.jsonl +0 -0
  61. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/history/codex/auth.json +0 -0
  62. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/history/codex/sessions/2026/10/29/rollout-2026-10-29T10-00-00-0199aaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl +0 -0
  63. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/upstream/README.md +0 -0
  64. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/upstream/anthropic_403_permission_error.json +0 -0
  65. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/upstream/openai_403_region_blocked.json +0 -0
  66. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/upstream/openrouter_401_user_not_found.json +0 -0
  67. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/upstream/openrouter_403_moderation.json +0 -0
  68. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/fixtures/upstream/openrouter_429_rate_limited.json +0 -0
  69. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/license_support.py +0 -0
  70. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/proxy_support.py +0 -0
  71. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_adapters.py +0 -0
  72. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_agent_set.py +0 -0
  73. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_agents.py +0 -0
  74. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_alerts.py +0 -0
  75. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_analytics.py +0 -0
  76. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_anthropic_proxy.py +0 -0
  77. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_anthropic_units.py +0 -0
  78. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_budget.py +0 -0
  79. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_child_status.py +0 -0
  80. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_clamp.py +0 -0
  81. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_claude_adapter_and_tiers.py +0 -0
  82. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_cli.py +0 -0
  83. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_codex_plugin.py +0 -0
  84. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_concurrent_forgive.py +0 -0
  85. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_e2e_claude.py +0 -0
  86. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_estimate.py +0 -0
  87. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_exit_codes.py +0 -0
  88. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_failsafe.py +0 -0
  89. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_harness.py +0 -0
  90. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_history.py +0 -0
  91. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_ledger.py +0 -0
  92. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_license.py +0 -0
  93. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_lifeline.py +0 -0
  94. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_live_quota.py +0 -0
  95. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_log_contract.py +0 -0
  96. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_log_contract_live.py +0 -0
  97. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_loop.py +0 -0
  98. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_plugin_package.py +0 -0
  99. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_pricing.py +0 -0
  100. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_private_dirs.py +0 -0
  101. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_procstop.py +0 -0
  102. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_proxy_auth.py +0 -0
  103. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_proxy_cancel.py +0 -0
  104. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_proxy_core.py +0 -0
  105. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_proxy_extras.py +0 -0
  106. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_proxy_streaming.py +0 -0
  107. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_quota.py +0 -0
  108. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_release.py +0 -0
  109. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_report_cli.py +0 -0
  110. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_runaway.py +0 -0
  111. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_runner.py +0 -0
  112. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_self_approve.py +0 -0
  113. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_stop_matrix.py +0 -0
  114. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_upstream_refusals.py +0 -0
  115. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_upstreams.py +0 -0
  116. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_usage.py +0 -0
  117. {agentcap_cli-0.5.1 → agentcap_cli-0.5.2}/tests/test_zombie_collector.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: agentcap-cli
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Local-first quota and cost guard for coding agents: per-job share of Claude Code/Codex/Gemini subscription quota, loop breaker, evidence receipt.
5
5
  Project-URL: Homepage, https://agentcap.launchbench.studio
6
6
  Project-URL: Repository, https://github.com/Blitz00X/agentcap
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agentcap-cli"
7
- version = "0.5.1"
7
+ version = "0.5.2"
8
8
  description = "Local-first quota and cost guard for coding agents: per-job share of Claude Code/Codex/Gemini subscription quota, loop breaker, evidence receipt."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -2,6 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- __version__ = "0.5.1"
5
+ __version__ = "0.5.2"
6
6
 
7
7
  __all__ = ["__version__"]
@@ -290,7 +290,11 @@ def codex_home() -> Path:
290
290
 
291
291
 
292
292
  def parse_quota(raw: str) -> float:
293
- text = str(raw).strip().rstrip("%").strip()
293
+ # Turkish users write the sign first: `%1` means the same as `1%`.
294
+ text = str(raw).strip()
295
+ if text.startswith("%"):
296
+ text = text[1:].strip()
297
+ text = text.rstrip("%").strip()
294
298
  try:
295
299
  value = float(text)
296
300
  except ValueError:
@@ -163,7 +163,8 @@ def test_manifests_valid_json():
163
163
  market = json.loads((ROOT / ".claude-plugin" / "marketplace.json").read_text())
164
164
  assert plugin["name"] == market["plugins"][0]["name"] == "agentcap"
165
165
  hooks = json.loads((ROOT / "hooks" / "hooks.json").read_text())["hooks"]
166
- assert set(hooks) == {"SessionStart", "PreToolUse", "PostToolUse", "PostToolUseFailure", "Stop"}
166
+ assert set(hooks) == {"SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse",
167
+ "PostToolUseFailure", "Stop"}
167
168
 
168
169
 
169
170
  # ------------------------------------------------------------- loop breaker
@@ -0,0 +1,219 @@
1
+ """A reached quota stops the conversation, not only the tool calls (0.5.2).
2
+
3
+ ``PreToolUse`` denies tool calls and ends the turn, but the user could type another
4
+ prompt and the model would answer in text, spending quota. Both plugins now check
5
+ ``UserPromptSubmit`` against the same reading ``PreToolUse`` uses; ``/agentcap:``
6
+ commands (Claude Code) and typed ``agentcap ...`` commands (Codex) always pass,
7
+ because they are how the user raises or clears the limit.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import importlib.util
13
+ import io
14
+ import json
15
+ from pathlib import Path
16
+
17
+ import pytest
18
+
19
+ from agentcap.quota import Reading, parse_agent_set, parse_limit_words, parse_quota
20
+
21
+ ROOT = Path(__file__).resolve().parent.parent
22
+
23
+
24
+ def _load(name):
25
+ spec = importlib.util.spec_from_file_location(name, ROOT / "scripts" / f"{name}.py")
26
+ mod = importlib.util.module_from_spec(spec)
27
+ spec.loader.exec_module(mod)
28
+ return mod
29
+
30
+
31
+ cc = _load("agentcap_cc")
32
+ cx = _load("agentcap_codex")
33
+
34
+ CC_SID = "4c2b1a00-1111-2222-3333-444455556666"
35
+ CX_SID = "01a1da0b-e835-7cf0-9dcd-5365269e5129"
36
+ RESETS = 2_000_000_000.0
37
+ R5 = 2_000_000_000.0
38
+ RW = 2_000_500_000.0
39
+
40
+
41
+ @pytest.fixture(autouse=True)
42
+ def env(tmp_path, monkeypatch):
43
+ monkeypatch.setenv("AGENTCAP_QUOTA_DIR", str(tmp_path / "state"))
44
+ monkeypatch.setenv("CLAUDE_CONFIG_DIR", str(tmp_path / "claude"))
45
+ monkeypatch.setenv("AGENTCAP_LICENSE_FILE", str(tmp_path / "license.json"))
46
+ monkeypatch.setattr(cx, "LIVE_READER", lambda: {"5h": Reading(10.0, R5), "week": Reading(40.0, RW)})
47
+ monkeypatch.setattr(cx, "SPAWN", lambda argv, **kw: None)
48
+ return tmp_path
49
+
50
+
51
+ def pro(tmp_path):
52
+ (tmp_path / "license.json").write_text(json.dumps(
53
+ {"source": "polar", "valid": True, "tier": "pro", "key": "X", "checked_at": 1, "reason": "ok"}))
54
+
55
+
56
+ # ------------------------------------------------------------------ Claude Code
57
+ def cc_hook(event, payload):
58
+ out = io.StringIO()
59
+ cc.main(["hook", event], stdin=io.StringIO(json.dumps(payload)), stdout=out)
60
+ text = out.getvalue().strip()
61
+ return json.loads(text) if text else None
62
+
63
+
64
+ def cc_prompt(text):
65
+ return cc_hook("prompt", {"session_id": CC_SID, "cwd": "/w", "hook_event_name": "UserPromptSubmit",
66
+ "prompt": text})
67
+
68
+
69
+ def cc_statusline(week, five=10.0):
70
+ payload = {"hook_event_name": "Status", "session_id": CC_SID, "cwd": "/w",
71
+ "rate_limits": {"five_hour": {"used_percentage": five, "resets_at": RESETS - 3600},
72
+ "seven_day": {"used_percentage": week, "resets_at": RESETS}}}
73
+ cc.main(["statusline"], stdin=io.StringIO(json.dumps(payload)), stdout=io.StringIO())
74
+
75
+
76
+ def cc_cmd(*args):
77
+ out = io.StringIO()
78
+ cc.main(list(args) + ["--session", CC_SID], stdout=out)
79
+ return out.getvalue()
80
+
81
+
82
+ def cc_at_limit(tmp_path):
83
+ """Pro, weekly quota 5 points from 40%, now at 45%: exactly at the stop point."""
84
+
85
+ pro(tmp_path)
86
+ cc_statusline(40.0)
87
+ cc_cmd("quota", "5%")
88
+ cc_statusline(45.0)
89
+
90
+
91
+ def test_claude_blocks_a_new_prompt_at_the_limit(env):
92
+ cc_at_limit(env)
93
+ out = cc_prompt("carry on with the task")
94
+ assert out["decision"] == "block"
95
+ assert out["reason"].startswith("agentcap: limit reached — weekly quota at 45%, stop point 45%.")
96
+ assert "/agentcap:approve (+50%)" in out["reason"]
97
+ assert "/agentcap:quota <N%> 5h" in out["reason"] and "/agentcap:off" in out["reason"]
98
+
99
+
100
+ def test_claude_slash_commands_pass_a_reached_limit(env):
101
+ cc_at_limit(env)
102
+ for command in ("/agentcap:off", "/agentcap:approve", "/agentcap:quota 5%", "/agentcap:status"):
103
+ assert cc_prompt(command) is None
104
+
105
+
106
+ def test_claude_under_the_limit_passes(env):
107
+ pro(env)
108
+ cc_statusline(40.0)
109
+ cc_cmd("quota", "10%")
110
+ cc_statusline(44.0)
111
+ assert cc_prompt("carry on") is None
112
+
113
+
114
+ def test_claude_free_tier_never_blocks_a_prompt(env):
115
+ cc_statusline(40.0) # no licence file: Free
116
+ cc_cmd("quota", "2%")
117
+ cc_statusline(45.0)
118
+ assert cc_prompt("carry on") is None
119
+
120
+
121
+ def test_claude_without_a_quota_passes(env):
122
+ pro(env)
123
+ cc_statusline(45.0)
124
+ assert cc_prompt("carry on") is None
125
+
126
+
127
+ # ------------------------------------------------------------------ Codex
128
+ def cx_hook(event, payload):
129
+ out = io.StringIO()
130
+ cx.main(["hook", event], stdin=io.StringIO(json.dumps(payload)), stdout=out)
131
+ text = out.getvalue().strip()
132
+ return json.loads(text) if text else None
133
+
134
+
135
+ def cx_prompt(text):
136
+ return cx_hook("UserPromptSubmit", {"session_id": CX_SID, "turn_id": "t", "cwd": "/w", "transcript_path": None,
137
+ "hook_event_name": "UserPromptSubmit", "model": "gpt-6-astra",
138
+ "permission_mode": "default", "prompt": text})
139
+
140
+
141
+ def cx_at_limit(tmp_path):
142
+ """Pro, 2 points of the 5-hour quota from 10%, the server now reports 13%."""
143
+
144
+ pro(tmp_path)
145
+ assert cx_prompt("agentcap 2% 5h")["decision"] == "block"
146
+ cx._atomic_write(cx.live_path(CX_SID), {"ts": 9e12, "readings": {"5h": {"used": 13.0, "resets_at": R5}}})
147
+
148
+
149
+ def test_codex_blocks_a_new_prompt_at_the_limit(env):
150
+ cx_at_limit(env)
151
+ out = cx_prompt("carry on with the task")
152
+ assert out["decision"] == "block"
153
+ assert "agentcap: limit reached — 5-hour quota at 13%, stop point 12%" in out["reason"]
154
+ assert "`agentcap approve` (+50%)" in out["reason"]
155
+ assert "`agentcap <N%> 5h`" in out["reason"] and "`agentcap off`" in out["reason"]
156
+
157
+
158
+ def test_codex_typed_commands_still_work_over_the_limit(env):
159
+ cx_at_limit(env)
160
+ assert "agentcap commands" in cx_prompt("agentcap help")["reason"]
161
+ assert "stops at 12%" in cx_prompt("agentcap status")["reason"]
162
+ cleared = cx_prompt("agentcap off")
163
+ assert cleared["decision"] == "block" and "cleared" in cleared["reason"]
164
+ assert cx_prompt("carry on") is None # the limit is gone
165
+
166
+
167
+ def test_codex_under_the_limit_passes(env):
168
+ pro(env)
169
+ cx_prompt("agentcap 5% 5h")
170
+ cx._atomic_write(cx.live_path(CX_SID), {"ts": 9e12, "readings": {"5h": {"used": 13.0, "resets_at": R5}}})
171
+ assert cx_prompt("carry on") is None
172
+
173
+
174
+ def test_codex_free_tier_never_blocks_a_prompt(env):
175
+ cx_prompt("agentcap 2% 5h")
176
+ cx._atomic_write(cx.live_path(CX_SID), {"ts": 9e12, "readings": {"5h": {"used": 13.0, "resets_at": R5}}})
177
+ assert cx_prompt("carry on") is None
178
+
179
+
180
+ def test_codex_without_a_quota_passes(env):
181
+ pro(env)
182
+ assert cx_prompt("carry on") is None
183
+
184
+
185
+ # ------------------------------------------------------------------ %1 / until %70
186
+ def test_a_leading_percent_is_the_same_limit():
187
+ assert parse_quota("%1") == parse_quota("1%") == 1.0
188
+ assert parse_quota(" %50 ") == 50.0
189
+ assert parse_limit_words(["%1", "5h"]) == parse_limit_words(["1%", "5h"]) == (1.0, "5h", False)
190
+ assert parse_limit_words(["until", "%70", "week"]) == \
191
+ parse_limit_words(["until", "70%", "week"]) == (70.0, "week", True)
192
+ assert parse_limit_words(["%50", "week"]) == parse_limit_words(["50%", "week"]) == (50.0, "week", False)
193
+ assert parse_agent_set("echo agentcap set %50 5h") == parse_agent_set("echo agentcap set 50% 5h")
194
+
195
+
196
+ def test_leading_percent_works_in_the_commands(env):
197
+ pro(env)
198
+ cc_statusline(40.0)
199
+ assert "5-hour" in cc_cmd("quota", "%2", "5h")
200
+ assert json.loads(cc.session_path(CC_SID).read_text())["quota"] == 2.0
201
+ assert "stops at 70% of the weekly quota" in cc_cmd("quota", "until", "%70", "week")
202
+
203
+ assert "2 more points of the 5-hour quota" in cx_prompt("agentcap %2 5h")["reason"]
204
+ assert "stops at 70% of the weekly quota" in cx_prompt("agentcap until %70 week")["reason"]
205
+
206
+
207
+ def test_a_bad_limit_message_is_whole(env):
208
+ with pytest.raises(ValueError) as excinfo:
209
+ parse_limit_words(["lots", "5h"])
210
+ assert str(excinfo.value) == "a limit looks like 50% or until 70% (got 'lots')"
211
+ assert "a limit looks like 50% or until 70% (got 'lots')" in cc_cmd("quota", "lots")
212
+ assert "a limit looks like 50% or until 70% (got 'lots')" in cx_prompt("agentcap lots")["reason"]
213
+
214
+
215
+ # ------------------------------------------------------------------ wiring
216
+ def test_claude_hooks_json_registers_the_prompt_hook():
217
+ hooks = json.loads((ROOT / "hooks" / "hooks.json").read_text())["hooks"]
218
+ command = hooks["UserPromptSubmit"][0]["hooks"][0]["command"]
219
+ assert command.endswith('agentcap_cc.py" hook prompt')
File without changes
File without changes
File without changes