agentcap-cli 0.2.1__tar.gz → 0.2.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 (73) hide show
  1. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/PKG-INFO +5 -3
  2. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/README.md +4 -2
  3. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/pyproject.toml +1 -1
  4. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/__init__.py +1 -1
  5. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/quota.py +12 -0
  6. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_quota.py +28 -0
  7. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/.gitignore +0 -0
  8. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/LICENSE +0 -0
  9. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/adapters.py +0 -0
  10. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/alerts.py +0 -0
  11. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/analytics.py +0 -0
  12. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/budget.py +0 -0
  13. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/clamp.py +0 -0
  14. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/cli.py +0 -0
  15. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/cli_history.py +0 -0
  16. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/data/pricing.json +0 -0
  17. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/demo.py +0 -0
  18. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/devtools/__init__.py +0 -0
  19. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/devtools/fake_upstream.py +0 -0
  20. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/estimate.py +0 -0
  21. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/eta.py +0 -0
  22. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/history.py +0 -0
  23. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/ledger.py +0 -0
  24. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/license.py +0 -0
  25. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/loop.py +0 -0
  26. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/plans.py +0 -0
  27. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/pricing.py +0 -0
  28. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/proxy.py +0 -0
  29. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/report.py +0 -0
  30. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/runner.py +0 -0
  31. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/upstreams.py +0 -0
  32. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/usage.py +0 -0
  33. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/src/agentcap/waste.py +0 -0
  34. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/conftest.py +0 -0
  35. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-a1b2c3.jsonl +0 -0
  36. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-d4e5f6.jsonl +0 -0
  37. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p.jsonl +0 -0
  38. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-00-thr-parent.jsonl +0 -0
  39. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-50-thr-child.jsonl +0 -0
  40. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-01-20-thr-fork.jsonl +0 -0
  41. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/history/claude/.credentials.json +0 -0
  42. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/history/claude/projects/-home-dev-shop/1f0c-sess-a.jsonl +0 -0
  43. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/history/codex/auth.json +0 -0
  44. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/fixtures/history/codex/sessions/2026/10/29/rollout-2026-10-29T10-00-00-0199aaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl +0 -0
  45. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/license_support.py +0 -0
  46. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/proxy_support.py +0 -0
  47. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_adapters.py +0 -0
  48. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_agents.py +0 -0
  49. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_alerts.py +0 -0
  50. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_analytics.py +0 -0
  51. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_anthropic_proxy.py +0 -0
  52. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_anthropic_units.py +0 -0
  53. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_budget.py +0 -0
  54. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_cc_plugin.py +0 -0
  55. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_clamp.py +0 -0
  56. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_claude_adapter_and_tiers.py +0 -0
  57. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_cli.py +0 -0
  58. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_e2e_claude.py +0 -0
  59. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_estimate.py +0 -0
  60. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_history.py +0 -0
  61. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_ledger.py +0 -0
  62. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_license.py +0 -0
  63. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_loop.py +0 -0
  64. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_pricing.py +0 -0
  65. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_proxy_cancel.py +0 -0
  66. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_proxy_core.py +0 -0
  67. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_proxy_extras.py +0 -0
  68. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_proxy_streaming.py +0 -0
  69. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_report_cli.py +0 -0
  70. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_runaway.py +0 -0
  71. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_runner.py +0 -0
  72. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_upstreams.py +0 -0
  73. {agentcap_cli-0.2.1 → agentcap_cli-0.2.2}/tests/test_usage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: agentcap-cli
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: API-key spend guard for unattended Codex CLI, Gemini CLI and Claude Code runs: hard per-run cap, kills the process at the limit.
5
5
  Project-URL: Homepage, https://agentcap.launchbench.studio
6
6
  Project-URL: Repository, https://github.com/Blitz00X/agentcap
@@ -78,7 +78,9 @@ your subscription quota % and Codex support.
78
78
  `this job used 5.1% of the weekly quota`) and the last tool call's name, as numbers and tool
