Skip to main content
Glama
README.md
# BowThruster

BowThruster keeps two small guarantees in an AI coding loop:

1. **Human session memory survives compaction.** A single `session.md` file holds the active goal, working ideas, problems, agreed decisions, ruled-out decisions, and open questions. Runtime hooks re-inject that context and block subagent tasks that revive a ruled-out decision.
2. **Test impact gets surfaced and verified.** A `tree-sitter` index finds the tests that import a production file you are about to edit, and a SHA-256 ledger blocks an agent from stopping before those tests have run against the current file contents.

BowThruster needs Python 3.11+ and installs `tree-sitter-language-pack`. The core CLI makes no model calls and needs no API keys.

## Install

```bash
pip install -e .
bowthruster init
```

Run `bowthruster init` from the repository root. It creates `session.md` and `.mental_cache/`, updates `.gitignore`, and installs the Claude Code and Git hooks.

## CLI

All commands accept `--project-root PATH` and `--json` either before or after the subcommand.

```text
bowthruster init [--agy] [--lead-id ID ...] [--no-hooks] [--json]
bowthruster status [--json]                 # alias: session
bowthruster impact <files...> [--limit N] [--max-hops H] [--json]   # alias: tests
bowthruster plan-tests [files...] [--max-tests N] [--max-hops H] [--rank-jev] [--json]
bowthruster check [files...] [--json]
bowthruster hook <action> [--file F] [--session-id S] [--transcript T] [--agy] [--lead-id ID ...] [--json]
```

- `init` creates `session.md` and `.mental_cache/`, then installs hooks unless `--no-hooks` is set. Use `--agy` to also install Antigravity hooks and `--lead-id` to mark Lead conversation IDs.
- `status` reports session state, parsed bullets, syntax errors, and unverified test-impact changes.
- `impact` resolves each file and lists importing tests across multi-hop reverse imports (`--max-hops`, default `6`).
- `plan-tests` computes a fail-closed test plan (`widen_full_suite`, `tests`, `reasons`, `frontend_changed`) from git dirty/deleted files or explicit file arguments, `.bowthruster_fixtures.json` glob rules, and optional `--rank-jev` fail-fast ordering.
- `check` runs the syntax + Python LLM AST check and the unverified test-impact check; it exits `1` when syntax or AST gate errors exist.
- `hook` runs one runtime action: `install`, `pre-prompt`, `pre-tool`, `post-tool`, `post-read`, `stop`, `distill-session`, `pre-commit`, or `post-commit`.

## Optional Credentials

The core CLI and SHA-256 test-impact gate run offline with zero API keys. Optional model features read environment variables (or `.env`):

- `TYPESAFE_API_KEY` — queries `https://api.typesafe.ai/v1/systemone` (`jev-latest`) for ruled-out dispatch checks, `session.md` curation, and `plan-tests --rank-jev` fail-fast ordering.
- `DEEPSEEK_API_KEY` or `GEMINI_API_KEY` — distills completed Lead turns into `session.md` (`deepseek-v4-pro` or `gemini-2.5-flash` with full model output ceilings).

## Feature 1: `session.md` memory and the ruled-out guard

`session.md` is a plain Markdown file the agent and the human can both read and edit:

```markdown
# Active Session

## Goal
- (exploring)

## Working Ideas & Current Focus
- (none yet)

## Problems & Findings
- (none yet)

## Agreed Decisions
- (none yet)

## Ruled Out (and Why)
- Do not parse raw token claims in the gateway; route every check through auth.

## Open Questions
- (none yet)
```

- `UserPromptSubmit` re-injects the active Goal and settled sections across long sessions.
- On an idle Lead stop, `distill-session` updates `session.md` from the latest transcript.
- `PreToolUse` checks subagent dispatch prompts against `## Ruled Out (and Why)`. When Jev credentials are configured, it blocks a task that would revive a ruled-out decision.
- Emptying `session.md` resets it to the Brainstorming template.

## Feature 2: test-impact surfacing and the SHA-256 gate

For a production file, BowThruster parses repository imports with `tree-sitter`, finds test files that import it, and deduplicates the result per session:

```bash
bowthruster impact src/auth/token.py
```

```json
{
  "files": ["src/auth/token.py"],
  "importing_tests": ["tests/test_gateway.py"]
}
```

Runtime hooks inject the same list on edit (`pre-tool`) and read (`post-read`) so the agent sees which tests to run before it stops.

The verification gate records SHA-256 hashes of production files when a test command succeeds:

```bash
.venv/bin/python -m pytest tests/test_gateway.py
```

