agentcap-cli 0.2.1__tar.gz → 0.3.1__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 (107) hide show
  1. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/PKG-INFO +162 -15
  2. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/README.md +160 -13
  3. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/pyproject.toml +5 -2
  4. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/__init__.py +1 -1
  5. agentcap_cli-0.3.1/src/agentcap/_lifeline_exec.py +99 -0
  6. agentcap_cli-0.3.1/src/agentcap/_lifeline_watch.py +46 -0
  7. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/adapters.py +100 -0
  8. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/alerts.py +57 -1
  9. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/budget.py +3 -1
  10. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/cli.py +145 -17
  11. agentcap_cli-0.3.1/src/agentcap/failsafe.py +161 -0
  12. agentcap_cli-0.3.1/src/agentcap/harness.py +566 -0
  13. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/history.py +2 -1
  14. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/ledger.py +3 -1
  15. agentcap_cli-0.3.1/src/agentcap/lifeline.py +209 -0
  16. agentcap_cli-0.3.1/src/agentcap/logschema.py +109 -0
  17. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/loop.py +189 -6
  18. agentcap_cli-0.3.1/src/agentcap/private.py +159 -0
  19. agentcap_cli-0.3.1/src/agentcap/procstop.py +640 -0
  20. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/proxy.py +245 -13
  21. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/quota.py +473 -177
  22. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/runner.py +176 -12
  23. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/waste.py +6 -0
  24. agentcap_cli-0.3.1/tests/fixtures/harness_logs/agy-1.4.11-2026-10-30.jsonl +8 -0
  25. agentcap_cli-0.3.1/tests/fixtures/harness_logs/claude-2.1.316-pretooluse.json +1 -0
  26. agentcap_cli-0.3.1/tests/fixtures/harness_logs/claude-2.1.316-statusline.json +1 -0
  27. agentcap_cli-0.3.1/tests/fixtures/harness_logs/codex-rollout-2026-10-29.jsonl +3 -0
  28. agentcap_cli-0.3.1/tests/fixtures/harness_logs/opencode-2026-10-30.jsonl +5 -0
  29. agentcap_cli-0.3.1/tests/fixtures/upstream/README.md +4 -0
  30. agentcap_cli-0.3.1/tests/fixtures/upstream/anthropic_403_permission_error.json +1 -0
  31. agentcap_cli-0.3.1/tests/fixtures/upstream/openai_403_region_blocked.json +1 -0
  32. agentcap_cli-0.3.1/tests/fixtures/upstream/openrouter_401_user_not_found.json +1 -0
  33. agentcap_cli-0.3.1/tests/fixtures/upstream/openrouter_403_moderation.json +1 -0
  34. agentcap_cli-0.3.1/tests/fixtures/upstream/openrouter_429_rate_limited.json +1 -0
  35. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_budget.py +1 -0
  36. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_cc_plugin.py +174 -1
  37. agentcap_cli-0.3.1/tests/test_child_status.py +232 -0
  38. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_claude_adapter_and_tiers.py +16 -0
  39. agentcap_cli-0.3.1/tests/test_concurrent_forgive.py +169 -0
  40. agentcap_cli-0.3.1/tests/test_exit_codes.py +326 -0
  41. agentcap_cli-0.3.1/tests/test_failsafe.py +150 -0
  42. agentcap_cli-0.3.1/tests/test_harness.py +524 -0
  43. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_history.py +1 -0
  44. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_ledger.py +10 -1
  45. agentcap_cli-0.3.1/tests/test_lifeline.py +280 -0
  46. agentcap_cli-0.3.1/tests/test_log_contract.py +192 -0
  47. agentcap_cli-0.3.1/tests/test_log_contract_live.py +54 -0
  48. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_loop.py +72 -0
  49. agentcap_cli-0.3.1/tests/test_private_dirs.py +226 -0
  50. agentcap_cli-0.3.1/tests/test_procstop.py +886 -0
  51. agentcap_cli-0.3.1/tests/test_proxy_auth.py +554 -0
  52. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_quota.py +277 -2
  53. agentcap_cli-0.3.1/tests/test_release.py +40 -0
  54. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_runner.py +96 -0
  55. agentcap_cli-0.3.1/tests/test_self_approve.py +129 -0
  56. agentcap_cli-0.3.1/tests/test_upstream_refusals.py +246 -0
  57. agentcap_cli-0.3.1/tests/test_zombie_collector.py +191 -0
  58. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/.gitignore +0 -0
  59. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/LICENSE +0 -0
  60. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/analytics.py +0 -0
  61. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/clamp.py +0 -0
  62. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/cli_history.py +0 -0
  63. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/data/pricing.json +0 -0
  64. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/demo.py +0 -0
  65. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/devtools/__init__.py +0 -0
  66. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/devtools/fake_upstream.py +0 -0
  67. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/estimate.py +0 -0
  68. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/eta.py +0 -0
  69. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/license.py +0 -0
  70. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/plans.py +0 -0
  71. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/pricing.py +0 -0
  72. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/report.py +0 -0
  73. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/upstreams.py +0 -0
  74. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/src/agentcap/usage.py +0 -0
  75. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/conftest.py +0 -0
  76. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-a1b2c3.jsonl +0 -0
  77. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-d4e5f6.jsonl +0 -0
  78. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p.jsonl +0 -0
  79. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-00-thr-parent.jsonl +0 -0
  80. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-50-thr-child.jsonl +0 -0
  81. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-01-20-thr-fork.jsonl +0 -0
  82. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/history/claude/.credentials.json +0 -0
  83. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/history/claude/projects/-home-dev-shop/1f0c-sess-a.jsonl +0 -0
  84. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/history/codex/auth.json +0 -0
  85. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/fixtures/history/codex/sessions/2026/10/29/rollout-2026-10-29T10-00-00-0199aaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl +0 -0
  86. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/license_support.py +0 -0
  87. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/proxy_support.py +0 -0
  88. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_adapters.py +0 -0
  89. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_agents.py +0 -0
  90. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_alerts.py +0 -0
  91. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_analytics.py +0 -0
  92. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_anthropic_proxy.py +0 -0
  93. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_anthropic_units.py +0 -0
  94. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_clamp.py +0 -0
  95. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_cli.py +0 -0
  96. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_e2e_claude.py +0 -0
  97. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_estimate.py +0 -0
  98. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_license.py +0 -0
  99. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_pricing.py +0 -0
  100. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_proxy_cancel.py +0 -0
  101. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_proxy_core.py +0 -0
  102. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_proxy_extras.py +0 -0
  103. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_proxy_streaming.py +0 -0
  104. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_report_cli.py +0 -0
  105. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_runaway.py +0 -0
  106. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_upstreams.py +0 -0
  107. {agentcap_cli-0.2.1 → agentcap_cli-0.3.1}/tests/test_usage.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: agentcap-cli
3
- Version: 0.2.1
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.
3
+ Version: 0.3.1
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
7
7
  Project-URL: Issues, https://github.com/Blitz00X/agentcap/issues
@@ -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
@@ -322,8 +324,9 @@ agentcap quota # read-only: last seen usage (Fre
322
324
  `used_percentage`, `resets_at`) and then runs **your own statusline command unchanged**,
323
325
  plus a `PreToolUse` hook that denies further tool calls with a clear reason once the job's
324
326
  share reaches the limit and ends the turn (`continue: false`). An interactive session stays open
325
- (run `agentcap approve` to continue, or quit). Headless `claude -p` runs, and sessions where
326
- the hook never fired, get SIGINT. Exit code 3.
327
+ (run `agentcap approve` to continue, or quit); a session where the hook never fired gets
328
+ SIGINT. Exit code 3. **Quota % is interactive-only:** headless `claude -p` exposes no usage %
329
+ to AgentCap, so `--quota` warns and only the loop/error breakers are active there.
327
330
  - **Codex CLI:** AgentCap tails the `token_count` events Codex writes to
328
331
  `~/.codex/sessions/**/rollout-*.jsonl` (`rate_limits.primary/secondary.used_percent`,
329
332
  `window_minutes`, `resets_at`) and sends SIGINT at the limit. Exit code 3.
@@ -338,10 +341,27 @@ agentcap quota # read-only: last seen usage (Fre
338
341
  use in the same window counts against the job (AgentCap warns when it sees another session).
339
342
  Values arrive once per model response, so a job **can overshoot by up to one request**.
340
343
  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.
342
- **Verified so far on fixtures and fake CLIs only** (plus real Claude Code 2.1.197: the `--settings`
343
- layer, the chained statusline and the `PreToolUse` deny were checked against a local fake API);
344
- a check on a real Max / ChatGPT account is still pending.
344
+ (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.
345
+ Claude Code reports whole percents too: a cap under 1% trips at the next 1% step (AgentCap warns).
346
+ Verified on real accounts: see the harness support matrix under "Supported & tested".
347
+
348
+ ## opencode and agy (Antigravity CLI)
349
+
350
+ Headless runs only. AgentCap reads each agent's own event stream; nothing is proxied in these modes.
351
+
352
+ ```bash
353
+ # opencode Go (or any opencode provider): token cap, loop + error breakers
354
+ agentcap run --tokens 200000 -- opencode run -m opencode-go/deepseek-v4.1-flash "fix the test"
355
+ # opencode: cap on opencode's own cost estimate
356
+ agentcap run --log-cap 0.50 -- opencode run -m opencode-go/glm-5.3 "..."
357
+ # agy on a Google subscription: real quota % from `agy -p /quota`
358
+ agentcap run --quota 2% --window 5h -- agy --model gemini-3.8-flash-low -p "..."
359
+ # $ APIs through the proxy (OpenRouter shown)
360
+ AGENTCAP_OPENAI_UPSTREAM=https://openrouter.ai/api OPENAI_API_KEY=$OPENROUTER_API_KEY \
361
+ agentcap run --cap 0.50 -- opencode run -m agentcap/<openrouter model id> "..."
362
+ ```
363
+
364
+ opencode does not expose subscription quota %, so `--quota` is refused for it; use `--tokens` or `--log-cap`. `--log-cap` trusts opencode's price table, not AgentCap's.
345
365
 
346
366
  ## Try it without an API key
347
367
 
@@ -394,6 +414,33 @@ billing. Gemini CLI 0.58 and Codex CLI 0.163 are tested end-to-end against a loc
394
414
 
395
415
  Models without a bundled price (for example OpenRouter or Ollama ids) are blocked until you add a price via `AGENTCAP_PRICING_FILE`.
396
416
 
417
+ ### Harness support matrix (real runs)
418
+
419
+ Legend: ✅ verified on a real account/endpoint · ⚠️ works with a limitation · ❌ not supported · **needs X** = untested, X blocks it.
420
+
421
+ | Harness + auth | Loop breaker (4x same call, exit 4) | Error breaker (8 failures, exit 4) | Quota % stop (exit 3) | $ / token cap |
422
+ | --- | --- | --- | --- | --- |
423
+ | Claude Code, Pro/Max sub, interactive | ✅ (deny keeps the session; resumes after approve) | ✅ | ✅ whole-% steps (deny keeps the session); `agentcap approve` ✅ | ❌ by design (no proxy on a subscription login; AgentCap refuses) |
424
+ | Claude Code, Pro/Max sub, headless `claude -p` | ✅ (exit 4) | ✅ (exit 4) | ❌ interactive only (warns at start) | ❌ by design (refused) |
425
+ | Codex, ChatGPT sub | ✅ | ✅ | ✅ (whole %; warns under 1%) | ❌ by design (no proxy on a subscription) |
426
+ | opencode Go | ✅ | ✅ | ❌ opencode exposes no quota % | ✅ `--tokens`; `--log-cap` uses opencode's own price table |
427
+ | agy, Google sub (plain `agentcap run -- agy` needs no key: breakers only) | ✅ | ✅ | ✅ (tested at 0.5%; ~10 s polling, can overshoot) | ❌ (sub); $ only via Gemini API |
428
+ | opencode + OpenRouter (free model) | ✅ | ✅ | n/a | ✅ $ cap |
429
+ | opencode + Ollama Cloud | ✅ | ✅ | n/a | ⚠️ needs a user price (`AGENTCAP_PRICING_FILE`): Ollama publishes none |
430
+ | Codex + Ollama | ✅ (exit 4 on 4th identical exec) | ✅ | n/a | ✅ $ cap (user price) |
431
+ | Codex + OpenRouter | ✅ (exit 4 after 4 identical steps in a row; Codex 0.166, free model, 5 Nov 2026) | ✅ (exit 4 on the 8th failing command) | n/a | ✅ $ cap stop (earlier release run, free model); a rejected key stops with `upstream_auth_failed` (exit 2) |
432
+ | agy + Gemini API | **not provable on a free key**: agy sends >5 req/min and exits on the first 429 (no retry); needs a paid key | same | n/a | ✅ $ cap (exit 3) |
433
+ | Claude Code + `ANTHROPIC_API_KEY` | **needs an Anthropic API key** (proxy path; only a local fake API so far) | **needs an Anthropic API key** | n/a | **needs an Anthropic API key** |
434
+
435
+ Tested with Claude Code 2.1.316 on a real Claude Pro login (Haiku) and an activated AgentCap Pro
436
+ license, through the CLI, 1 Nov 2026. 429/5xx retries (identical resends) are counted neither as loops nor as failing tool calls.
437
+
438
+ Known limits: quota % is account-level (parallel sessions count); Claude/Codex report whole
439
+ percents; interactive Claude turns with no tool calls can't be denied, so after a 30 s grace
440
+ period AgentCap sends SIGINT and the session ends; Codex's sandbox can't run commands on Ubuntu 24.04 by default:
441
+ `kernel.apparmor_restrict_unprivileged_userns=1` blocks bubblewrap's user namespace
442
+ (host setting, not AgentCap; Codex falls back or needs an AppArmor profile for bwrap).
443
+
397
444
  **Platforms:** Linux and macOS. Windows: not yet (use WSL2).
398
445
 
399
446
  ## How it works
@@ -428,8 +475,12 @@ Models without a bundled price (for example OpenRouter or Ollama ids) are blocke
428
475
  running; real usage still settles the reservation. Clamping is on by default
429
476
  and can be disabled with `--no-clamp`.
430
477
  6. If even a minimal clamped request cannot fit, the request is blocked and the
431
- whole child process group is terminated (`SIGTERM`, then `SIGKILL` after
432
- 5s). `agentcap run` exits with code `3`. Pro's loop/burn breaker exits
478
+ whole child process group is terminated. In proxy (`--cap`) mode that is
479
+ `SIGTERM`, then `SIGKILL` after 5 s. Quota and harness (`--quota`,
480
+ `--tokens`, `--log-cap`) modes use `SIGINT` → `SIGTERM` → `SIGKILL`
481
+ (5 s / 3 s / 2 s) so a headless agent can end its turn; both paths are
482
+ described under "Stopping, fail-closed and self-approval". `agentcap run`
483
+ exits with code `3`. Pro's loop/burn breaker exits
433
484
  with `4` (same step 4 times in a row, 8 failing tool results in a row, or a
434
485
  burn rate above `--max-burn` $/min; see Free vs Pro).
435
486
  The kill and its red alert fire at most once per run; later rejected
@@ -449,6 +500,19 @@ raised. Everything else is forwarded byte-for-byte, including credentials.
449
500
  Reasoning/thinking tokens are billed as output and count against the same
450
501
  output limit, so a clamp also caps them.
451
502
 
503
+ ### Exit codes
504
+
505
+ `agentcap run` uses the same codes in `--cap`, `--quota`, `--tokens` and
506
+ `--log-cap` modes (0.3.1). Otherwise it returns the agent's own exit code.
507
+
508
+ | Code | Meaning |
509
+ | --- | --- |
510
+ | `2` | Setup or auth refusal: bad flags, a Pro-only flag on Free, a conflicting CLI config, a second quota job, the provider rejected the credentials (`upstream_auth_failed`), or it refused the request for another reason (`upstream_refused`). |
511
+ | `3` | A cap stopped the agent (`--cap`, `--quota`, `--tokens`, `--log-cap`). |
512
+ | `4` | Pro's loop/error/burn breaker stopped the agent. |
513
+ | `5` | Internal error: AgentCap could not use its own state (HOME, `quota.lock`, ledger, license or job files), its proxy could not start, an opencode/agy log schema or Codex rollout log could not be read (fail-closed), or AgentCap hit an internal fault. The message names the failed action and path (`internal state error: could not open the quota lock ...`); the agent was not started, or was stopped (reason `internal_error`). |
514
+ | `127` | The command itself could not be started (not found, not executable): `could not start the command (...)`. |
515
+
452
516
  ## Metered endpoints
453
517
 
454
518
  | Provider | Endpoints |
@@ -478,9 +542,92 @@ Request bodies are billed at price-book rates; embeddings are input-only.
478
542
  tokenizer differences), the final spend can exceed the cap by that one