79
79
  names only, never prompts or tool inputs.
80
80
  - **Approve.** After a stop, `agentcap approve` (or `/agentcap:approve` in the plugin) raises the
81
- limit by 50%, at most twice, and the run continues.
81
+ limit by 50%, at most twice, and the run continues. This works for interactive Claude Code,
82
+ which stays open after a stop. Codex and headless `claude -p` jobs are stopped with SIGINT, so
83
+ there approve only helps before the limit is hit; after a stop it says so and changes nothing.
82
84
  - **Free** runs the same detectors in observe-only mode and prints what Pro would have done.
83
85
 
84
86
  Honest limits: Claude tool-error streaks are only caught on API-key runs (the subscription hook sees
@@ -338,7 +340,7 @@ agentcap quota # read-only: last seen usage (Fre
338
340
  use in the same window counts against the job (AgentCap warns when it sees another session).
339
341
  Values arrive once per model response, so a job **can overshoot by up to one request**.
340
342
  Claude Code only reports `rate_limits` for Pro/Max logins and only in interactive sessions
341
- (the statusline does not run in `claude -p`). Codex's rollout format is undocumented and may change.
343
+ (the statusline does not run in `claude -p`). Codex's rollout format is undocumented and may change. Codex reports `used_percent` in whole percent, so a Codex cap under 1% cannot trigger until the job has used a full 1% (AgentCap warns at start). Use `--quota 1%` or more for Codex.
342
344
  **Verified so far on fixtures and fake CLIs only** (plus real Claude Code 2.1.197: the `--settings`
343
345
  layer, the chained statusline and the `PreToolUse` deny were checked against a local fake API);
344
346
  a check on a real Max / ChatGPT account is still pending.
@@ -48,7 +48,9 @@ your subscription quota % and Codex support.
48
48
  `this job used 5.1% of the weekly quota`) and the last tool call's name, as numbers and tool
49
49
  names only, never prompts or tool inputs.
50
50
  - **Approve.** After a stop, `agentcap approve` (or `/agentcap:approve` in the plugin) raises the
51
- limit by 50%, at most twice, and the run continues.
51
+ limit by 50%, at most twice, and the run continues. This works for interactive Claude Code,
52
+ which stays open after a stop. Codex and headless `claude -p` jobs are stopped with SIGINT, so
53
+ there approve only helps before the limit is hit; after a stop it says so and changes nothing.
52
54
  - **Free** runs the same detectors in observe-only mode and prints what Pro would have done.
53
55
 
