@tigorhutasuhut/herdr-claude-retry 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tigor Hutasuhut
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# herdr-claude-retry
|
|
2
|
+
|
|
3
|
+
Watches Claude CLI panes running inside [herdr](https://herdr.dev/). When a pane hits Anthropic's
|
|
4
|
+
usage/session limit, it detects the on-screen rate-limit banner, cross-checks against Anthropic's
|
|
5
|
+
usage API to get the exact reset time, and injects `continue` automatically once the limit clears.
|
|
6
|
+
Zero polling — event-driven via herdr's socket API.
|
|
7
|
+
|
|
8
|
+
## Requirements
|
|
9
|
+
|
|
10
|
+
- Node.js >= 20
|
|
11
|
+
- herdr >= 0.7 (provides the UNIX socket API and `HERDR_SOCKET_PATH` env var)
|
|
12
|
+
- Claude Code running inside a herdr-managed pane
|
|
13
|
+
- A logged-in Claude Code installation with `<CLAUDE_CONFIG_DIR>/.credentials.json` (for usage-API
|
|
14
|
+
detection; without it the daemon degrades gracefully to on-screen text parsing)
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @tigorhutasuhut/herdr-claude-retry
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The installed command is `herdr`.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Run as a foreground daemon in its own herdr pane (the daemon excludes its own pane from monitoring):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
herdr start
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
| Flag | Default | Description |
|
|
35
|
+
|------|---------|-------------|
|
|
36
|
+
| `--socket <path>` | `$HERDR_SOCKET_PATH` or `~/.config/herdr/herdr.sock` | herdr socket path |
|
|
37
|
+
| `--margin-seconds <n>` | `60` | Extra seconds to wait after reset time before injecting |
|
|
38
|
+
| `--sweep-interval-ms <n>` | `300000` | Reconcile sweep interval (ms) |
|
|
39
|
+
|
|
40
|
+
### What it watches
|
|
41
|
+
|
|
42
|
+
Every pane herdr knows about — current and future. New panes are picked up automatically via
|
|
43
|
+
herdr's `pane.created` event subscription. The daemon skips its own pane.
|
|
44
|
+
|
|
45
|
+
## How it works
|
|
46
|
+
|
|
47
|
+
The daemon runs two concurrent loops:
|
|
48
|
+
|
|
49
|
+
1. **Event loop** — subscribes to `pane.output_matched` (regex: rate-limit phrases) and
|
|
50
|
+
`pane.agent_status_changed` on all known panes. When herdr fires a match, the pane is
|
|
51
|
+
immediately checked.
|
|
52
|
+
|
|
53
|
+
2. **Reconcile sweep** — runs on startup and every `--sweep-interval-ms`. Walks all live panes
|
|
54
|
+
via `agent.list`, prunes gone panes, checks any not already in an active state. Catches panes
|
|
55
|
+
the event loop might miss (reconnects, races).
|
|
56
|
+
|
|
57
|
+
**Per-pane state machine:**
|
|
58
|
+
|
|
59
|
+
- **MONITORING** — no banner, idle. On banner detected:
|
|
60
|
+
- Account **LIMITED** via usage API → enter WAITING until `resets_at`.
|
|
61
|
+
- Account **CLEARED** or **UNKNOWN** (API down) → parse reset from on-screen text:
|
|
62
|
+
- Future reset → enter WAITING.
|
|
63
|
+
- Already-past reset + canonical banner at screen bottom → inject `continue` immediately
|
|
64
|
+
(text-fallback path).
|
|
65
|
+
- **WAITING** — banner gone (pane exited/user resumed) → drop back to MONITORING. Account
|
|
66
|
+
cleared or timer elapsed → inject `continue`.
|
|
67
|
+
|
|
68
|
+
**Inject sequence:** `Ctrl+C` (clears partial input) → `continue` + Enter via `pane.send_text`.
|
|
69
|
+
|
|
70
|
+
**Account resolution (Linux):** reads `CLAUDE_CONFIG_DIR` from the Claude process's `/proc`
|
|
71
|
+
environment, falls back to session UUID → config dir scan, then default `~/.claude`. On non-Linux
|
|
72
|
+
or when resolution fails, usage=null → text-fallback path.
|
|
73
|
+
|
|
74
|
+
## Development
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm install
|
|
78
|
+
npm run typecheck # tsc --noEmit
|
|
79
|
+
npm test # node --test (unit tests, no live herdr needed)
|
|
80
|
+
npm run build # tsc -> dist/
|
|
81
|
+
npm run verify # typecheck + test + build (publish gate)
|
|
82
|
+
npm run e2e # acceptance test — needs live herdr
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The e2e test (`test/e2e/blocked-pane.e2e.ts`) creates a temporary herdr workspace, sends a
|
|
86
|
+
rate-limit banner to its root pane, runs the daemon against it, and asserts the daemon detects the
|
|
87
|
+
banner. It skips gracefully if no herdr socket is found.
|
|
88
|
+
|
|
89
|
+
## Publishing
|
|
90
|
+
|
|
91
|
+
Releases are published to npm by GitHub Actions
|
|
92
|
+
([.github/workflows/publish.yml](.github/workflows/publish.yml)) on `push` to a `v*` tag.
|
|
93
|
+
Auth uses npm [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) (OIDC) — no
|
|
94
|
+
`NPM_TOKEN` secret — and [provenance](https://docs.npmjs.com/generating-provenance-statements)
|
|
95
|
+
is attached automatically.
|
|
96
|
+
|
|
97
|
+
> `npm publish` is a manual human step — the workflow runs on a tagged release you create.
|
|
98
|
+
|
|
99
|
+
### One-time setup
|
|
100
|
+
|
|
101
|
+
1. **Bootstrap the package** (trusted publishing can only be configured on an existing package).
|
|
102
|
+
Publish `0.1.0` once from your machine:
|
|
103
|
+
```bash
|
|
104
|
+
npm login
|
|
105
|
+
npm run verify
|
|
106
|
+
npm publish --provenance=false
|
|
107
|
+
```
|
|
108
|
+
`--provenance=false` is required for local bootstrap: provenance requires OIDC from CI.
|
|
109
|
+
2. **Configure trusted publisher** on npmjs.com: package → **Settings → Trusted Publisher →
|
|
110
|
+
GitHub Actions**:
|
|
111
|
+
- Organization or user: `tigorhutasuhut`
|
|
112
|
+
- Repository: `herdr-claude-retry`
|
|
113
|
+
- Workflow filename: `publish.yml`
|
|
114
|
+
|
|
115
|
+
### Cutting a release
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm version patch # bump version + create git tag
|
|
119
|
+
git push --follow-tags
|
|
120
|
+
# workflow triggers on the v* tag push
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The workflow runs `npm ci` → `npm run verify` → `npm publish --provenance`. `prepublishOnly`
|
|
124
|
+
gates the publish on a clean typecheck, test, and build.
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tigorhutasuhut/herdr-claude-retry",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Herdr daemon — monitor Claude CLI sessions and auto-retry on rate-limit and errors",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Tigor Hutasuhut <tigor.hutasuhut@gmail.com>",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*.js",
|
|
13
|
+
"dist/**/*.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"herdr": "dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"provenance": true
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "node --test 'test/**/*.test.ts'",
|
|
26
|
+
"e2e": "node --test 'test/e2e/*.e2e.ts'",
|
|
27
|
+
"verify": "npm run typecheck && npm test && npm run build",
|
|
28
|
+
"prepublishOnly": "npm run verify"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "25.9.1",
|
|
32
|
+
"typescript": "^5.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|