479
543
  request's estimation error. AgentCap emits an `overshoot` alert when a
480
544
  settlement exceeds its reservation.
481
- - The ledger lives at `~/.local/share/agentcap/ledger.sqlite3`
545
+ - The ledger lives at `~/.local/state/agentcap/ledger.sqlite3`
482
546
  (override with `$AGENTCAP_DB`).
483
547
 
548
+ ### Stopping, fail-closed and self-approval (0.3, Linux-verified)
549
+
550
+ - **Whole process tree.** A quota/harness stop (`--quota`, `--tokens`, `--log-cap`) sends SIGINT
551
+ to the agent's process group, then SIGTERM, then SIGKILL (5 s / 3 s / 2 s); a proxy (`--cap`)
552
+ stop sends SIGTERM, then SIGKILL after 5 s. Helpers the agent left behind in its group are also killed after a
553
+ normal exit, so a dev server started by the agent does not outlive the run.
554
+ On Linux AgentCap also enables `PR_SET_CHILD_SUBREAPER` for the run: descendants that call
555
+ `setsid()` or double-fork are adopted, matched against a pre-run snapshot (PID + start time),
556
+ and swept with SIGTERM then SIGKILL after a normal exit or a stop. It prints
557
+ `killed N process(es) that left the agent's process group` when that happens. A descendant it
558
+ may not signal (a root-owned `sudo -b` child, a setuid program) is tried once, not waited on, and
559
+ left running with a `could not stop N process(es) (permission denied): pid ...` warning. Daemons the agent
560
+ starts (a dev server, a `tmux` server, a Gradle daemon) are part of its tree and stop with the run.
561
+ If AgentCap itself is SIGKILLed or OOM-killed, the parent-death lifeline (`PR_SET_PDEATHSIG`)
562
+ kills the direct agent and a small watchdog SIGKILLs the agent's process group, which also covers
563
+ a real agent started by a launcher (Codex's npm wrapper on Node without `process.execve`) and
564
+ the agent's tool processes.
565
+ Limits: on non-Linux only the process group is cleaned and there is no lifeline. A process that
566
+ left the agent's group (`setsid`/daemonized) before AgentCap itself was SIGKILLed can still
567
+ escape: no userspace process can clean up after its own SIGKILL. Use a container/cgroup or a
568
+ separate OS user when the agent is not trusted. Adopted helpers that exit during a run stay
569
+ zombies until it ends (the agent's group is reaped once the agent exits, the rest by the final
570
+ sweep): `/proc` cannot tell an adopted `setsid` helper from a child AgentCap's own process
571
+ started in a new session, and taking that child's exit status would make it report 0. A long
572
+ run whose agent keeps leaving short-lived detached helpers holds one PID per finished helper,
573
+ counted against `ulimit -u`, until the run ends. Opt-in (0.3.1, default off):
574
+ `AGENTCAP_COLLECT_ZOMBIES=1` reaps, about once a second during the run, adopted zombies whose
575
+ session id is neither AgentCap's nor their own pid (an in-group background job, a double-forked
576
+ daemon), after re-checking their PID + start time. The agent, `setsid` helpers (session leaders)
577
+ and AgentCap's own children are never reaped early, so their exit codes are kept; `setsid`
578
+ helpers are still collected by the final sweep. Interrupting a job
579
+ can leave its work half done (a migration, a deploy): that is the job's responsibility, so
580
+ commit before a guarded run.
581
+ - **Fail-closed.** On Pro, quota and harness runs (`--quota`, `--tokens`, `--log-cap`) stop the
582
+ agent with exit code 5 instead of letting it run unguarded when opencode/agy output matches no
583
+ known log schema, the Codex session log becomes unreadable, or AgentCap itself hits an internal
584
+ error; Free only warns about these. In `--cap` mode an internal AgentCap error stops the agent
585
+ too, with exit code 5 and reason `internal_error` (since 0.3.1; see "Exit codes"). Two quota jobs at once are refused on Free and Pro (exit 2),
586
+ since the quota % is account-wide; `AGENTCAP_ALLOW_PARALLEL=1` turns that lock off.
587
+ Not covered yet: a stale Claude statusline (no fresh `rate_limits`) is reported, not stopped.
588
+ - **Rejected credentials (`--cap` proxy mode).** When the provider answers HTTP 401, 402
589
+ (OpenRouter: no credits), 403, or Gemini's 400 `API_KEY_INVALID`, AgentCap prints
590
+ `upstream rejected the request (HTTP 401: User not found.) — check the API key for <host>;
591
+ nothing was spent.` (the provider's short `error.message`, truncated, key-shaped text redacted,
592
+ headers never read). The agent's resends of such a request never count toward the loop breaker.
593
+ After 3 rejections in a row with no other answer between them, the run is stopped on Free and Pro
594
+ with reason `upstream_auth_failed` and exit 2 (like AgentCap's other exit-2 refusals: a setup
595
+ problem to fix, rerunning unchanged cannot help). 429/5xx answers in between neither count nor
596
+ break the streak, so 401/429/401/429/401 still stops. A 403 whose body is not about the key,
597
+ permission or account (a region/country block, a moderation or policy refusal, or no readable
598
+ body) is reported as `provider refused the request` instead, and three in a row stop the run with
599
+ reason `upstream_refused` (exit 2). If the agent gives up first with a non-zero exit code, the
600
+ reason is still `upstream_auth_failed`/`upstream_refused` and its own exit code is kept; if it
601
+ exits 0, the reason stays `child_exit` and the rejection is printed as a separate warning. One
602
+ rejection followed by a success changes nothing. `agentcap serve` only reports it and keeps serving.
603
+ - **Self-approval.** `agentcap approve` refuses (exit 2) when it runs inside an agent session
604
+ (`AGENTCAP_QUOTA_JOB`, `AGENTCAP_GUARDED` or `CLAUDECODE` in its environment), and the hook of
605
+ `agentcap run --quota -- claude` denies a Bash call that runs `agentcap approve`;
606
+ `/agentcap:approve` cannot be invoked by the model (`disable-model-invocation`). Run approve
607
+ from your own terminal. The Claude Code plugin's `PreToolUse` hook denies, on Free and Pro, any
608
+ model tool call that would run its own script (`python3 .../scripts/agentcap_cc.py approve`,
609
+ `quota`, `off`, `setup`, `unsetup`, `statusline`, `hook`; any path, `python -m agentcap_cc`,
610
+ `import agentcap_cc`, an `agentcap*` glob, quoted/escaped/`$IFS` forms, inside `bash -c`/`sh -c`)
611
+ or touch its state dir or installed plugin files: Bash and any other tool with a `command`, and
612
+ Write/Edit/MultiEdit/NotebookEdit on those paths. Plain reads (`cat`, `grep`, `ls`, `jq`, ...;
613
+ `git` without `-c`/config/checkout-style subcommands) still pass. Your own `/agentcap:approve`,
614
+ `/agentcap:quota` and `/agentcap:off` keep working: Claude Code runs a slash command's `!` line
615
+ without `PreToolUse` hooks (measured on 2.1.318, headless). When Claude Code's working
616
+ directory is inside the plugin's own checkout, its code files stay editable (plugin development).
617
+ What still passes: a command that never names the script or state dir (a script the agent
618
+ writes elsewhere that builds the path at run time, `$(printf ...)` path pieces, other globs),
619
+ and tools that execute code without a `command` field.
620
+ **Honest limit:** the agent runs as your OS user, so a determined agent can still clear the
621
+ environment, edit AgentCap's state files or kill AgentCap. AgentCap guards cooperative
622
+ workloads against accidents (loops, runaway spend), not a hostile agent; use a separate OS
623
+ user or container for that.
624
+ - **Log format changes.** AgentCap reads harness logs, and vendors change them. The fields it
625
+ reads are pinned per harness in `agentcap/logschema.py` (opencode, agy, Claude Code statusline
626
+ and PreToolUse, Codex rollout) and checked by `tests/test_log_contract.py` against recorded
627
+ fixtures; `AGENTCAP_LIVE_CONTRACT=1 pytest tests/test_log_contract_live.py` re-checks the
628
+ installed opencode/agy (one small model call). At run time an unknown schema fails closed
629
+ (above). Last live check: opencode 2.2.4 (3 Nov 2026).
630
+
484
631
  ## Privacy
485
632
 
486
633
  Prompts and keys pass through the local proxy in memory; AgentCap never stores
@@ -563,7 +710,7 @@ steps are noisy. No team aggregation: everything stays on your machine.
563
710
  When the Pro detectors below would have fired on a Free run, AgentCap does not stop it.
564
711
  It prints one line: `Pro's loop breaker would have stopped this at $X.XX`.
565
712
 
566
- **Pro, $12 one-time (launch week, until 10 Nov; then $19): stop runs that loop or eat your quota.**
713
+ **Pro, $12 one-time (launch week; $19 after): stop runs that loop or eat your quota.**
567
714
 
568
715
  **Get Pro:** buy at https://agentcap.launchbench.studio/#pricing (Polar checkout). Polar then
569
716
  emails you an **Access purchase** link; the key is in the Polar customer portal (not in the
@@ -592,7 +739,7 @@ The VS Code/Cursor extension and the Claude Code plugin use the same CLI licence
592
739
 
593
740
  ### Purchase terms
594
741
 
595
- - Pro is $12 one-time (launch week, until 10 Nov; then $19), no subscription.
742
+ - Pro is $12 one-time (launch week; $19 after), no subscription. The current launch-week end date is on the pricing page.
596
743
  - 14-day no-questions refund — email
597
744
  [kutaykarahan6@gmail.com](mailto:kutaykarahan6@gmail.com).
598
745
  - One licence key activates on up to 3 machines.
@@ -661,7 +808,7 @@ prices and reported usage; when usage is missing it charges the full reservation
661
808
  **Is the day cap shared across machines?** No. Hour/day caps are per machine
662
809
  (local SQLite ledger). A license covers 3 machines, each with its own budget.
663
810
 
664
- **What does one-time purchase include?** $12 once in launch week ($19 after 10 Nov), all 0.x updates; not a
811
+ **What does one-time purchase include?** $12 once in launch week ($19 after), all 0.x updates; not a
665
812
  promise of future major versions. 14-day refund window per purchase terms.
666
813
 
667
814
  ## License
@@ -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
@@ -292,8 +294,9 @@ agentcap quota # read-only: last seen usage (Fre
292
294
  `used_percentage`, `resets_at`) and then runs **your own statusline command unchanged**,
