captain-barbossa 0.13.0__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 (33) hide show
  1. captain_barbossa-0.13.0/LICENSE +21 -0
  2. captain_barbossa-0.13.0/PKG-INFO +359 -0
  3. captain_barbossa-0.13.0/README.md +346 -0
  4. captain_barbossa-0.13.0/pyproject.toml +42 -0
  5. captain_barbossa-0.13.0/setup.cfg +4 -0
  6. captain_barbossa-0.13.0/src/captain_barbossa/__init__.py +5 -0
  7. captain_barbossa-0.13.0/src/captain_barbossa/__main__.py +5 -0
  8. captain_barbossa-0.13.0/src/captain_barbossa/agents.py +982 -0
  9. captain_barbossa-0.13.0/src/captain_barbossa/cli.py +133 -0
  10. captain_barbossa-0.13.0/src/captain_barbossa/layout.py +99 -0
  11. captain_barbossa-0.13.0/src/captain_barbossa/memory.py +543 -0
  12. captain_barbossa-0.13.0/src/captain_barbossa/models.py +82 -0
  13. captain_barbossa-0.13.0/src/captain_barbossa/prompts.py +76 -0
  14. captain_barbossa-0.13.0/src/captain_barbossa/runtime.py +59 -0
  15. captain_barbossa-0.13.0/src/captain_barbossa.egg-info/PKG-INFO +359 -0
  16. captain_barbossa-0.13.0/src/captain_barbossa.egg-info/SOURCES.txt +31 -0
  17. captain_barbossa-0.13.0/src/captain_barbossa.egg-info/dependency_links.txt +1 -0
  18. captain_barbossa-0.13.0/src/captain_barbossa.egg-info/entry_points.txt +2 -0
  19. captain_barbossa-0.13.0/src/captain_barbossa.egg-info/requires.txt +1 -0
  20. captain_barbossa-0.13.0/src/captain_barbossa.egg-info/top_level.txt +1 -0
  21. captain_barbossa-0.13.0/tests/test_captain.py +2483 -0
  22. captain_barbossa-0.13.0/tests/test_child_memory_roots.py +117 -0
  23. captain_barbossa-0.13.0/tests/test_instruction_size.py +70 -0
  24. captain_barbossa-0.13.0/tests/test_launcher_cleanup.py +66 -0
  25. captain_barbossa-0.13.0/tests/test_memory_hygiene.py +181 -0
  26. captain_barbossa-0.13.0/tests/test_memory_roots.py +151 -0
  27. captain_barbossa-0.13.0/tests/test_memory_show_bound.py +130 -0
  28. captain_barbossa-0.13.0/tests/test_model_switch.py +163 -0
  29. captain_barbossa-0.13.0/tests/test_model_tiers.py +51 -0
  30. captain_barbossa-0.13.0/tests/test_prompts.py +128 -0
  31. captain_barbossa-0.13.0/tests/test_prune.py +248 -0
  32. captain_barbossa-0.13.0/tests/test_short_labels.py +190 -0
  33. captain_barbossa-0.13.0/tests/test_wait_memory.py +320 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Preetam
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.
@@ -0,0 +1,359 @@
1
+ Metadata-Version: 2.4
2
+ Name: captain-barbossa
3
+ Version: 0.13.0
4
+ Summary: Launch a native captain and crew inside a Herdr workspace
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/dev-preetamraj/captain-barbossa
7
+ Project-URL: Issues, https://github.com/dev-preetamraj/captain-barbossa/issues
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: questionary<3,>=2.1
12
+ Dynamic: license-file
13
+
14
+ # Captain Barbossa
15
+
16
+ [![CI](https://github.com/dev-preetamraj/captain-barbossa/actions/workflows/ci.yml/badge.svg)](https://github.com/dev-preetamraj/captain-barbossa/actions/workflows/ci.yml)
17
+
18
+ Captain Barbossa launches a native agent CLI (Claude Code or Codex) as a
19
+ **captain** inside a [Herdr](https://herdr.dev) workspace. The captain recruits
20
+ further native agents as **crew** in new Herdr panes or tabs, so a team of
21
+ native agent sessions can work on the same checkout at once. There is no
22
+ daemon, custom UI, or tmux layer: everything runs through Herdr, plus a small
23
+ graph memory stored outside the repo.
24
+
25
+ ## Requirements
26
+
27
+ - macOS or Linux, Python 3.11+
28
+ - Git
29
+ - [uv](https://docs.astral.sh/uv/getting-started/installation/)
30
+ - [Herdr](https://herdr.dev/docs/cli-reference/), as your terminal workspace
31
+ - Claude Code and/or Codex, installed and already signed in
32
+
33
+ ## Install
34
+
35
+ No manual clone is needed; uv downloads the package and installs its
36
+ dependencies in an isolated environment.
37
+
38
+ ```sh
39
+ uv tool install git+https://github.com/dev-preetamraj/captain-barbossa.git
40
+ ```
41
+
42
+ If your shell cannot find `captain` afterward, run `uv tool update-shell` and
43
+ restart the terminal.
44
+
45
+ ## Upgrade
46
+
47
+ ```sh
48
+ uv tool upgrade captain-barbossa
49
+ ```
50
+
51
+ `captain --version` prints the installed version. uv re-resolves the Git
52
+ source recorded at install time and installs the latest commit on the default
53
+ branch, even when the version number has not changed.
54
+ `uv tool install --force git+https://github.com/dev-preetamraj/captain-barbossa.git`
55
+ does the same. Running captains keep the old code until restarted with
56
+ `captain --session <session-id>`.
57
+
58
+ ## Starting a captain
59
+
60
+ Launch `captain` from an interactive terminal inside a Herdr workspace:
61
+
62
+ ```sh
63
+ captain # asks: Claude Code or Codex?
64
+ captain --agent claude # Claude Code in this pane
65
+ captain --agent codex # Codex in this pane
66
+ captain --prompt "Inspect this project"
67
+ ```
68
+
69
+ It renames the current tab to **Captain Barbossa** and replaces itself with
70
+ the chosen native CLI, so native input, history, permissions, and login all
71
+ stay with that agent.
72
+
73
+ ## Recruiting crew
74
+
75
+ Ask the captain to spin up a crew in plain language; its startup instructions
76
+ carry a recruiting ruleset. When you state no preference it recruits with no
77
+ questions, using:
78
+
79
+ - **agent**: the CLI the captain itself runs as
80
+ - **placement**: a pane split picked from the tab layout (auto), or a new tab
81
+ when crowded
82
+ - **model**: a tier picked from the task (see below)
83
+
84
+ Every choice you do state is used as given; the captain asks at most one
85
+ question, and only when you hand a choice back to it ("ask me where to put
86
+ it") or name one too vaguely to map to a flag. Only the captain recruits;
87
+ crew forward any delegation request back to the captain instead of spawning
88
+ their own.
89
+
90
+ You can also run the command directly from a shell attached to the captain's
91
+ session:
92
+
93
+ ```sh
94
+ captain crew --task "Review the current changes"
95
+ captain crew gibbs --task "Review the current changes" # request a specific name
96
+ ```
97
+
98
+ **Names.** Every crew gets a one-word Pirates of the Caribbean name: Jack,
99
+ Will, Elizabeth, Gibbs, Anamaria, Pintel, Ragetti, Cotton, Marty, Tia, Davy, or
100
+ Sao, assigned in that order and skipping names already in use. Dismissing
101
+ crew frees the name for reuse, so the next recruit takes the lowest free
102
+ roster name again. Once every name is taken, numbering starts at Jack-2.
103
+ Barbossa is reserved for the captain. The same name is used everywhere: the
104
+ crew ID, the pane/tab label, and the name in memory, `wait`, `focus`,
105
+ `model`, and `dismiss`.
106
+
107
+ **Placement.** `--placement pane|tab`, and for a pane, `--direction
108
+ vertical|horizontal|auto` with `--split-pane <pane-id>|auto`. `auto` searches
109
+ existing crew tabs (current tab first) for the split that leaves both halves
110
+ largest and squarest on screen, at least 60 columns by 15 rows. Ties favor
111
+ panes without crew, then panes nearest the captain; splitting the captain's
112
+ own pane ranks last. When nothing fits, the crew opens in a new tab instead.
113
+ The chosen pane, direction, and a one-line reason are printed and recorded in
114
+ memory.
115
+
116
+ **Model tiers.** `--model` takes a provider-neutral tier or free text:
117
+
118
+ | Tier | Claude Code | Codex |
119
+ |----------|-------------------|-----------------------|
120
+ | `cheap` | claude-haiku-4-5 | gpt-5.3-codex-spark |
121
+ | `mid` | claude-sonnet-5 | gpt-5.6-terra |
122
+ | `strong` | claude-opus-5 | gpt-6-astra |
123
+
124
+ The captain picks a tier from the task: `cheap` for mechanical edits,
125
+ renames, formatting, and docs; `mid` for normal features, tests, and work
126
+ inside one area; `strong` for design, debugging, multi-file changes, or
127
+ long-context reads. Free text also works and is matched to the closest model
128
+ the chosen CLI offers (exact IDs and aliases first, then prefixes,
129
+ substrings, and close spellings): Claude Code additionally offers
130
+ `claude-fable-5-1` (fable); Codex additionally offers `gpt-5.4-mini` (mini),
131
+ `gpt-5.6-luna` (luna), `gpt-5.6-sol` (sol), and `gpt-5.5`. Ambiguous or
132
+ unknown text reports the options and creates nothing. Without `--model`, the
133
+ CLI's own default applies.
134
+
135
+ New crew panes/tabs open in the same workspace and project without stealing
136
+ focus. Captain waits for the native agent to hold an idle state across
137
+ consecutive polls before naming it and submitting its task, since a freshly
138
+ drawn TUI silently drops a submitted prompt. A task that never starts, or an
139
+ agent waiting for approval, preserves the pane for inspection and reports an
140
+ error naming the `herdr agent prompt` command to send the task by hand;
141
+ nothing is retried automatically beyond one resend.
142
+
143
+ Crew share the checkout; see [Editing guardrails](#editing-guardrails) below.
144
+
145
+ ## Waiting for crew to finish
146
+
147
+ ```sh
148
+ captain wait Jack
149
+ captain wait Jack --timeout 300
150
+ ```
151
+
152
+ Polls Herdr until the crew settles at idle (across consecutive polls, so a
153
+ pause between tools isn't mistaken for the end), or reports done or blocked.
154
+ Records a `completed` entry in memory with the final status and the crew's
155
+ own report, falling back to the tail of its pane when it recorded none, and
156
+ prints the same. A crew still working when the timeout (900s by default)
157
+ expires records nothing and reports an error; wait again, or read its pane
158
+ directly with `herdr agent read <name>`.
159
+
160
+ ## Focusing crew
161
+
162
+ Tell the captain "focus on Jack", "switch to Will", or "take me to
163
+ Elizabeth", or run the command directly:
164
+
165
+ ```sh
166
+ captain focus Jack
167
+ ```
168
+
169
+ Names are case-insensitive; crew IDs and Herdr agent names also work.
170
+ Focusing switches to the crew's tab first when it differs from the captain's,
171
+ follows the registered agent if its pane has moved, and never sends input or
172
+ interrupts its work. An unknown or ambiguous name reports the available
173
+ choices.
174
+
175
+ ## Switching a running crew's model
176
+
177
+ Ask the captain to step a crew up or down a tier when its model stops fitting
178
+ the work, or run the command directly:
179
+
180
+ ```sh
181
+ captain model Jack strong
182
+ captain model Will cheap
183
+ ```
184
+
185
+ This drives the CLI's own `/model` command through Herdr: Claude Code takes
186
+ the model inline; Codex opens its numbered picker, reads the pane for the
187
+ matching row, and keeps the reasoning level it already had. Either way the
188
+ switch is verified from the pane; without the CLI's own confirmation line
189
+ naming that model, the command reports an error and changes nothing. A
190
+ confirmed switch updates the session and memory; the pane, the conversation,
191
+ and the assignment are untouched. Claude Code's inline `/model` also saves
192
+ the model as the default for new sessions, and the command prints that as a
193
+ reminder.
194
+
195
+ ## Dismissing crew
196
+
197
+ ```sh
198
+ captain dismiss Jack
199
+ ```
200
+
201
+ Closes the crew's pane, retires the name (freeing it for reuse), and records
202
+ the dismissal in memory. This is permanent, so confirm any unreported or
203
+ uncommitted work is handled first: crew commit their own hunks, and the
204
+ captain only cleans up the user's leftover edits afterward.
205
+
206
+ ## Editing guardrails
207
+
208
+ Crew share one checkout, so both captain and crew instructions carry the
209
+ same contract:
210
+
211
+ - Edit only files in your own assignment; give simultaneous writers disjoint
212
+ files and serialize same-file work.
213
+ - Re-read a file right before editing it, and keep others' unexpected
214
+ changes in place.
215
+ - Stage and commit only your own files/hunks, never `git add -A` or
216
+ repo-wide formatting.
217
+ - Never overwrite, rewrite from scratch, or discard existing or uncommitted
218
+ work; edit in place, and ask the user first if an assignment implies
219
+ replacing content.
220
+ - Finish or record a handoff before anyone else edits your file.
221
+ - Never commit or bump the version unless the user explicitly asks;
222
+ otherwise leave the work in the working tree and report the diff.
223
+
224
+ Nothing locks files: this is an instruction-only contract, not enforcement.
225
+
226
+ ## Memory
227
+
228
+ Captain stores graph relationships and launch metadata outside the
229
+ repository, split so durable project facts survive OS temp cleanup while
230
+ ephemeral session state does not:
231
+
232
+ ```text
233
+ ~/.local/state/captain-barbossa/<hash of project path>/
234
+ graph.json # explicit --scope project facts
235
+
236
+ <OS temp>/captain-barbossa-<uid>/<hash of project path>/
237
+ sessions/<session-id>/
238
+ session.json # workspace and crew references
239
+ graph.json # this session's memory only
240
+ ```
241
+
242
+ `$XDG_STATE_HOME` is honored in place of `~/.local/state` when set. Git
243
+ repositories use their checkout root as project identity; other directories
244
+ use the launch directory. Crew inherit their captain's project and session;
245
+ only explicitly saved project facts carry into other sessions. Set
246
+ `CAPTAIN_MEMORY_ROOT` before starting captain to redirect both roots at once
247
+ (used for test isolation and custom retention); it must point outside the
248
+ project.
249
+
250
+ ```sh
251
+ captain memory add "rate limiter" "uses" "per-user windows"
252
+ captain memory add "test command" "is" "python -m unittest" --scope project
253
+ captain memory show
254
+ captain memory query "rate limiter"
255
+ captain memory path
256
+ ```
257
+
258
+ `memory show` prints the most recent relationships as `[scope] [subject,
259
+ relation, object]`; `--all` shows every link, `--json` dumps the raw graph.
260
+ Default scope is `session`; use `--scope project` only for facts that should
261
+ survive into future sessions.
262
+
263
+ [Graphify](https://graphify.com/docs/cli) is optional: install it with
264
+ `uv tool install graphifyy` to enable `memory query`, which runs `graphify
265
+ query` against an isolated snapshot of project and session memory (output,
266
+ cache, and query logging are scoped to that snapshot and removed afterward).
267
+ Relationships can still be added and read with `memory add`/`show` without
268
+ it.
269
+
270
+ Session directories accumulate as sessions end. `captain memory prune` (also
271
+ run automatically, silently, and best-effort at every launch) removes
272
+ directories where nothing has been touched for `--older-than` days (7 by
273
+ default) and Herdr reports no live agent in their panes; when Herdr is
274
+ unreachable, only directories twice that age are removed. The current
275
+ session and the durable project graph are never removed.
276
+
277
+ ```sh
278
+ captain memory prune
279
+ captain memory prune --older-than 30
280
+ ```
281
+
282
+ ## Running commands from another pane
283
+
284
+ These commands run inside the launched agent's environment. From a separate
285
+ Herdr shell in the same project/workspace, pass the session explicitly:
286
+
287
+ ```sh
288
+ captain --session <session-id> memory show
289
+ captain --session <session-id> crew --task "Check boundary cases"
290
+ captain --session <session-id> --agent codex
291
+ ```
292
+
293
+ `--session` reuses the captain's graph memory; it starts a fresh native
294
+ conversation, not a provider transcript resume.
295
+
296
+ ## Troubleshooting
297
+
298
+ - **`captain: command not found`** - run `uv tool update-shell` and restart
299
+ the terminal.
300
+ - **"Launch captain from an interactive Herdr terminal."** - `captain` with
301
+ no subcommand needs a TTY; run it directly in a Herdr pane, not through a
302
+ script or pipe.
303
+ - **Crew pane opens but the task never starts, or is marked
304
+ `needs_attention`** - the native CLI may be waiting for approval or
305
+ sign-in. Inspect the pane in Herdr; the task is not retried automatically
306
+ past one resend. Send it by hand with
307
+ `herdr agent prompt <agent-name> '<task>'`.
308
+ - **"... is waiting for input or approval instead of starting the task."** -
309
+ read the pane before approving, then send the requested key with
310
+ `herdr agent send-keys <name> <key>` (Claude Code may need Enter or a
311
+ number, not always `y`).
312
+ - **"... did not confirm the switch to ..."** - the native CLI didn't echo
313
+ the expected model name; read the pane with `herdr agent read <name>`
314
+ before retrying `captain model`.
315
+ - **"This session belongs to another project or Herdr workspace."** - a
316
+ session ID is tied to the project and workspace it was created in; start a
317
+ new captain or pass the matching `--session`.
318
+ - **"durable memory root ... is inside the OS temp directory"** - a captain
319
+ started before the state/temp split is still exporting one root to its
320
+ children; restart it so project-scope memory survives temp cleanup.
321
+ - **`memory query` fails or reports a skip** - Graphify isn't installed; run
322
+ `uv tool install graphifyy`, or use `memory show`/`add` instead.
323
+ - **Ambiguous crew name or model** - the error lists the available crew or
324
+ models; ask for one of those exactly.
325
+
326
+ ## Command reference
327
+
328
+ | Command | Purpose |
329
+ |---|---|
330
+ | `captain [--agent claude\|codex] [--prompt TEXT]` | Start a captain in this pane |
331
+ | `captain crew [NAME] --task TEXT [--agent ...] [--placement pane\|tab] [--direction ...] [--split-pane ...] [--model ...]` | Recruit crew |
332
+ | `captain wait NAME [--timeout SECONDS]` | Wait for crew to finish |
333
+ | `captain model NAME cheap\|mid\|strong\|<model>` | Switch a running crew's model |
334
+ | `captain focus NAME` | Focus crew's pane and tab |
335
+ | `captain dismiss NAME` | Close and retire crew |
336
+ | `captain memory add SUBJECT RELATION TARGET [--scope session\|project]` | Save a memory relationship |
337
+ | `captain memory query QUESTION` | Search memory with Graphify |
338
+ | `captain memory show [--json] [--all]` | Print memory relationships |
339
+ | `captain memory path` | Print this session's memory directory |
340
+ | `captain memory prune [--older-than DAYS]` | Remove finished sessions' memory |
341
+ | `captain --session ID ...` | Run any command against another shell's session |
342
+ | `captain --version` | Print the installed version |
343
+
344
+ All `NAME` arguments are case-insensitive and accept the crew's display
345
+ name, ID, or Herdr agent name.
346
+
347
+ ## Development
348
+
349
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for setting up a checkout, running
350
+ checks, and the commit/PR workflow. Current implementation scope is tracked
351
+ in [docs/plan.md](docs/plan.md).
352
+
353
+ Related CLIs: [Herdr](https://herdr.dev/docs/cli-reference/),
354
+ [Graphify](https://graphify.com/docs/cli), and
355
+ [Codex's additional instructions](https://learn.chatgpt.com/docs/config-file/config-reference).
356
+
357
+ ## License
358
+
359
+ Licensed under [MIT](LICENSE).