Later, `bowthruster check` and the `stop` hook compare each dirty production file's current SHA-256 against the verified ledger. If the file changed after the last successful test run, the agent is blocked from stopping until it runs the importing tests again.

### Fail-closed test planning (`plan-tests`), fixtures, and shadow recall

`bowthruster plan-tests` builds an inspectable CI/local test plan:

```bash
bowthruster plan-tests --rank-jev --json
```

- **Reason tags:** each selected test records `"changed-test"`, `"direct-import:<src>"`, `"transitive-caller:<src>"`, or `"declared-fixture:<pattern>"`.
- **Fail-closed full-suite widen (`"tests": ["*"]`):** widens automatically on deleted/renamed Python modules (`"deleted-module:<path>"`), unmapped or global Python dependencies such as `conftest.py` / `pyproject.toml` (`"unmapped-dependency:<path>"`), or candidate counts exceeding `--max-tests` (`"fanout-overflow"`).
- **Non-import fixture rules (`.bowthruster_fixtures.json`):** map repo-relative globs to test files, `["*"]`, or `["FRONTEND_BUILD"]` (which sets `"frontend_changed": true` without adding a fake pytest target):

```json
{
  "fixtures/**/*.json": ["tests/test_loader.py"],
  "migrations/*.sql": ["*"],
  "web/**": ["FRONTEND_BUILD"]
}
```

- **Opaque fail-fast Jev ranking (`--rank-jev`):** sends only opaque `q_0001`..`q_NNNN` IDs and anonymized coupling counts to `https://api.typesafe.ai/v1/systemone` (`jev-latest`). `UNKNOWN` (`None`) probabilities run first, followed by descending failure probability; Jev never drops or skips a selected test.
- **Shadow recall telemetry:** `record_shadow_proposal` appends pre-run proposals and actual failures to `.mental_cache/shadow_proposals.jsonl`, and `shadow_recall_summary` reports total runs and false-negative misses.

## `.mental_cache/` layout

`.mental_cache/` is git-ignored and lives next to `session.md`:

```text
.mental_cache/
├── hook_config.json        # Lead conversation IDs and install flags
├── pre_prompt_turns.json   # per-conversation prompt-injection cadence
├── session_state.json      # distillation state
├── session_parked.md       # parked session items
├── test_callers.json       # cached tree-sitter caller index
├── verified_tests.json     # SHA-256 verification ledger and stop-block signatures
├── seen_impact.json        # read/edit impact deduplication
├── shadow_proposals.jsonl  # immutable pre-run shadow selector log
├── distill.log             # detached distillation log
└── .gitignore              # ignores everything in this directory
```

## Walkthrough

```bash
# 1. Start a session.
cd your-repo
bowthruster init

# 2. Record a rule in session.md.
#    Edit "## Ruled Out (and Why)" with a bullet such as:
#    - Do not parse raw token claims in the gateway; route every check through auth.

# 3. Before editing a shared module, list the tests that import it.
bowthruster impact src/auth/token.py

# 4. Run those importing tests, then check the gate.
.venv/bin/python -m pytest tests/test_gateway.py
bowthruster check

# 5. Inspect the live session.
bowthruster status
```

With hooks installed, the ruled-out guard and test-impact prompts run automatically during the agent's normal edit, read, subagent-spawn, and stop events.

## License

Functional Source License, Version 1.1, with an Apache 2.0 future licence (`FSL-1.1-Apache-2.0`). See [LICENSE](LICENSE).

TDQS

B3.2/5.0

Scored across 8 tools

Disambiguation3/5

The tools map onto a clear staged workflow (atlas/slice=Step 1, turn=Step 2, packets=Step 3, git_sync/status=Step 4) which aids selection, and logs/readme are distinct. However, git_sync is heavily mode-overloaded (pre/post/baseline/drift), atlas supports two output modes, and status overlaps with git_sync's mark_verified STALE->VERIFIED transition, creating real boundary confusion.

Naming Consistency4/5

All names are single lowercase words or a single snake_case compound (git_sync), so style is consistent. There is no verb_noun convention, so the name alone doesn't convey the action (e.g. 'turn' and 'packets' are opaque until you read the description), but internal consistency is high.

Tool Count4/5

8 tools is well within a healthy range for a spec/workflow lifecycle server, and each participates in the pipeline rather than duplicating. The only concern is functional density (git_sync's four modes, atlas's two modes) rather than raw count.

Completeness4/5

The surface covers the core loop: explore (atlas), retrieve code (slice), mutate board (turn), compile packets, verify/sync (git_sync), transition (status), and diagnose failures (logs), plus format guidance (readme). Minor gaps exist: no explicit undo/rollback for a bad turn, and code editing itself is delegated to external read_file/grep and implied editors.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues