harnex 0.2.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/GUIDE.md +242 -0
  3. data/LICENSE +21 -0
  4. data/README.md +119 -0
  5. data/TECHNICAL.md +595 -0
  6. data/bin/harnex +18 -0
  7. data/lib/harnex/adapters/base.rb +134 -0
  8. data/lib/harnex/adapters/claude.rb +105 -0
  9. data/lib/harnex/adapters/codex.rb +112 -0
  10. data/lib/harnex/adapters/generic.rb +14 -0
  11. data/lib/harnex/adapters.rb +32 -0
  12. data/lib/harnex/cli.rb +115 -0
  13. data/lib/harnex/commands/guide.rb +23 -0
  14. data/lib/harnex/commands/logs.rb +184 -0
  15. data/lib/harnex/commands/pane.rb +251 -0
  16. data/lib/harnex/commands/recipes.rb +104 -0
  17. data/lib/harnex/commands/run.rb +384 -0
  18. data/lib/harnex/commands/send.rb +415 -0
  19. data/lib/harnex/commands/skills.rb +163 -0
  20. data/lib/harnex/commands/status.rb +171 -0
  21. data/lib/harnex/commands/stop.rb +127 -0
  22. data/lib/harnex/commands/wait.rb +165 -0
  23. data/lib/harnex/core.rb +286 -0
  24. data/lib/harnex/runtime/api_server.rb +187 -0
  25. data/lib/harnex/runtime/file_change_hook.rb +111 -0
  26. data/lib/harnex/runtime/inbox.rb +207 -0
  27. data/lib/harnex/runtime/message.rb +23 -0
  28. data/lib/harnex/runtime/session.rb +380 -0
  29. data/lib/harnex/runtime/session_state.rb +55 -0
  30. data/lib/harnex/version.rb +3 -0
  31. data/lib/harnex/watcher/inotify.rb +43 -0
  32. data/lib/harnex/watcher/polling.rb +92 -0
  33. data/lib/harnex/watcher.rb +24 -0
  34. data/lib/harnex.rb +25 -0
  35. data/recipes/01_fire_and_watch.md +82 -0
  36. data/recipes/02_chain_implement.md +115 -0
  37. data/skills/chain-implement/SKILL.md +234 -0
  38. data/skills/close/SKILL.md +47 -0
  39. data/skills/dispatch/SKILL.md +171 -0
  40. data/skills/harnex/SKILL.md +304 -0
  41. data/skills/open/SKILL.md +32 -0
  42. metadata +88 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 814a587579199179b2b9fcd64b512c45c60ce06904834b9b7caac62e193b9306
4
+ data.tar.gz: 6f16ba96dc5e7dfb2fd08d99908b1a1dad4d373c0e47a395a1f3e1a62edb0705
5
+ SHA512:
6
+ metadata.gz: f61b445033ab07d79b42695c91089d07a3050cb0cf9a51c8c6ef46259bf22bc48f7a5867332ac1609f09ae0a1dc28b9484ae8a0fee2cc85941e69b17ced30c84
7
+ data.tar.gz: 7f502e09fd03fd6608fbd81fee346aa0ecaeea15e908b0a5114f38a0c4c5fb45ac4d3f327f106a45c6aac69a69de9684686bb9a054b32c6f626068b2fabbcdb3
data/GUIDE.md ADDED
@@ -0,0 +1,242 @@
1
+ # Getting Started with Harnex
2
+
3
+ You've installed harnex. Here's how to actually use it.
4
+
5
+ ## Recommended mental model
6
+
7
+ Treat harnex as a local supervisor harness, not as a conversation
8
+ bus between agents.
9
+
10
+ - Start a fresh worker for each step, usually with `--tmux`
11
+ - Send one clear task, often by pointing the worker at a file
12
+ - Use `--wait-for-idle` as a fence, then inspect with `harnex pane`
13
+ - Ask the worker to write its output to a file when the next step
14
+ needs structured input
15
+ - Stop the worker when that step is done
16
+
17
+ For multi-step flows, chain fresh workers with file handoffs:
18
+ Codex writes a plan, another Codex implements it, Claude reviews it,
19
+ another Codex fixes it.
20
+
21
+ ## Your first session
22
+
23
+ Start an agent the way you normally would, but through harnex:
24
+
25
+ ```bash
26
+ harnex run codex
27
+ ```
28
+
29
+ The agent looks and works exactly the same. Harnex runs alongside
30
+ it — registering the session, listening for messages, and tracking
31
+ whether the agent is busy or idle.
32
+
33
+ Give it a name so other sessions can find it:
34
+
35
+ ```bash
36
+ harnex run codex --id worker
37
+ ```
38
+
39
+ ## Sending messages
40
+
41
+ From another terminal:
42
+
43
+ ```bash
44
+ harnex send --id worker --message "implement the auth module"
45
+ ```
46
+
47
+ If the agent is busy, the message queues and delivers
48
+ automatically when the agent is ready. You don't have to wait
49
+ or retry. Queueing exists, but the default workflow should still be
50
+ one task per fresh worker.
51
+
52
+ ## Seeing what's running
53
+
54
+ ```bash
55
+ harnex status
56
+ ```
57
+
58
+ Shows all live sessions for the current repo with their ID, CLI
59
+ type, age, and state (prompt/busy).
60
+
61
+ ## Running agents in tmux
62
+
63
+ This is the recommended way to run multiple agents. Each one gets
64
+ its own tmux window you can switch to anytime:
65
+
66
+ ```bash
67
+ harnex run codex --id impl --tmux
68
+ harnex run claude --id review --tmux
69
+ ```
70
+
71
+ Switch between them with your normal tmux keys (`Ctrl-b n`,
72
+ `Ctrl-b p`, or `Ctrl-b w` to pick from a list). This is the
73
+ easiest way to monitor what each agent is doing — you see exactly
74
+ what you'd see if you were running it directly.
75
+
76
+ For longer-running work, `harnex pane` lets you peek at an
77
+ agent's screen without switching windows:
78
+
79
+ ```bash
80
+ harnex pane --id impl --lines 30
81
+ ```
82
+
83
+ Or watch it live from your current terminal:
84
+
85
+ ```bash
86
+ harnex pane --id impl --follow
87
+ ```
88
+
89
+ ## Sending work and waiting for it to finish
90
+
91
+ Use `--wait-for-idle` to block until the agent finishes
92
+ processing:
93
+
94
+ ```bash
95
+ harnex send --id impl --message "implement the plan" --wait-for-idle --timeout 600
96
+ ```
97
+
98
+ This is better than separate send + wait commands because there's
99
+ no gap where you might check too early and think the agent is
100
+ done when it hasn't started yet.
101
+
102
+ Treat `--wait-for-idle` as the fence, not the report. After the
103
+ send returns, use `harnex pane` or `harnex logs` to inspect what
104
+ actually happened.
105
+
106
+ ## Sending large prompts
107
+
108
+ PTY buffers and shell quoting don't love multi-kilobyte inline
109
+ messages. For anything longer than a few sentences, write the
110
+ task to a file and tell the agent to read it:
111
+
112
+ ```bash
113
+ cat > /tmp/task-impl.md <<'EOF'
114
+ Implement phase 2 from koder/plans/03_output_streaming.md.
115
+
116
+ Focus on:
117
+ - The HTTP endpoint for streaming output
118
+ - Integration with the existing ring buffer
119
+ - Tests for the new endpoint
120
+
121
+ Do not modify the CLI commands.
122
+ EOF
123
+
124
+ harnex send --id impl --message "Read and execute /tmp/task-impl.md"
125
+ ```
126
+
127
+ If the task is already written down — a plan file, an issue, a
128
+ spec — just point to it:
129
+
130
+ ```bash
131
+ harnex send --id impl --message "Implement koder/plans/plan_09_atomic_send_wait.md"
132
+ ```
133
+
134
+ This is more reliable, easier to debug (you can read the file to
135
+ see exactly what was sent), and avoids quoting headaches.
136
+
137
+ ## Capturing results
138
+
139
+ For dependable multi-step work, prefer file handoffs over reply
140
+ messages.
141
+
142
+ Examples:
143
+
144
+ ```bash
145
+ # Planning
146
+ harnex send --id plan --message "Read koder/issues/13_atomic_send_wait.md and write a plan to /tmp/plan-13.md. Do not change code." --wait-for-idle --timeout 600
147
+
148
+ # Review
149
+ harnex send --id review --message "Review the current changes against /tmp/plan-13.md and write findings to /tmp/review-13.md. If clean, say so explicitly." --wait-for-idle --timeout 600
150
+ ```
151
+
152
+ Why files work better:
153
+
154
+ - The next worker can read exactly the same artifact you reviewed
155
+ - The supervisor can inspect the artifact without scraping terminal text
156
+ - If the session dies, the output still exists
157
+
158
+ After the worker finishes, inspect the screen:
159
+
160
+ ```bash
161
+ harnex pane --id review --lines 60
162
+ ```
163
+
164
+ Optional: if you're inside a harnex-managed session yourself and
165
+ really want a callback, you can still use `$HARNEX_ID` as the return
166
+ address. Treat that as secondary, not the main control flow.
167
+
168
+ ## Stopping agents
169
+
170
+ ```bash
171
+ harnex stop --id impl
172
+ ```
173
+
174
+ This sends the agent's native exit sequence (e.g. `/exit` for
175
+ Codex). The agent shuts down cleanly.
176
+
177
+ ## A reliable supervised workflow
178
+
179
+ Use fresh instances for each stage. Codex plans and implements.
180
+ Claude only reviews.
181
+
182
+ ```bash
183
+ # 1. Plan with Codex
184
+ harnex run codex --id cx-plan-13 --tmux
185
+ harnex send --id cx-plan-13 --message "Read koder/issues/13_atomic_send_wait.md and write a concrete implementation plan to /tmp/plan-13.md. Do not change code." --wait-for-idle --timeout 600
186
+ harnex pane --id cx-plan-13 --lines 60
187
+ harnex stop --id cx-plan-13
188
+
189
+ # 2. Implement with a fresh Codex
190
+ harnex run codex --id cx-impl-13 --tmux
191
+ harnex send --id cx-impl-13 --message "Read /tmp/plan-13.md, implement it, run tests, and write a short summary to /tmp/impl-13.md." --wait-for-idle --timeout 1200
192
+ harnex pane --id cx-impl-13 --lines 80
193
+ harnex stop --id cx-impl-13
194
+
195
+ # 3. Review with a fresh Claude
196
+ harnex run claude --id cl-rev-13 --tmux
197
+ harnex send --id cl-rev-13 --message "Review the current changes against /tmp/plan-13.md. Write findings to /tmp/review-13.md. If there are no issues, say clean." --wait-for-idle --timeout 900
198
+ harnex pane --id cl-rev-13 --lines 80
199
+ harnex stop --id cl-rev-13
200
+ ```
201
+
202
+ If the review finds issues, spawn another fresh Codex worker and tell
203
+ it to read `/tmp/review-13.md`, fix the findings, run tests, and write
204
+ an updated summary. Then review again with a fresh Claude instance.
205
+
206
+ ## Teaching your agents about harnex
207
+
208
+ Harnex ships a skill file that tells AI agents how to use harnex
209
+ commands. To make it available globally:
210
+
211
+ ```bash
212
+ # For Claude Code
213
+ ln -s /path/to/harnex/skills/harnex ~/.claude/skills/harnex
214
+
215
+ # For Codex
216
+ ln -s /path/to/harnex/skills/harnex ~/.codex/skills/harnex
217
+ ```
218
+
219
+ After this, any Claude or Codex session — in any repo — can use
220
+ harnex commands without being taught how. The skill activates
221
+ automatically when agent collaboration is needed.
222
+
223
+ ## Recipes
224
+
225
+ Tested workflows for common multi-agent patterns. Read them
226
+ from the CLI:
227
+
228
+ ```bash
229
+ harnex recipes # list all recipes
230
+ harnex recipes show 01 # read one
231
+ ```
232
+
233
+ - **Fire and Watch** (`harnex recipes show 01`) — send work to a
234
+ fresh worker, watch its tmux screen, capture the result, stop it.
235
+ - **Chain Implement** (`harnex recipes show 02`) — process a
236
+ batch as repeated fire-and-watch: Codex plan/implement,
237
+ Claude review, Codex fix, then review again if needed.
238
+
239
+ ## What's next
240
+
241
+ For the full command reference, flags, HTTP API, and internals,
242
+ see [TECHNICAL.md](TECHNICAL.md).
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jikku Jose
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.
data/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # Harnex
2
+
3
+ Run multiple AI coding agents from your terminal and coordinate them.
4
+
5
+ Harnex wraps Claude Code and OpenAI Codex (or any terminal CLI) in a
6
+ local harness so you can launch agents, send them tasks, watch their
7
+ screens, and stop them cleanly — all from the command line.
8
+
9
+ ```bash
10
+ gem install harnex
11
+ ```
12
+
13
+ Requires **Ruby 3.x**. No other dependencies.
14
+
15
+ ## What it does
16
+
17
+ ```bash
18
+ # Start an agent in tmux
19
+ harnex run codex --id planner --tmux
20
+
21
+ # Send it a task and wait for it to finish
22
+ harnex send --id planner --message "Write a plan to /tmp/plan.md" --wait-for-idle
23
+
24
+ # Peek at what it's doing
25
+ harnex pane --id planner --lines 30
26
+
27
+ # Stop it
28
+ harnex stop --id planner
29
+ ```
30
+
31
+ That's the core loop. Start a fresh agent for each step, hand it one
32
+ job, watch it work, stop it when done.
33
+
34
+ ## Why use this
35
+
36
+ - **You want agents to plan, implement, review, and fix — in sequence.**
37
+ Codex writes code. Claude reviews it. Another Codex fixes the review
38
+ findings. Each step is a fresh agent with clean context.
39
+
40
+ - **You want to see what agents are doing.** `harnex pane` shows
41
+ the agent's live terminal. No black boxes.
42
+
43
+ - **You don't want to babysit.** Send a task with `--wait-for-idle`,
44
+ walk away, check back when it's done.
45
+
46
+ - **You want local-only orchestration.** Everything runs on your
47
+ machine. No cloud services, no API keys beyond what the agents need.
48
+
49
+ ## When you wouldn't use this
50
+
51
+ - You only use one agent at a time (just run it directly)
52
+ - You need cloud-hosted orchestration
53
+ - Your agents aren't terminal-based
54
+
55
+ ## Supported agents
56
+
57
+ | Agent | Support |
58
+ |-------|---------|
59
+ | Claude Code | Full (prompt detection, stop sequence, vim mode) |
60
+ | OpenAI Codex | Full (prompt detection, stop sequence) |
61
+ | Any terminal CLI | Generic wrapping (everything works except smart prompt detection) |
62
+
63
+ ## Multi-agent workflows
64
+
65
+ The real power is chaining agents together:
66
+
67
+ ```bash
68
+ # 1. Codex writes a plan
69
+ harnex run codex --id cx-plan --tmux
70
+ harnex send --id cx-plan --message "Plan the auth module, write to /tmp/plan.md" --wait-for-idle
71
+ harnex stop --id cx-plan
72
+
73
+ # 2. Fresh Codex implements the plan
74
+ harnex run codex --id cx-impl --tmux
75
+ harnex send --id cx-impl --message "Implement /tmp/plan.md, run tests" --wait-for-idle
76
+ harnex stop --id cx-impl
77
+
78
+ # 3. Claude reviews the implementation
79
+ harnex run claude --id cl-review --tmux
80
+ harnex send --id cl-review --message "Review changes against /tmp/plan.md, write /tmp/review.md" --wait-for-idle
81
+ harnex stop --id cl-review
82
+ ```
83
+
84
+ Harnex ships workflow skills that automate this pattern:
85
+
86
+ - **[Dispatch](skills/dispatch/SKILL.md)** — the fire-and-watch pattern:
87
+ spawn an agent, poll its screen, stop it when done
88
+ - **[Chain Implement](skills/chain-implement/SKILL.md)** — end-to-end
89
+ issue-to-code workflow: plan, review plan, implement, review code, fix
90
+
91
+ Install skills into your repo so agents can use them:
92
+
93
+ ```bash
94
+ harnex skills install dispatch chain-implement
95
+ ```
96
+
97
+ ## All commands
98
+
99
+ | Command | What it does |
100
+ |---------|-------------|
101
+ | `harnex run <cli>` | Start an agent (`--tmux` for a visible window, `--detach` for background) |
102
+ | `harnex send --id <id>` | Send a message (queues if busy, `--wait-for-idle` to block until done) |
103
+ | `harnex stop --id <id>` | Send the agent's native exit sequence |
104
+ | `harnex status` | List running sessions (`--json` for full payloads) |
105
+ | `harnex pane --id <id>` | Capture the agent's tmux screen (`--follow` for live) |
106
+ | `harnex logs --id <id>` | Read session transcript (`--follow` to tail) |
107
+ | `harnex wait --id <id>` | Block until exit or a target state |
108
+ | `harnex guide` | Getting started walkthrough |
109
+ | `harnex recipes` | Tested workflow patterns |
110
+ | `harnex skills install` | Install bundled skills for Claude/Codex |
111
+
112
+ ## Going deeper
113
+
114
+ - [GUIDE.md](GUIDE.md) — getting started walkthrough with examples
115
+ - [TECHNICAL.md](TECHNICAL.md) — full command reference, flags, HTTP API, architecture
116
+
117
+ ## License
118
+
119
+ [MIT](LICENSE)