54
56
  Honest limits: Claude tool-error streaks are only caught on API-key runs (the subscription hook sees
@@ -308,7 +310,7 @@ agentcap quota # read-only: last seen usage (Fre
308
310
  use in the same window counts against the job (AgentCap warns when it sees another session).
309
311
  Values arrive once per model response, so a job **can overshoot by up to one request**.
310
312
  Claude Code only reports `rate_limits` for Pro/Max logins and only in interactive sessions
311
- (the statusline does not run in `claude -p`). Codex's rollout format is undocumented and may change.
313
+ (the statusline does not run in `claude -p`). Codex's rollout format is undocumented and may change. Codex reports `used_percent` in whole percent, so a Codex cap under 1% cannot trigger until the job has used a full 1% (AgentCap warns at start). Use `--quota 1%` or more for Codex.
312
314
  **Verified so far on fixtures and fake CLIs only** (plus real Claude Code 2.1.197: the `--settings`
313
315
  layer, the chained statusline and the `PreToolUse` deny were checked against a local fake API);
314
316
  a check on a real Max / ChatGPT account is still pending.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agentcap-cli"
7
- version = "0.2.1"
7
+ version = "0.2.2"
8
8
  description = "API-key spend guard for unattended Codex CLI, Gemini CLI and Claude Code runs: hard per-run cap, kills the process at the limit."
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.2.1"
5
+ __version__ = "0.2.2"
6
6
 
7
7
  __all__ = ["__version__"]
@@ -73,6 +73,9 @@ def approve_job(root: Path | None = None) -> str:
73
73
  job = _read_json(d / "job.json") or {}
74
74
  if not job.get("enforce"):
75
75
  return "agentcap: this job is observe-only (Free); approve is a Pro feature."
76
+ if job.get("stopped"):
77
+ return ("agentcap: this job was already stopped (SIGINT), so approve cannot resume it. "
78
+ "Start it again with a higher --quota.")
76
79
  n = int(job.get("approvals") or 0)
77
80
  if n >= APPROVE_MAX:
78
81
  return (f"agentcap: already approved twice (limit {float(job.get('quota', 0)):g}%); "
@@ -745,6 +748,12 @@ class QuotaRunner:
745
748
  pass
746
749
 
747
750
  def _stop(self) -> None:
751
+ job = _read_json(self.job_dir / "job.json") or {}
752
+ job["stopped"] = True # a signalled job cannot be resumed by `agentcap approve`
753
+ try:
754
+ _atomic_write(self.job_dir / "job.json", job)
755
+ except OSError:
756
+ pass
748
757
  self._signal(signal.SIGINT)
749
758
  deadline = time.time() + 5
750
759
  while self.child and self.child.poll() is None and time.time() < deadline:
@@ -791,6 +800,9 @@ class QuotaRunner:
791
800
  else f"observe only (Free); Pro would stop it at {self.quota:g}%")
792
801
  + ". Read-only; your login and traffic are untouched."
793
802
  )
803
+ if self.agent == "codex" and self.quota < 1:
804
+ self._say(f"agentcap: WARNING: Codex reports quota in whole percent, so a {self.quota:g}% cap "
805
+ "cannot trigger until the job has used a full 1%. Use --quota 1% or more for Codex.")
794
806
  self.child = subprocess.Popen(argv, env=env, start_new_session=True, cwd=self.cwd)
795
807
 
796
808
  warned = hit = parallel = observed = no_data_warned = False
@@ -597,3 +597,31 @@ def test_cli_approve(tmp_path, monkeypatch, capsys):
597
597
  monkeypatch.setenv("AGENTCAP_QUOTA_DIR", str(root))
598
598
  assert cli.main(["approve"]) == 0
599
599
  assert "6%" in capsys.readouterr().out
600
+
601
+
602
+ def test_approve_refuses_a_job_already_stopped_by_sigint(tmp_path):
603
+ # real Codex run 30 Oct: approve after the SIGINT said "the run continues" but the job was ending
604
+ root, d = _job(tmp_path, agent="codex", stopped=True)
605
+ msg = q.approve_job(root)
606
+ assert "already stopped" in msg and "continues" not in msg
607
+ assert json.loads((d / "job.json").read_text())["quota"] == 4.0
608
+
609
+
610
+ def test_codex_stop_marks_job_stopped(fakebin, tmp_path):
611
+ r, events, err = make_runner(["codex"], tmp_path)
612
+ assert r.run() == 3
613
+ assert json.loads((r.job_dir / "job.json").read_text())["stopped"] is True
614
+
615
+
616
+ def test_codex_sub_1pct_quota_warns_whole_percent(fakebin, tmp_path, monkeypatch):
617
+ monkeypatch.setenv("FAKE_N", "2")
618
+ r, events, err = make_runner(["codex"], tmp_path, quota=0.5)
619
+ r.run()
620
+ assert "whole percent" in err.getvalue()
621
+
622
+
623
+ def test_codex_1pct_quota_no_whole_percent_warning(fakebin, tmp_path, monkeypatch):
624
+ monkeypatch.setenv("FAKE_N", "2")
625
+ r, events, err = make_runner(["codex"], tmp_path, quota=1.0)
626
+ r.run()
627
+ assert "whole percent" not in err.getvalue()
File without changes
File without changes