293
295
  plus a `PreToolUse` hook that denies further tool calls with a clear reason once the job's
294
296
  share reaches the limit and ends the turn (`continue: false`). An interactive session stays open
295
- (run `agentcap approve` to continue, or quit). Headless `claude -p` runs, and sessions where
296
- the hook never fired, get SIGINT. Exit code 3.
297
+ (run `agentcap approve` to continue, or quit); a session where the hook never fired gets
298
+ SIGINT. Exit code 3. **Quota % is interactive-only:** headless `claude -p` exposes no usage %
299
+ to AgentCap, so `--quota` warns and only the loop/error breakers are active there.
297
300
  - **Codex CLI:** AgentCap tails the `token_count` events Codex writes to
298
301
  `~/.codex/sessions/**/rollout-*.jsonl` (`rate_limits.primary/secondary.used_percent`,
299
302
  `window_minutes`, `resets_at`) and sends SIGINT at the limit. Exit code 3.
@@ -308,10 +311,27 @@ agentcap quota # read-only: last seen usage (Fre
308
311
  use in the same window counts against the job (AgentCap warns when it sees another session).
309
312
  Values arrive once per model response, so a job **can overshoot by up to one request**.
310
313
  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.
312
- **Verified so far on fixtures and fake CLIs only** (plus real Claude Code 2.1.197: the `--settings`
313
- layer, the chained statusline and the `PreToolUse` deny were checked against a local fake API);
314
- a check on a real Max / ChatGPT account is still pending.
314
+ (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.
315
+ Claude Code reports whole percents too: a cap under 1% trips at the next 1% step (AgentCap warns).
316
+ Verified on real accounts: see the harness support matrix under "Supported & tested".
317
+
318
+ ## opencode and agy (Antigravity CLI)
319
+
320
+ Headless runs only. AgentCap reads each agent's own event stream; nothing is proxied in these modes.
321
+
322
+ ```bash
323
+ # opencode Go (or any opencode provider): token cap, loop + error breakers
324
+ agentcap run --tokens 200000 -- opencode run -m opencode-go/deepseek-v4.1-flash "fix the test"
325
+ # opencode: cap on opencode's own cost estimate
326
+ agentcap run --log-cap 0.50 -- opencode run -m opencode-go/glm-5.3 "..."
327
+ # agy on a Google subscription: real quota % from `agy -p /quota`
328
+ agentcap run --quota 2% --window 5h -- agy --model gemini-3.8-flash-low -p "..."
329
+ # $ APIs through the proxy (OpenRouter shown)
330
+ AGENTCAP_OPENAI_UPSTREAM=https://openrouter.ai/api OPENAI_API_KEY=$OPENROUTER_API_KEY \
331
+ agentcap run --cap 0.50 -- opencode run -m agentcap/<openrouter model id> "..."
332
+ ```
333
+
334
+ opencode does not expose subscription quota %, so `--quota` is refused for it; use `--tokens` or `--log-cap`. `--log-cap` trusts opencode's price table, not AgentCap's.
315
335
 
316
336
  ## Try it without an API key
317
337
 
@@ -364,6 +384,33 @@ billing. Gemini CLI 0.58 and Codex CLI 0.163 are tested end-to-end against a loc
364
384
 
365
385
  Models without a bundled price (for example OpenRouter or Ollama ids) are blocked until you add a price via `AGENTCAP_PRICING_FILE`.
366
386
 
387
+ ### Harness support matrix (real runs)
388
+
389
+ Legend: ✅ verified on a real account/endpoint · ⚠️ works with a limitation · ❌ not supported · **needs X** = untested, X blocks it.
390
+
391
+ | Harness + auth | Loop breaker (4x same call, exit 4) | Error breaker (8 failures, exit 4) | Quota % stop (exit 3) | $ / token cap |
392
+ | --- | --- | --- | --- | --- |
393
+ | Claude Code, Pro/Max sub, interactive | ✅ (deny keeps the session; resumes after approve) | ✅ | ✅ whole-% steps (deny keeps the session); `agentcap approve` ✅ | ❌ by design (no proxy on a subscription login; AgentCap refuses) |
394
+ | Claude Code, Pro/Max sub, headless `claude -p` | ✅ (exit 4) | ✅ (exit 4) | ❌ interactive only (warns at start) | ❌ by design (refused) |
395
+ | Codex, ChatGPT sub | ✅ | ✅ | ✅ (whole %; warns under 1%) | ❌ by design (no proxy on a subscription) |
396
+ | opencode Go | ✅ | ✅ | ❌ opencode exposes no quota % | ✅ `--tokens`; `--log-cap` uses opencode's own price table |
397
+ | agy, Google sub (plain `agentcap run -- agy` needs no key: breakers only) | ✅ | ✅ | ✅ (tested at 0.5%; ~10 s polling, can overshoot) | ❌ (sub); $ only via Gemini API |
398
+ | opencode + OpenRouter (free model) | ✅ | ✅ | n/a | ✅ $ cap |
399
+ | opencode + Ollama Cloud | ✅ | ✅ | n/a | ⚠️ needs a user price (`AGENTCAP_PRICING_FILE`): Ollama publishes none |
400
+ | Codex + Ollama | ✅ (exit 4 on 4th identical exec) | ✅ | n/a | ✅ $ cap (user price) |
401
+ | Codex + OpenRouter | ✅ (exit 4 after 4 identical steps in a row; Codex 0.166, free model, 5 Nov 2026) | ✅ (exit 4 on the 8th failing command) | n/a | ✅ $ cap stop (earlier release run, free model); a rejected key stops with `upstream_auth_failed` (exit 2) |
402
+ | agy + Gemini API | **not provable on a free key**: agy sends >5 req/min and exits on the first 429 (no retry); needs a paid key | same | n/a | ✅ $ cap (exit 3) |
403
+ | Claude Code + `ANTHROPIC_API_KEY` | **needs an Anthropic API key** (proxy path; only a local fake API so far) | **needs an Anthropic API key** | n/a | **needs an Anthropic API key** |
404
+
405
+ Tested with Claude Code 2.1.316 on a real Claude Pro login (Haiku) and an activated AgentCap Pro
406
+ license, through the CLI, 1 Nov 2026. 429/5xx retries (identical resends) are counted neither as loops nor as failing tool calls.
407
+
408
+ Known limits: quota % is account-level (parallel sessions count); Claude/Codex report whole
409
+ percents; interactive Claude turns with no tool calls can't be denied, so after a 30 s grace
410
+ period AgentCap sends SIGINT and the session ends; Codex's sandbox can't run commands on Ubuntu 24.04 by default:
411
+ `kernel.apparmor_restrict_unprivileged_userns=1` blocks bubblewrap's user namespace
412
+ (host setting, not AgentCap; Codex falls back or needs an AppArmor profile for bwrap).
413
+
367
414
  **Platforms:** Linux and macOS. Windows: not yet (use WSL2).
368
415
 
369
416
  ## How it works
@@ -398,8 +445,12 @@ Models without a bundled price (for example OpenRouter or Ollama ids) are blocke
398
445
  running; real usage still settles the reservation. Clamping is on by default
399
446
  and can be disabled with `--no-clamp`.
400
447
  6. If even a minimal clamped request cannot fit, the request is blocked and the
401
- whole child process group is terminated (`SIGTERM`, then `SIGKILL` after
402
- 5s). `agentcap run` exits with code `3`. Pro's loop/burn breaker exits
448
+ whole child process group is terminated. In proxy (`--cap`) mode that is
449
+ `SIGTERM`, then `SIGKILL` after 5 s. Quota and harness (`--quota`,
450
+ `--tokens`, `--log-cap`) modes use `SIGINT` → `SIGTERM` → `SIGKILL`
451
+ (5 s / 3 s / 2 s) so a headless agent can end its turn; both paths are
452
+ described under "Stopping, fail-closed and self-approval". `agentcap run`
453
+ exits with code `3`. Pro's loop/burn breaker exits
403
454
  with `4` (same step 4 times in a row, 8 failing tool results in a row, or a
404
455
  burn rate above `--max-burn` $/min; see Free vs Pro).
405
456
  The kill and its red alert fire at most once per run; later rejected
@@ -419,6 +470,19 @@ raised. Everything else is forwarded byte-for-byte, including credentials.
419
470
  Reasoning/thinking tokens are billed as output and count against the same
420
471
  output limit, so a clamp also caps them.
421
472
 
473
+ ### Exit codes
474
+
475
+ `agentcap run` uses the same codes in `--cap`, `--quota`, `--tokens` and
476
+ `--log-cap` modes (0.3.1). Otherwise it returns the agent's own exit code.
477
+
478
+ | Code | Meaning |
479
+ | --- | --- |
480
+ | `2` | Setup or auth refusal: bad flags, a Pro-only flag on Free, a conflicting CLI config, a second quota job, the provider rejected the credentials (`upstream_auth_failed`), or it refused the request for another reason (`upstream_refused`). |
481
+ | `3` | A cap stopped the agent (`--cap`, `--quota`, `--tokens`, `--log-cap`). |
482
+ | `4` | Pro's loop/error/burn breaker stopped the agent. |
483
+ | `5` | Internal error: AgentCap could not use its own state (HOME, `quota.lock`, ledger, license or job files), its proxy could not start, an opencode/agy log schema or Codex rollout log could not be read (fail-closed), or AgentCap hit an internal fault. The message names the failed action and path (`internal state error: could not open the quota lock ...`); the agent was not started, or was stopped (reason `internal_error`). |
484
+ | `127` | The command itself could not be started (not found, not executable): `could not start the command (...)`. |
485
+
422
486
  ## Metered endpoints
423
487
 
424
488
  | Provider | Endpoints |
@@ -448,9 +512,92 @@ Request bodies are billed at price-book rates; embeddings are input-only.
448
512
  tokenizer differences), the final spend can exceed the cap by that one
449
513
  request's estimation error. AgentCap emits an `overshoot` alert when a
450
514
  settlement exceeds its reservation.
451
- - The ledger lives at `~/.local/share/agentcap/ledger.sqlite3`
515
+ - The ledger lives at `~/.local/state/agentcap/ledger.sqlite3`
452
516
  (override with `$AGENTCAP_DB`).
453
517
 
518
+ ### Stopping, fail-closed and self-approval (0.3, Linux-verified)
519
+
520
+ - **Whole process tree.** A quota/harness stop (`--quota`, `--tokens`, `--log-cap`) sends SIGINT
521
+ to the agent's process group, then SIGTERM, then SIGKILL (5 s / 3 s / 2 s); a proxy (`--cap`)
522
+ stop sends SIGTERM, then SIGKILL after 5 s. Helpers the agent left behind in its group are also killed after a
523
+ normal exit, so a dev server started by the agent does not outlive the run.
524
+ On Linux AgentCap also enables `PR_SET_CHILD_SUBREAPER` for the run: descendants that call
525
+ `setsid()` or double-fork are adopted, matched against a pre-run snapshot (PID + start time),
526
+ and swept with SIGTERM then SIGKILL after a normal exit or a stop. It prints
527
+ `killed N process(es) that left the agent's process group` when that happens. A descendant it
528
+ may not signal (a root-owned `sudo -b` child, a setuid program) is tried once, not waited on, and
529
+ left running with a `could not stop N process(es) (permission denied): pid ...` warning. Daemons the agent
530
+ starts (a dev server, a `tmux` server, a Gradle daemon) are part of its tree and stop with the run.
531
+ If AgentCap itself is SIGKILLed or OOM-killed, the parent-death lifeline (`PR_SET_PDEATHSIG`)
532
+ kills the direct agent and a small watchdog SIGKILLs the agent's process group, which also covers
533
+ a real agent started by a launcher (Codex's npm wrapper on Node without `process.execve`) and
534
+ the agent's tool processes.
535
+ Limits: on non-Linux only the process group is cleaned and there is no lifeline. A process that
536
+ left the agent's group (`setsid`/daemonized) before AgentCap itself was SIGKILLed can still
537
+ escape: no userspace process can clean up after its own SIGKILL. Use a container/cgroup or a
538
+ separate OS user when the agent is not trusted. Adopted helpers that exit during a run stay
539
+ zombies until it ends (the agent's group is reaped once the agent exits, the rest by the final
540
+ sweep): `/proc` cannot tell an adopted `setsid` helper from a child AgentCap's own process
541
+ started in a new session, and taking that child's exit status would make it report 0. A long
542
+ run whose agent keeps leaving short-lived detached helpers holds one PID per finished helper,
543
+ counted against `ulimit -u`, until the run ends. Opt-in (0.3.1, default off):
544
+ `AGENTCAP_COLLECT_ZOMBIES=1` reaps, about once a second during the run, adopted zombies whose
545
+ session id is neither AgentCap's nor their own pid (an in-group background job, a double-forked
546
+ daemon), after re-checking their PID + start time. The agent, `setsid` helpers (session leaders)
547
+ and AgentCap's own children are never reaped early, so their exit codes are kept; `setsid`
548
+ helpers are still collected by the final sweep. Interrupting a job
549
+ can leave its work half done (a migration, a deploy): that is the job's responsibility, so
550
+ commit before a guarded run.
551
+ - **Fail-closed.** On Pro, quota and harness runs (`--quota`, `--tokens`, `--log-cap`) stop the
552
+ agent with exit code 5 instead of letting it run unguarded when opencode/agy output matches no
553
+ known log schema, the Codex session log becomes unreadable, or AgentCap itself hits an internal
554
+ error; Free only warns about these. In `--cap` mode an internal AgentCap error stops the agent
555
+ too, with exit code 5 and reason `internal_error` (since 0.3.1; see "Exit codes"). Two quota jobs at once are refused on Free and Pro (exit 2),
556
+ since the quota % is account-wide; `AGENTCAP_ALLOW_PARALLEL=1` turns that lock off.
557
+ Not covered yet: a stale Claude statusline (no fresh `rate_limits`) is reported, not stopped.
558
+ - **Rejected credentials (`--cap` proxy mode).** When the provider answers HTTP 401, 402
559
+ (OpenRouter: no credits), 403, or Gemini's 400 `API_KEY_INVALID`, AgentCap prints
560
+ `upstream rejected the request (HTTP 401: User not found.) — check the API key for <host>;
561
+ nothing was spent.` (the provider's short `error.message`, truncated, key-shaped text redacted,
562
+ headers never read). The agent's resends of such a request never count toward the loop breaker.
563
+ After 3 rejections in a row with no other answer between them, the run is stopped on Free and Pro
564
+ with reason `upstream_auth_failed` and exit 2 (like AgentCap's other exit-2 refusals: a setup
565
+ problem to fix, rerunning unchanged cannot help). 429/5xx answers in between neither count nor
566
+ break the streak, so 401/429/401/429/401 still stops. A 403 whose body is not about the key,
567
+ permission or account (a region/country block, a moderation or policy refusal, or no readable
568
+ body) is reported as `provider refused the request` instead, and three in a row stop the run with
569
+ reason `upstream_refused` (exit 2). If the agent gives up first with a non-zero exit code, the
570
+ reason is still `upstream_auth_failed`/`upstream_refused` and its own exit code is kept; if it
571
+ exits 0, the reason stays `child_exit` and the rejection is printed as a separate warning. One
572
+ rejection followed by a success changes nothing. `agentcap serve` only reports it and keeps serving.
573
+ - **Self-approval.** `agentcap approve` refuses (exit 2) when it runs inside an agent session
574
+ (`AGENTCAP_QUOTA_JOB`, `AGENTCAP_GUARDED` or `CLAUDECODE` in its environment), and the hook of
575
+ `agentcap run --quota -- claude` denies a Bash call that runs `agentcap approve`;
576
+ `/agentcap:approve` cannot be invoked by the model (`disable-model-invocation`). Run approve
577
+ from your own terminal. The Claude Code plugin's `PreToolUse` hook denies, on Free and Pro, any
578
+ model tool call that would run its own script (`python3 .../scripts/agentcap_cc.py approve`,
579
+ `quota`, `off`, `setup`, `unsetup`, `statusline`, `hook`; any path, `python -m agentcap_cc`,
580
+ `import agentcap_cc`, an `agentcap*` glob, quoted/escaped/`$IFS` forms, inside `bash -c`/`sh -c`)
581
+ or touch its state dir or installed plugin files: Bash and any other tool with a `command`, and
582
+ Write/Edit/MultiEdit/NotebookEdit on those paths. Plain reads (`cat`, `grep`, `ls`, `jq`, ...;
583
+ `git` without `-c`/config/checkout-style subcommands) still pass. Your own `/agentcap:approve`,
584
+ `/agentcap:quota` and `/agentcap:off` keep working: Claude Code runs a slash command's `!` line
585
+ without `PreToolUse` hooks (measured on 2.1.318, headless). When Claude Code's working
586
+ directory is inside the plugin's own checkout, its code files stay editable (plugin development).
587
+ What still passes: a command that never names the script or state dir (a script the agent
588
+ writes elsewhere that builds the path at run time, `$(printf ...)` path pieces, other globs),
589
+ and tools that execute code without a `command` field.
590
+ **Honest limit:** the agent runs as your OS user, so a determined agent can still clear the
591
+ environment, edit AgentCap's state files or kill AgentCap. AgentCap guards cooperative
592
+ workloads against accidents (loops, runaway spend), not a hostile agent; use a separate OS
593
+ user or container for that.
594
+ - **Log format changes.** AgentCap reads harness logs, and vendors change them. The fields it
595
+ reads are pinned per harness in `agentcap/logschema.py` (opencode, agy, Claude Code statusline
596
+ and PreToolUse, Codex rollout) and checked by `tests/test_log_contract.py` against recorded
597
+ fixtures; `AGENTCAP_LIVE_CONTRACT=1 pytest tests/test_log_contract_live.py` re-checks the
598
+ installed opencode/agy (one small model call). At run time an unknown schema fails closed
599
+ (above). Last live check: opencode 2.2.4 (3 Nov 2026).
600
+
454
601
  ## Privacy
455
602
 
456
603
  Prompts and keys pass through the local proxy in memory; AgentCap never stores
@@ -533,7 +680,7 @@ steps are noisy. No team aggregation: everything stays on your machine.
533
680
  When the Pro detectors below would have fired on a Free run, AgentCap does not stop it.
534
681
  It prints one line: `Pro's loop breaker would have stopped this at $X.XX`.
535
682
 
536
- **Pro, $12 one-time (launch week, until 10 Nov; then $19): stop runs that loop or eat your quota.**
683
+ **Pro, $12 one-time (launch week; $19 after): stop runs that loop or eat your quota.**
537
684
 
538
685
  **Get Pro:** buy at https://agentcap.launchbench.studio/#pricing (Polar checkout). Polar then
539
686
  emails you an **Access purchase** link; the key is in the Polar customer portal (not in the
@@ -562,7 +709,7 @@ The VS Code/Cursor extension and the Claude Code plugin use the same CLI licence
562
709
 
563
710
  ### Purchase terms
564
711
 
565
- - Pro is $12 one-time (launch week, until 10 Nov; then $19), no subscription.
712
+ - Pro is $12 one-time (launch week; $19 after), no subscription. The current launch-week end date is on the pricing page.
566
713
  - 14-day no-questions refund — email
567
714
  [kutaykarahan6@gmail.com](mailto:kutaykarahan6@gmail.com).
568
715
  - One licence key activates on up to 3 machines.
@@ -631,7 +778,7 @@ prices and reported usage; when usage is missing it charges the full reservation
631
778
  **Is the day cap shared across machines?** No. Hour/day caps are per machine
632
779
  (local SQLite ledger). A license covers 3 machines, each with its own budget.
633
780
 
634
- **What does one-time purchase include?** $12 once in launch week ($19 after 10 Nov), all 0.x updates; not a
781
+ **What does one-time purchase include?** $12 once in launch week ($19 after), all 0.x updates; not a
635
782
  promise of future major versions. 14-day refund window per purchase terms.
636
783
 
637
784
  ## License
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agentcap-cli"
7
- version = "0.2.1"
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."
7
+ version = "0.3.1"
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"
11
11
  license = "MIT"
@@ -56,9 +56,12 @@ Issues = "https://github.com/Blitz00X/agentcap/issues"
56
56
 
57
57
  [tool.hatch.build.targets.wheel]
58
58
  packages = ["src/agentcap"]
59
+ # agentcap.ops is an internal task/notification tracker, not part of the CLI.
60
+ exclude = ["src/agentcap/ops"]
59
61
 
60
62
  [tool.hatch.build.targets.sdist]
61
63
  include = ["src/agentcap", "tests", "README.md", "LICENSE", "pyproject.toml"]
64
+ exclude = ["src/agentcap/ops", "tests/test_ops_*.py", "tests/ops_support.py"]
62
65
 
63
66
  [tool.pytest.ini_options]
64
67
  testpaths = ["tests"]
@@ -2,6 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- __version__ = "0.2.1"
5
+ __version__ = "0.3.1"
6
6
 
7
7
  __all__ = ["__version__"]
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env python3
2
+ """Tiny exec shim that arms Linux ``PR_SET_PDEATHSIG`` before exec.
3
+
4
+ AgentCap spawns this file (not the agent directly) so the guarded process is
5
+ killed by the kernel if AgentCap itself dies, including a SIGKILL where no
6
+ Python cleanup can run. The shim only uses the standard library, then
7
+ ``execvp``s the real command so its PID, process group and environment are
8
+ unchanged.
9
+
10
+ Usage: ``python _lifeline_exec.py --parent PID [--errfd FD] -- COMMAND [ARGS...]``
11
+
12
+ With ``--errfd`` the shim reports an ``execvp`` failure as its errno on that
13
+ close-on-exec pipe instead of printing it, so AgentCap can raise the same
14
+ start failure ``subprocess.Popen`` raises for a command that cannot run.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import ctypes
20
+ import os
21
+ import signal
22
+ import sys
23
+
24
+ _PR_SET_PDEATHSIG = 1
25
+
26
+
27
+ def _arm_parent_death_signal() -> bool:
28
+ """Ask Linux to SIGKILL this process when its parent dies."""
29
+
30
+ try:
31
+ libc = ctypes.CDLL(None, use_errno=True)
32
+ return libc.prctl(_PR_SET_PDEATHSIG, signal.SIGKILL, 0, 0, 0) == 0
33
+ except (OSError, AttributeError):
34
+ return False
35
+
36
+
37
+ def _parse(argv: list[str]) -> tuple[int, int | None, list[str]] | None:
38
+ args = argv[1:]
39
+ try:
40
+ sep = args.index("--")
41
+ except ValueError:
42
+ return None
43
+ options, command = args[:sep], args[sep + 1:]
44
+ if not command or len(options) not in (2, 4) or options[0] != "--parent":
45
+ return None
46
+ if len(options) == 4 and options[2] != "--errfd":
47
+ return None
48
+ try:
49
+ parent = int(options[1])
50
+ errfd = int(options[3]) if len(options) == 4 else None
51
+ except ValueError:
52
+ return None
53
+ return parent, errfd, command
54
+
55
+
56
+ def main(argv: list[str]) -> int:
57
+ parsed = _parse(argv)
58
+ if parsed is None:
59
+ print("lifeline: bad arguments", file=sys.stderr)
60
+ return 2
61
+ parent, errfd, command = parsed
62
+ if errfd is not None:
63
+ try:
64
+ os.set_inheritable(errfd, False) # a successful exec closes it
65
+ except OSError:
66
+ print("lifeline: bad error pipe", file=sys.stderr)
67
+ return 2
68
+
69
+ if not _arm_parent_death_signal():
70
+ print("lifeline: could not arm PR_SET_PDEATHSIG; refusing to run unguarded",
71
+ file=sys.stderr)
72
+ return 5
73
+ # The parent may have died between fork/exec and prctl. In that case the
74
+ # kernel had nobody to signal, so check the reparented pid explicitly.
75
+ if os.getppid() != parent:
76
+ return 137
77
+ # Python ignores these at startup and exec keeps an ignored signal ignored.
78
+ # Undo it like subprocess's restore_signals does for a direct child, or the
79
+ # agent's pipelines (``producer | head -1``) would never get SIGPIPE.
80
+ for name in ("SIGPIPE", "SIGXFZ", "SIGXFSZ"):
81
+ number = getattr(signal, name, None)
82
+ if number is not None:
83
+ signal.signal(number, signal.SIG_DFL)
84
+ try:
85
+ os.execvp(command[0], command)
86
+ except OSError as exc:
87
+ if errfd is not None:
88
+ try:
89
+ os.write(errfd, str(exc.errno or 0).encode("ascii"))
90
+ except OSError:
91
+ pass
92
+ else:
93
+ print(f"lifeline: cannot exec {command[0]!r}: {exc.strerror or exc}", file=sys.stderr)
94
+ return 127
95
+ return 0 # pragma: no cover - execvp never returns
96
+
97
+
98
+ if __name__ == "__main__":
99
+ raise SystemExit(main(sys.argv))