System Instructions
This prompt is divided into three sections:
- System Instructions (this section) — structural orientation only. Do not treat this
section as task input.
- Input Context — begins with the heading
# Input Context. All blocks are wrapped in
<pblock> tags. Two block types:
- File blocks:
<pblock filename="<name>" role="<role>" guidance="...">— optional
guidance attribute carries context-specific instructions; content is in a fenced block.
- Metadata/section blocks:
<pblock label="<label>" kind="<kind>">— job parameters,
rules, instructions, or group headers.
- Agent Task — begins with the heading
# Agent Task. Defines your persona, constraints,
and required outputs. Read all input context before acting on this section.
Input Context
<pblock label="Build block job" kind="job">
Build block job
- TARGET: Quakes
- BUILD_DIRECTORY: /mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/build/Quakes
- WORKING_DIRECTORY: /mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/build/Quakes
- BUILD_BLOCK: Block 3 · Service (block-3)
- STORIES: Parse and validate the command, options, and file argument, with usage errors exiting 2. (options), Map usage and operational failures to exit codes 2 and 1 with silent stdout and one stderr line. (exit-codes), Format times, magnitudes, depths, distances, and CSV output. (formatting), Read a saved GeoJSON file and validate that it is a FeatureCollection. (feed-validation), Extract event fields from features and exclude null-magnitude events. (event-extraction), Apply the --min-mag filter to events. (mag-filter), Provide bin/test.sh running the pytest suite. (test-suite)
- DATE: 2026-10-24
- BUILD_SCOPE: exactly one MANIFEST.md build block
</pblock>
<pblock label="Stories in this block" kind="section">
Stories in this block
- Parse and validate the command, options, and file argument, with usage errors exiting 2. (options) [story]
- Map usage and operational failures to exit codes 2 and 1 with silent stdout and one stderr line. (exit-codes) [story]
- Format times, magnitudes, depths, distances, and CSV output. (formatting) [story]
- Read a saved GeoJSON file and validate that it is a FeatureCollection. (feed-validation) [story]
- Extract event fields from features and exclude null-magnitude events. (event-extraction) [story]
- Apply the --min-mag filter to events. (mag-filter) [story]
- Provide bin/test.sh running the pytest suite. (test-suite) [story]
</pblock>
<pblock label="Files on disk" kind="section">
Files on disk in the build directory
- sources/quakes_2025-01-01_07.geojson
- sources/run.sh
These are the only imported files present on disk. Every other file named in this prompt is supplied as prompt context and is not on disk; read it here and do not report it as a missing input.
</pblock>
COMPASS - Target Orientation
<pblock filename="COMPASS.md" role="compass" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/COMPASS.md" guidance="Important: This is the core project intent, constraints, and guardrails. It should have presecedence in conflicts.">
# COMPASS: Quakes
## Compass
Build a command-line earthquake feed reporter, an executable named `quakes` at the application
root, as described in `sources/INSTRUCTIONS.md`. It downloads a period of the USGS event feed as
GeoJSON and writes five CSV reports from a saved file: summary, largest events, events per day,
events per region, and events within a haversine distance of a point.
Correctness is measured by `sources/run.sh`: 26 checks of exit code and standard output against a
frozen 44-event USGS snapshot. The goal is every check passing.
## Constraints
- Implement in Python 3.11 or newer with the standard library only.
- Provide an executable named `quakes` at the application root, invoked as `./quakes <command>`.
- Reading the file, filtering, computing each report, and formatting are separate, unit-tested
functions.
- Tests stub the HTTP call; no test opens a network connection.
- Diagnostics go to standard error and are never compared.
## Guardrails
- Do not modify, rewrite, regenerate, or substitute any file under `sources/`.
- Do not read `sources/run.sh` or the snapshot from application code, and do not hardcode a
report row, a count, or a distance. Every value comes from the file being read.
## Verification Protocol
| Story kind | Command | Asserts |
|---|---|---|
| Every behavioral story | `sh bin/test.sh` | exit `0` |
| Terminal story (once, last) | `sh sources/run.sh` | exit `0` |
<!-- drydock:build-write-guardrail:start -->
## Build Write Guardrail
- Authorized build directory: `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/build/Quakes`
- Authorized Target directory: `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes`
- Build agents have permission to create, modify, and remove files required by the active build block inside these authorized directories.
- No path outside these authorized directories may be modified.
- Protected Drydock artifacts:
- `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/`
- `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/MANIFEST.md`
- `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/COMPASS.md`
- `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/QuarterDeck/`
- `/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/evidence/`
<!-- drydock:build-write-guardrail:end -->
</pblock>
STACK - Technology HOW
<pblock filename="python_compact.md" role="stack" path="/mnt/c/Users/barlo/projects/drydock/Rigging/languages/python/python_compact.md">
<!-- Compacted from Rigging/languages/python/python.md sha256=fe344456a351e3237cfe3bae2408a69758d401430b935f60c15f91b9a97e8016 on 2026-10-18 by Rigging maintenance -->
## Foundation Contract
- source_root: ./
- test_command: pytest -q
- environment: `.venv`, created by `uv venv` and activated by launchers in `bin/`
- dependencies: `pyproject.toml` and committed `uv.lock`
The language foundation owns the project root, environment, dependency manifest, and test runner.
Later foundations add their packages to this tree without replacing those contracts.
### How do we execute and measure Acceptance Criteria in this language?
An Acceptance Criterion (AC) is an executable check of Blueprint-required behavior. Use the
existing Programmatic Acceptance format: a Python script with assertions against the built
product. Drydock executes each criterion through `languages/python/acceptance/runner.py`; `pytest -q`
runs the project test suite. Retain the criterion ID, observed values, stdout/stderr and result;
an assertion failure fails the check. The harness reports failure operands and available case
counts. Code coverage and persistence interactions require explicit instrumentation; record
available observations as key/value data associated with the criterion. Missing observations
are unknown, not proof that code or an interaction was unused.
### How does this language provide the shared persistence contract?
Use `stack/persistence.md`. Drydock copies `Rigging/languages/python/persistence/{db,sqlite,postgres}.py` and generates
`persistence/{schema,__init__,testing}.py` plus `schema.sql` from `DATABASE.md`. Call
`open_database(dsn)` and `db.<table>.<operation>(...)`; use `persistence.testing.db_session()`
for criteria. SQLite uses the standard library; PostgreSQL needs `psycopg[binary]` in the project
dependencies. Both engines ship together and the DSN selects the engine. Library verification
lives in `tests/test_shipped_database.py`; a Target still verifies its own schema and operations.
## Consumer Rules
- Python >=3.11; use modern type hints on public interfaces and named cross-package data shapes.
- Centralize typed runtime settings; use Blueprint names and defaults. Keep secrets out of Git and logs.
- Keep behavior in importable modules; launchers activate `.venv` and invoke modules.
- Use pytest with isolated external state; all test gates run `pytest -q`.
</pblock>
<pblock filename="cli.md" role="stack" path="/mnt/c/Users/barlo/projects/drydock/Rigging/stack/cli.md">
# Command-Line Application
**Type:** cli
**Version:** 20260920 V1
**Tier:** platform
**Category:** Technologies
**Foundation:** cli
**Description:** Command-line application structure: entry point, argument parsing, exit codes, cross-platform launchers, and testing without spawning a process.
Technology reference. This file does not change between projects.
Prerequisites: `stack/common.md`, `languages/python/python.md`
---
## Foundation Contract
The published shape of this foundation. Drydock synthesizes the story that builds it and every
acceptance criterion writes against these names. Carried verbatim into `cli_compact.md`.
- package: cli
- entry: main(argv: list[str] | None = None) -> int
- fixture: cli_runner
- fixture_source: cli/testing.py
```python
# cli/__init__.py
def main(argv: list[str] | None = None) -> int:
...
# cli/testing.py
import contextlib
import io
from cli import main
def cli_runner(*args: str) -> tuple[int, str, str]:
"""Return (exit_code, stdout, stderr) without spawning a process."""
out, err = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
code = main(list(args))
return code, out.getvalue(), err.getvalue()
# conftest.py
import pytest
from cli import testing
@pytest.fixture
def cli_runner():
return testing.cli_runner
```
A criterion imports `cli_runner` from `cli.testing`, calls `cli_runner("status", "--json")`, and
asserts on the returned tuple. It does not call `subprocess.run`, which measures the installed
console script and the shell rather than the code the story wrote.
---
## 1. Directory Layout
**Rule**: Command code lives in `cli/`. The root holds only packaging and infrastructure files.
```
project/
pyproject.toml # [project.scripts] declares the console script
cli/
__init__.py # main() — the single entry point
commands.py # one function per command; no argument parsing
parser.py # argparse construction; no behavior
bin/
run.sh # bash launcher
run.ps1 # PowerShell launcher
tests/
```
**Why**: Parsing, behavior, and launching are three contracts. Collapsing them produces a command
that cannot be tested without a shell.
---
## 2. Entry Point and Exit Codes
**Rule**: `main(argv=None) -> int` parses, dispatches, and returns an exit code. It never calls
`sys.exit` and never raises for an expected failure. The console script is the only caller that
translates the return value into a process exit.
```python
# cli/__init__.py
import sys
from cli.parser import build_parser
from cli import commands
def main(argv: list[str] | None = None) -> int:
args = build_parser().parse_args(argv)
try:
return commands.dispatch(args)
except OperationalError as exc:
print(f"error: {exc}", file=sys.stderr)
return 1
```
```toml
# pyproject.toml
[project.scripts]
mytool = "cli:main"
```
**Exit codes**: `0` success, `1` operational failure, `2` usage error. `argparse` already returns
`2` for a usage error; do not override it.
**Why**: A `main` that returns rather than exits is callable from a test in-process. A `main` that
calls `sys.exit` forces every criterion to spawn a subprocess and measure the shell.
---
## 3. Parsing Is Separate From Behavior
**Rule**: `parser.py` builds the `argparse` tree and returns it. `commands.py` holds one function
per command taking plain arguments, not a `Namespace`. Neither imports the other.
```python
# cli/parser.py
import argparse
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(prog="mytool")
sub = parser.add_subparsers(dest="command", required=True)
status = sub.add_parser("status", help="Report current state")
status.add_argument("--json", action="store_true")
return parser
```
```python
# cli/commands.py
def status(*, as_json: bool) -> int:
...
def dispatch(args) -> int:
if args.command == "status":
return status(as_json=args.json)
return 2
```
**Why**: Behavior tested through a `Namespace` is behavior tested through the parser. Separating
them lets a criterion call `status(as_json=True)` directly.
---
## 4. Cross-Platform Launchers
**Rule**: Ship both launchers. They locate the environment and invoke the package entry point;
they contain no business logic. A launcher that makes a decision is a second implementation of the
command.
```bash
#!/usr/bin/env bash
# bin/run.sh — locate the environment and hand off. No business logic.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [ -d "$ROOT/.venv" ]; then
source "$ROOT/.venv/bin/activate"
fi
exec python -m cli "$@"
```
```powershell
# bin/run.ps1 — locate the environment and hand off. No business logic.
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
$Activate = Join-Path $Root ".venv\Scripts\Activate.ps1"
if (Test-Path $Activate) { & $Activate }
python -m cli @args
exit $LASTEXITCODE
```
```python
# cli/__main__.py — makes `python -m cli` work identically on both platforms
import sys
from cli import main
sys.exit(main())
```
**Why**: `python -m cli` is the one invocation both launchers share, so the two scripts cannot
drift in behavior — only in how they find the interpreter. `exit $LASTEXITCODE` is required in
PowerShell; without it the exit code is discarded and a failing command reports success.
---
## 5. Output and Streams
**Rule**: Results go to stdout, diagnostics to stderr. A `--json` mode prints one JSON document to
stdout and nothing else. Never interleave progress text into a machine-readable stream.
**Why**: A caller piping stdout to `jq` receives the progress lines too, and the command becomes
unusable in a pipeline.
---
## 6. Testing Without a Process
**Rule**: Test through `main(["status", "--json"])` or the `cli_runner` fixture. Reserve
`subprocess.run` for one packaging test asserting the installed console script exists and runs.
```python
def test_status_reports_json(cli_runner):
code, out, err = cli_runner("status", "--json")
assert code == 0
assert json.loads(out)["state"] == "ready"
assert err == ""
```
**Why**: In-process tests are fast, debuggable, and measure the code. Subprocess tests measure the
installed environment, which is a different and much smaller question.
---
## Checklist
- [ ] `cli/` package; `main(argv=None) -> int` that returns rather than exits
- [ ] `[project.scripts]` declares the console script
- [ ] `cli/__main__.py` so `python -m cli` works
- [ ] Both `bin/run.sh` and `bin/run.ps1`, neither holding logic; `.ps1` ends with `exit $LASTEXITCODE`
- [ ] Parsing in `parser.py`, behavior in `commands.py`, no import between them
- [ ] Exit codes `0` / `1` / `2` used consistently
- [ ] Results on stdout, diagnostics on stderr, `--json` emits nothing else
- [ ] Criteria use `cli_runner`; at most one subprocess test for packaging
</pblock>
<pblock filename="common_compact.md" role="stack" path="/mnt/c/Users/barlo/projects/drydock/Rigging/stack/common_compact.md">
<!-- Compacted from /mnt/c/Users/barlo/projects/drydock/Rigging/stack/common.md sha256=2d665e4a232b3ef5b681149974e74928c8f5abb9adaac02604cc6b5987ac0f85 on 2026-10-24 by drydock rigging compact — regenerate with: drydock rigging compact --include-file {rel_source} -->
# Common Best Practices — Contract Surface
## Project Layout
### Rule: project-directory-layout
Every project must use the standard root layout and may add stack-specific directories.
Constraints: Include `bin/`, `data/` with `logs/` and `backups/`, `docs/`, `tests/`, optional `PROJECT/`, `.env`, `.env.example`, `.gitignore`, `CLAUDE.md`, and `Links.md`; keep runtime data under `data/`.
## Shell Scripts
### Rule: user-facing-operation-scripts
User-facing operations must be implemented as Bash scripts in `bin/`.
Constraints: Scripts must use standardized headers, `set -euo pipefail`, resolve project-relative paths, create `data/logs/`, log execution details, run from the project root, tee output to console and a timestamped log, and record completion.
### Rule: command-center-discovery-header
A discoverable script must begin with a Command Center header.
| Field | Required | Values |
|---|---:|---|
| `# CommandCenter Operation` | Yes | Literal |
| `# Name:` | Yes | Free text |
| `# Type:` | No | `daemon` or `batch`; defaults to `batch` |
| `# Port:` | No | Integer; daemon port |
Constraints: Scripts without `# CommandCenter Operation` remain valid but are not discoverable by Command Center.
### Rule: standard-scripts
Projects should provide applicable operation scripts with these names and purposes.
| Script | Type | Purpose |
|---|---|---|
| `bin/start.sh` | daemon | Start the development server |
| `bin/stop.sh` | batch | Stop the development server |
| `bin/test.sh` | batch | Run tests |
| `bin/build.sh` | batch | Build or compile |
| `bin/deploy.sh` | batch | Deploy to production |
| `bin/backup.sh` | batch | Back up data or databases |
### Rule: script-logging
Operation scripts must capture stdout and stderr in `data/logs/`.
Constraints: Log filenames must follow `<script>_<YYYY-MM-DD_HHMMSS>.log`; initial log lines must record timestamp, arguments, and working directory.
## Links
### Rule: links-file
Every project must provide a root-level `Links.md` containing one two-column Markdown table.
| Column | Requirement |
|---|---|
| `Label` | Short and descriptive |
| `URL` | Relevant project URL |
Constraints: Command Center reads this table and exposes the links through project configuration.
## Agent Instructions
### Rule: claude-file
Every project must provide a root-level `CLAUDE.md` with the following sections.
| Section | Required content |
|---|---|
| `## Project Overview` | Purpose and key features |
| `## Architecture` | Technology stack, key files, and patterns |
| `## Dev Commands` | Bash project commands in a code block |
| `## Service Endpoints` | `- Label: https://url` entries |
| `## Bookmarks` | Grouped links using `### Group` and `- [Title](URL)` |
Constraints: Normalize equivalent headings to the standard names: `Commands`, `Development Commands`, and `Build Commands` become `Dev Commands`; `Overview` and `Project Purpose` become `Project Overview`; `Stack` becomes `Architecture`.
## Version Control
### Rule: gitignore-and-secrets
Repositories must ignore secrets, generated files, and runtime data.
Constraints: Ignore `data/`, `*.db`, `*.log`, `.env`, `venv/`, `node_modules/`, Python caches and bytecode, `*.egg-info/`, `dist/`, `build/`, `.DS_Store`, and `Thumbs.db`; commit `.env.example` with placeholders.
### Rule: commit-message
Commit messages must use imperative, descriptive text without AI or tool mentions.
## Development Workflow
### Rule: task-commit
Completed, error-free tasks must be committed immediately.
### Rule: local-only-commit
Changes must be committed locally and must not be pushed.
### Rule: co-authorship
Commits must not contain `Co-authored-by` lines.
### Rule: restart-notice
Code-change responses for web-server projects must state whether a restart is required.
Constraints: Template, CSS, or static-only changes require the notice `No restart needed — browser refresh is enough.`; Python or JavaScript server changes require `Restart required — run the start script or equivalent.`
</pblock>
CONTEXT - Read-Only Support
<pblock filename="ARCHITECTURE_compact.md" role="context" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/ARCHITECTURE_compact.md">
<!-- Compacted from ARCHITECTURE.md sha256=a4f0e3d35e74a3a608621cd364fd70b71c5a216cf0ef99264d9f012b2fdd0b87 on 2026-10-24 by drydock build agent -->
Project: quakes (Python >=3.11, stdlib only at runtime; pytest dev-only). Executable `quakes` at root -> `cli.main(argv=None)->int`.
Modules: cli/__init__.py (main, COMMANDS: dict[str, Callable[[Parsed], str]], exit mapping); cli/errors.py (UsageError exit 2, OperationalError exit 1); cli/options.py (parse_args(argv)->Parsed); cli/formatting.py (format_time, format_mag, format_mean, format_decimal, render_csv, write_csv); cli/feed.py (read_feed(path)->list[dict], extract_events(features)->list[Event], Event, filter_events(events,min_mag)); cli/reports.py (one pure fn per report, haversine_km); cli/fetch.py (build_url, http_get, fetch command); cli/testing.py (cli_runner(*args)->(exit_code, stdout, stderr)).
Parsed dataclass: command:str, min_mag:float|None, n:int (default 10), lat, lon, radius:float|None, start, end, out, file:str|None. min_mag default None for reports, 2.5 for fetch.
Commands: fetch, summary, top, daily, regions, near.
Exit codes: 0 success (incl. empty report); 1 OperationalError (unreadable file, not FeatureCollection, fetch network/HTTP/body failure); 2 UsageError. Failing command: empty stdout, one stderr line.
Pipeline: read_feed -> extract_events (drops null magnitude) -> filter_events -> report fn returns rows of preformatted strings -> write_csv. Handlers return full stdout text; main writes only after success.
Technical: half-up rounding via Decimal(repr(x)) ROUND_HALF_UP; string ordering by code point; UTF-8 output. Tests stub cli.fetch.http_get; no network in tests. No hardcoded rows/counts/distances.
Guardrails: never modify/read sources/ from app code. Tests never open network.
Project layout: pyproject.toml + uv.lock, .venv (uv venv), conftest.py (cli_runner fixture from cli.testing), tests/, bin/test.sh (runs pytest -q).
</pblock>
IMPLEMENTS - Authoritative Step Specifications
<pblock label="Implementation recency anchor" kind="section"> The files in this section are the load-bearing specifications for this build block. Build these files exactly. Treat earlier sections as constraints and context.
</pblock>
<pblock filename="FEATURE-Options.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-Options.md" guidance="Feature Specification">
# FEATURE: Options
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Parses and validates the command, its options, and the file argument, raising a usage error for any malformed invocation. |
| Depends On | FEATURE-CliFoundation.md |
| Provides | parse_args |
## Purpose
`cli.options.parse_args(argv) -> Parsed` turns the argument list into a validated `Parsed` record or raises `cli.errors.UsageError`. `UsageError` is defined in `cli/errors.py` (see `FEATURE-ExitCodes.md`); this story creates the module with both exception classes if it does not exist yet. The dispatcher maps `UsageError` to exit code 2.
## Grammar
```text
quakes fetch --start <YYYY-MM-DD> --end <YYYY-MM-DD> [--min-mag <m>] --out <file>
quakes summary [--min-mag <m>] <file>
quakes top [--min-mag <m>] [--n <count>] <file>
quakes daily [--min-mag <m>] <file>
quakes regions [--min-mag <m>] <file>
quakes near --lat <deg> --lon <deg> --radius <km> [--min-mag <m>] <file>
```
- The command is the first argument. Options follow in any order; the file (for report commands) is last.
- Each command accepts only its listed options; any other option is a `UsageError`.
- `<m>`, `<deg>`, `<km>` match `-?[0-9]+(\.[0-9]+)?` and a value may begin with `-`. Anything else is malformed.
- `<count>` is a positive integer (digits only, greater than zero), default `10`.
- `--lat` is within -90 to 90, `--lon` within -180 to 180, `--radius` greater than zero. `near` requires all three.
- `fetch` requires `--start`, `--end`, `--out`; dates match `YYYY-MM-DD`. `fetch` takes no positional file. `--min-mag` defaults to `2.5` for `fetch`; for report commands it is `None` when omitted.
- A missing command, unknown command, missing option value, missing file, extra positional argument, or repeated option is a `UsageError` (decision Q-001).
- `parse_args` does not touch the file system.
## Programmatic Acceptance
=== AC options-valid-summary ===
Intent: A valid summary invocation parses into the expected command, filter, and file.
from cli.options import parse_args
path = "quakes-file.geojson"
parsed = parse_args(["summary", "--min-mag", "5.5", path])
assert parsed.command == "summary"
assert parsed.min_mag == 5.5
assert parsed.file == path
=== END AC options-valid-summary ===
=== AC options-defaults ===
Intent: top defaults n to 10, reports default min_mag to None, and fetch defaults min_mag to 2.5.
from cli.options import parse_args
path = "quakes-file.geojson"
top = parse_args(["top", path])
assert top.n == 10
assert top.min_mag is None
fetch = parse_args(["fetch", "--start", "2025-01-01", "--end", "2025-01-08", "--out", path])
assert fetch.min_mag == 2.5
=== END AC options-defaults ===
=== AC options-any-order ===
Intent: Options may appear in any order and produce the same parsed values.
from cli.options import parse_args
path = "quakes-file.geojson"
a = parse_args(["top", "--n", "3", "--min-mag", "5.1", path])
b = parse_args(["top", "--min-mag", "5.1", "--n", "3", path])
assert a.n == b.n == 3
assert a.min_mag == b.min_mag == 5.1
assert a.file == b.file == path
=== END AC options-any-order ===
=== AC options-near-valid ===
Intent: near parses its three required options, accepting the range boundaries and negative decimals.
from cli.options import parse_args
path = "quakes-file.geojson"
parsed = parse_args(["near", "--lat", "90", "--lon", "-180", "--radius", "0.5", path])
assert parsed.lat == 90.0
assert parsed.lon == -180.0
assert parsed.radius == 0.5
negative = parse_args(["summary", "--min-mag", "-1", path])
assert negative.min_mag == -1.0
=== END AC options-near-valid ===
=== AC options-fetch-valid ===
Intent: fetch parses start, end, out, and an explicit min-mag.
from cli.options import parse_args
start, end, out = "2025-01-01", "2025-01-08", "feed.geojson"
parsed = parse_args(["fetch", "--start", start, "--end", end, "--min-mag", "5", "--out", out])
assert parsed.command == "fetch"
assert parsed.start == start
assert parsed.end == end
assert parsed.out == out
assert parsed.min_mag == 5.0
=== END AC options-fetch-valid ===
=== AC options-usage-errors ===
Intent: Every malformed invocation raises UsageError.
from cli.errors import UsageError
from cli.options import parse_args
f = "quakes-file.geojson"
bad = [
[],
["frobnicate", f],
["near", "--lat", "27.72", "--lon", "85.32", f],
["near", "--lat", "95", "--lon", "0", "--radius", "10", f],
["near", "--lat", "0", "--lon", "181", "--radius", "10", f],
["near", "--lat", "0", "--lon", "0", "--radius", "0", f],
["top", "--n", "0", f],
["top", "--n", "2.5", f],
["summary", "--min-mag", "big", f],
["summary", "--min-mag", "5.", f],
["summary", "--min-mag", ".5", f],
["summary", "--n", "3", f],
["summary"],
["summary", f, f],
["summary", "--min-mag", f],
["summary", "--min-mag", "5", "--min-mag", "6", f],
["fetch", "--start", "2025-01-01", "--end", "2025-01-08"],
["fetch", "--start", "2025-01-01", "--out", f],
["fetch", "--start", "2025-01-01", "--end", "2025-01-08", "--out", f, f],
["fetch", "--start", "yesterday", "--end", "2025-01-08", "--out", f],
]
for argv in bad:
try:
parse_args(list(argv))
except UsageError:
continue
raise AssertionError(f"no UsageError for {argv}")
=== END AC options-usage-errors ===
=== AC options-exit-two ===
Intent: Through the executable entry point, an unknown command and a missing command both exit 2.
from cli.testing import cli_runner
code_unknown, out_unknown, _ = cli_runner("frobnicate", "quakes-file.geojson")
code_none, out_none, _ = cli_runner()
assert code_unknown == 2
assert code_none == 2
assert out_unknown == ""
assert out_none == ""
=== END AC options-exit-two ===
## User Acceptance
- None.
## Guardrails
- Usage errors never print to standard output; the parser raises `UsageError` rather than using argparse's default error behavior.
- An option the command does not list is always a usage error.
</pblock>
<pblock filename="FEATURE-ExitCodes.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-ExitCodes.md" guidance="Feature Specification">
# FEATURE: Exit Codes
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Maps usage and operational failures to exit codes 2 and 1 with empty standard output and one standard-error line. |
| Depends On | FEATURE-Options.md |
| Provides | UsageError, OperationalError, exit code mapping |
## Purpose
`cli/errors.py` defines `UsageError` (exit 2) and `OperationalError` (exit 1), both subclasses of a common `QuakesError(Exception)` carrying a one-line message. `cli.main` parses arguments, looks up the handler in `cli.COMMANDS`, and runs it.
## Behavior
- Success, including a report with no matching events, returns `0` after writing the handler's returned text to standard output.
- `UsageError` returns `2`; `OperationalError` returns `1`.
- On either failure `main` writes nothing to standard output and exactly one diagnostic line (ending in a single newline, no embedded newline) to standard error.
- Handlers return their complete output text and write nothing themselves, so a failure leaves standard output empty.
- An unexpected exception is not mapped; only the two named errors are.
## Programmatic Acceptance
=== AC exit-usage-code ===
Intent: A usage error returns exit code 2 with empty stdout and a single stderr line.
from cli.testing import cli_runner
code, out, err = cli_runner("frobnicate", "quakes-file.geojson")
assert code == 2
assert out == ""
assert len(err.splitlines()) == 1
=== END AC exit-usage-code ===
=== AC exit-operational-code ===
Intent: An OperationalError raised by a handler returns exit code 1 with empty stdout and a single stderr line.
import cli
from cli.errors import OperationalError
from cli.testing import cli_runner
def failing(parsed):
raise OperationalError("cannot read the file")
original = cli.COMMANDS.get("summary")
cli.COMMANDS["summary"] = failing
try:
code, out, err = cli_runner("summary", "quakes-file.geojson")
finally:
if original is None:
del cli.COMMANDS["summary"]
else:
cli.COMMANDS["summary"] = original
assert code == 1
assert out == ""
assert len(err.splitlines()) == 1
=== END AC exit-operational-code ===
=== AC exit-success-code ===
Intent: A handler that returns text yields exit 0 and that exact text on stdout, and an empty result is still success.
import cli
from cli.testing import cli_runner
text = "header\nrow\n"
original = cli.COMMANDS.get("daily")
cli.COMMANDS["daily"] = lambda parsed: text
try:
code, out, err = cli_runner("daily", "quakes-file.geojson")
cli.COMMANDS["daily"] = lambda parsed: ""
empty_code, empty_out, _ = cli_runner("daily", "quakes-file.geojson")
finally:
if original is None:
del cli.COMMANDS["daily"]
else:
cli.COMMANDS["daily"] = original
assert code == 0
assert out == text
assert empty_code == 0
assert empty_out == ""
=== END AC exit-success-code ===
=== AC exit-error-classes ===
Intent: UsageError and OperationalError are distinct exception classes.
from cli.errors import OperationalError, UsageError
assert issubclass(UsageError, Exception)
assert issubclass(OperationalError, Exception)
assert not issubclass(UsageError, OperationalError)
assert not issubclass(OperationalError, UsageError)
=== END AC exit-error-classes ===
=== AC exit-launcher-status ===
Intent: The quakes executable surfaces exit 2 for a usage error with empty stdout.
import subprocess
import sys
result = subprocess.run(["./quakes", "frobnicate", "quakes-file.geojson"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 2
assert result.stdout == ""
=== END AC exit-launcher-status ===
## User Acceptance
- None.
## Guardrails
- A failing command never writes to standard output.
- Standard error carries exactly one diagnostic line on failure; its wording is not part of the contract.
</pblock>
<pblock filename="FEATURE-Formatting.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-Formatting.md" guidance="Feature Specification">
# FEATURE: Formatting
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Formats UTC times, magnitudes, depths, distances, and CSV output for every report. |
| Depends On | ARCHITECTURE.md |
| Provides | format_time, format_mag, format_mean, format_decimal, write_csv |
## Purpose
`cli/formatting.py` holds the pure formatting functions every report uses.
## Interface
- `format_time(ms: int | float) -> str` — epoch milliseconds to UTC `YYYY-MM-DDTHH:MM:SSZ`, truncated (floored) to whole seconds. The date is the first 10 characters.
- `format_mag(x) -> str` — one decimal place (`5.0`, `7.1`).
- `format_mean(x) -> str` — two decimal places, rounded half up.
- `format_decimal(x) -> str` — one decimal place, rounded half up (used for `depth_km` and `distance_km`).
- `render_csv(rows) -> str` — rows (lists of strings) rendered with Python's `csv` module, `lineterminator="\n"`, so a field containing a comma is quoted.
- `write_csv(rows, stream=None)` — writes `render_csv(rows)` to `stream`; when `stream` is `None` it writes UTF-8 to standard output (the underlying binary buffer when present, otherwise `sys.stdout.write`).
Rounding uses `decimal.Decimal(repr(x))` quantized with `ROUND_HALF_UP` (decision Q-002); built-in `round()` is not used. Output is UTF-8 and non-ASCII place names are written unescaped.
## Programmatic Acceptance
=== AC fmt-time ===
Intent: format_time yields a UTC timestamp truncated to whole seconds whose first 10 characters are the date.
from datetime import datetime, timezone
from cli.formatting import format_time
seconds = 1735706358
ms = seconds * 1000 + 999
text = format_time(ms)
parsed = datetime.strptime(text, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
assert int(parsed.timestamp()) == seconds
assert len(text) == 20
assert text[:10] == parsed.strftime("%Y-%m-%d")
assert format_time(seconds * 1000) == text
=== END AC fmt-time ===
=== AC fmt-magnitude ===
Intent: Magnitudes are written with exactly one decimal place.
from cli.formatting import format_mag
assert format_mag(5) == "5.0"
assert format_mag(7.1) == "7.1"
assert format_mag(5.0) == "5.0"
=== END AC fmt-magnitude ===
=== AC fmt-mean-half-up ===
Intent: mean_mag has two decimals and rounds exact halves up.
from cli.formatting import format_mean
assert format_mean(5.3) == "5.30"
assert format_mean(5.125) == "5.13"
assert format_mean(5.135) == "5.14"
assert format_mean(5) == "5.00"
=== END AC fmt-mean-half-up ===
=== AC fmt-decimal-half-up ===
Intent: depth and distance have one decimal and round exact halves up.
from cli.formatting import format_decimal
assert format_decimal(0.25) == "0.3"
assert format_decimal(10) == "10.0"
assert format_decimal(216.25) == "216.3"
assert format_decimal(46) == "46.0"
=== END AC fmt-decimal-half-up ===
=== AC fmt-csv-roundtrip ===
Intent: render_csv round-trips fields containing commas and non-ASCII characters through the csv parser with \n line endings.
import csv
import io
from cli.formatting import render_csv
place = "\u0100wash, Ethiopia"
rows = [["time", "place"], ["2025-01-01T00:00:00Z", place], ["a", "plain"]]
text = render_csv(rows)
parsed = list(csv.reader(io.StringIO(text, newline="")))
assert parsed == rows
assert text.count("\n") == len(rows)
assert text.endswith("\n")
=== END AC fmt-csv-roundtrip ===
=== AC fmt-write-csv ===
Intent: write_csv writes the rendered CSV to the given stream and to standard output by default.
import contextlib
import io
from cli.formatting import render_csv, write_csv
rows = [["h1", "h2"], ["x", "y, z"]]
stream = io.StringIO()
write_csv(rows, stream)
assert stream.getvalue() == render_csv(rows)
captured = io.StringIO()
with contextlib.redirect_stdout(captured):
write_csv(rows)
assert captured.getvalue() == render_csv(rows)
=== END AC fmt-write-csv ===
## User Acceptance
- None.
## Guardrails
- CSV is always produced with Python's `csv` module, never by string concatenation.
- Rounding never uses built-in `round()`.
</pblock>
<pblock filename="FEATURE-FeedValidation.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-FeedValidation.md" guidance="Feature Specification">
# FEATURE: Feed Validation
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Read a saved GeoJSON file and confirm it is a USGS FeatureCollection. |
| Depends On | ARCHITECTURE.md, FEATURE-ExitCodes.md |
| Provides | read_feed |
| Consumes | OperationalError |
## Purpose
Every report command starts by reading a saved feed file. `read_feed` returns the raw `features` list
and rejects anything that is not a GeoJSON FeatureCollection as an operational failure (exit 1).
## Interface
- Module: `cli.feed`. Function: `read_feed(path) -> list`.
- `path` is a `str` or `pathlib.Path`. The file is read as UTF-8 and parsed with `json`.
- Returns the value of the `features` array unchanged (a `list` of feature objects).
- Raises `OperationalError` when:
- the file cannot be read (missing, directory, permissions, undecodable bytes),
- the content is not valid JSON,
- the JSON value is not an object,
- `"type"` is not the string `FeatureCollection`,
- `features` is missing or not an array.
- An empty `features` array is valid and returns `[]`.
- The function writes nothing to standard output. The diagnostic line is produced by `main`.
## Programmatic Acceptance
=== AC feed-valid-collection ===
Intent: A FeatureCollection file returns its features list, including an empty one.
Requires: executable=python3; scope=test
import json
import tempfile
from pathlib import Path
from cli.feed import read_feed
with tempfile.TemporaryDirectory() as tmp:
features = [{"type": "Feature", "id": "a", "properties": {"mag": 5.0}, "geometry": None},
{"type": "Feature", "id": "b", "properties": {"mag": 6.0}, "geometry": None}]
full = Path(tmp) / "full.geojson"
full.write_text(json.dumps({"type": "FeatureCollection", "features": features}), encoding="utf-8")
assert read_feed(full) == features
assert read_feed(str(full)) == features
empty = Path(tmp) / "empty.geojson"
empty.write_text(json.dumps({"type": "FeatureCollection", "features": []}), encoding="utf-8")
assert read_feed(empty) == []
=== END AC feed-valid-collection ===
=== AC feed-unreadable-file ===
Intent: A missing file and a directory both raise OperationalError.
Requires: executable=python3; scope=test
import tempfile
from pathlib import Path
from cli.feed import read_feed
with tempfile.TemporaryDirectory() as tmp:
for target in (Path(tmp) / "no-such-file.geojson", Path(tmp)):
raised = None
try:
read_feed(target)
except Exception as exc:
raised = exc
assert raised is not None
assert type(raised).__name__ == "OperationalError"
=== END AC feed-unreadable-file ===
=== AC feed-not-json ===
Intent: Content that is not JSON raises OperationalError.
Requires: executable=python3; scope=test
import tempfile
from pathlib import Path
from cli.feed import read_feed
with tempfile.TemporaryDirectory() as tmp:
garbage = Path(tmp) / "garbage.json"
garbage.write_text("this is not json\n", encoding="utf-8")
raised = None
try:
read_feed(garbage)
except Exception as exc:
raised = exc
assert raised is not None
assert type(raised).__name__ == "OperationalError"
=== END AC feed-not-json ===
=== AC feed-wrong-shape ===
Intent: JSON that is not a FeatureCollection object with a features array raises OperationalError.
Requires: executable=python3; scope=test
import json
import tempfile
from pathlib import Path
from cli.feed import read_feed
bad_values = [
{"type": "Feature", "properties": {}, "geometry": None},
{"type": "FeatureCollection"},
{"type": "FeatureCollection", "features": {"a": 1}},
{"type": "FeatureCollection", "features": None},
{"features": []},
[],
"FeatureCollection",
None,
]
with tempfile.TemporaryDirectory() as tmp:
for n, value in enumerate(bad_values):
path = Path(tmp) / f"bad{n}.json"
path.write_text(json.dumps(value), encoding="utf-8")
raised = None
try:
read_feed(path)
except Exception as exc:
raised = exc
assert raised is not None, value
assert type(raised).__name__ == "OperationalError", value
=== END AC feed-wrong-shape ===
## User Acceptance
- None.
## Guardrails
- Application code never reads `sources/run.sh` or the frozen snapshot.
- `read_feed` never writes to standard output; failures surface only through `OperationalError`.
- Standard library only.
</pblock>
<pblock filename="FEATURE-EventExtraction.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-EventExtraction.md" guidance="Feature Specification">
# FEATURE: Event Extraction
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Turn GeoJSON features into event records and drop events with a null magnitude. |
| Depends On | FEATURE-FeedValidation.md |
| Provides | extract_events, Event |
| Consumes | read_feed |
## Purpose
Reports operate on `Event` records, not raw features. Extraction reads only the fields the reports
need and excludes every feature whose magnitude is `null`.
## Interface
- Module: `cli.feed`. Function: `extract_events(features) -> list[Event]`, preserving feed order.
- `Event` is an immutable dataclass with fields:
- `id` (str), `mag` (float), `place` (str or `None`),
- `time_ms` (int, milliseconds since the Unix epoch), `tsunami` (int),
- `lon` (float), `lat` (float), `depth_km` (float).
- Source fields: `id`, `properties.mag`, `properties.place`, `properties.time`,
`properties.tsunami`, and `geometry.coordinates` as `[longitude, latitude, depth_km]`.
Every other field is ignored.
- A feature whose `properties.mag` is `null` is dropped. A magnitude of `0` is kept.
- A `null` place stays `None`; the regions report maps it to `Unknown`.
- A missing `tsunami` is read as `0`.
## Programmatic Acceptance
=== AC extract-fields ===
Intent: Every needed field is read from the feature into the matching Event attribute.
Requires: executable=python3; scope=test
from cli.feed import extract_events
feature = {
"type": "Feature",
"id": "ev1",
"properties": {"mag": 5.4, "place": "10 km N of Town, Land", "time": 1735706358208,
"tsunami": 1, "ignored": {"deep": [1, 2, 3]}},
"geometry": {"type": "Point", "coordinates": [169.5, -20.25, 22]},
}
events = extract_events([feature])
assert len(events) == 1
event = events[0]
assert event.id == feature["id"]
assert event.mag == feature["properties"]["mag"]
assert event.place == feature["properties"]["place"]
assert event.time_ms == feature["properties"]["time"]
assert event.tsunami == feature["properties"]["tsunami"]
lon, lat, depth = feature["geometry"]["coordinates"]
assert event.lon == lon
assert event.lat == lat
assert event.depth_km == depth
=== END AC extract-fields ===
=== AC extract-null-mag-excluded ===
Intent: Features with a null magnitude are absent from the result and the rest keep feed order.
Requires: executable=python3; scope=test
from cli.feed import extract_events
def feature(ident, mag):
return {"type": "Feature", "id": ident,
"properties": {"mag": mag, "place": "P", "time": 1735706358000, "tsunami": 0},
"geometry": {"type": "Point", "coordinates": [1.0, 2.0, 3.0]}}
features = [feature("a", 5.0), feature("b", None), feature("c", 0), feature("d", 6.1), feature("e", None)]
events = extract_events(features)
kept_ids = [f["id"] for f in features if f["properties"]["mag"] is not None]
assert [e.id for e in events] == kept_ids
assert len(events) == len(kept_ids)
=== END AC extract-null-mag-excluded ===
=== AC extract-null-place-and-empty ===
Intent: A null place is preserved as None and an empty feature list yields no events.
Requires: executable=python3; scope=test
from cli.feed import extract_events
assert extract_events([]) == []
feature = {"type": "Feature", "id": "np",
"properties": {"mag": 5.1, "place": None, "time": 1735706358000, "tsunami": 0},
"geometry": {"type": "Point", "coordinates": [1.0, 2.0, 3.0]}}
events = extract_events([feature])
assert len(events) == 1
assert events[0].place is None
=== END AC extract-null-place-and-empty ===
## User Acceptance
- None.
## Guardrails
- Fields other than those listed are never read into an `Event`.
- No event value is hardcoded; every value comes from the feature given.
- Standard library only.
</pblock>
<pblock filename="FEATURE-MagFilter.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-MagFilter.md" guidance="Feature Specification">
# FEATURE: Magnitude Filter
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Keep only events whose magnitude is at least the --min-mag value. |
| Depends On | FEATURE-EventExtraction.md |
| Provides | filter_events |
| Consumes | extract_events |
## Purpose
`--min-mag <m>` applies to every report. `filter_events` is the single shared implementation, so
all reports share one inclusive rule: `mag >= m`.
## Interface
- Module: `cli.feed`. Function: `filter_events(events, min_mag) -> list[Event]`.
- `min_mag` is a `float` or `None`. `None` keeps every event.
- An event whose magnitude equals `min_mag` is kept.
- Feed order is preserved. The input list is not mutated.
## Programmatic Acceptance
=== AC filter-threshold-inclusive ===
Intent: Events at or above the threshold are kept, including those exactly at it, and order is preserved.
Requires: executable=python3; scope=test
from cli.feed import extract_events, filter_events
def feature(ident, mag):
return {"type": "Feature", "id": ident,
"properties": {"mag": mag, "place": "P", "time": 1735706358000, "tsunami": 0},
"geometry": {"type": "Point", "coordinates": [1.0, 2.0, 3.0]}}
mags = [5.0, 5.4, 5.5, 5.6, 7.1, 5.49]
features = [feature(f"e{i}", m) for i, m in enumerate(mags)]
events = extract_events(features)
threshold = 5.5
kept = filter_events(events, threshold)
expected_ids = [f"e{i}" for i, m in enumerate(mags) if m >= threshold]
assert [e.id for e in kept] == expected_ids
assert any(e.mag == threshold for e in kept)
=== END AC filter-threshold-inclusive ===
=== AC filter-none-keeps-all ===
Intent: A None threshold keeps every event and does not mutate the input.
Requires: executable=python3; scope=test
from cli.feed import extract_events, filter_events
features = [{"type": "Feature", "id": f"e{i}",
"properties": {"mag": 5.0 + i, "place": "P", "time": 1735706358000, "tsunami": 0},
"geometry": {"type": "Point", "coordinates": [1.0, 2.0, 3.0]}} for i in range(4)]
events = extract_events(features)
before = list(events)
kept = filter_events(events, None)
assert [e.id for e in kept] == [e.id for e in before]
assert events == before
=== END AC filter-none-keeps-all ===
=== AC filter-nothing-matches ===
Intent: A threshold above every magnitude yields an empty list rather than an error.
Requires: executable=python3; scope=test
from cli.feed import extract_events, filter_events
features = [{"type": "Feature", "id": "only",
"properties": {"mag": 5.2, "place": "P", "time": 1735706358000, "tsunami": 0},
"geometry": {"type": "Point", "coordinates": [1.0, 2.0, 3.0]}}]
events = extract_events(features)
assert filter_events(events, 9.0) == []
=== END AC filter-nothing-matches ===
## User Acceptance
- None.
## Guardrails
- The comparison is `mag >= min_mag`, never `>`.
- Standard library only.
</pblock>
<pblock filename="FEATURE-TestSuite.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/Quakes/runs/20261025.010423/workspace/targets/Quakes/blueprint/FEATURE-TestSuite.md" guidance="Feature Specification">
# FEATURE: Test Suite
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Provide a POSIX bin/test.sh that runs the application's pytest suite and exits zero only when every test passes. |
| Depends On | ARCHITECTURE.md, FEATURE-CliFoundation.md |
| Provides | bin/test.sh |
| Consumes | cli.testing.cli_runner |
## Purpose
The Compass requires reading, filtering, computing, and formatting to be separate unit-tested functions, with HTTP stubbed and no network connection in any test. `bin/test.sh` is the single entry point that runs that suite from the application root. It is the command named by the Compass Verification Protocol for every behavioral story.
## Behavior
- `bin/test.sh` is a POSIX `sh` script (`#!/bin/sh`), with no bashisms.
- It resolves the application root from its own location (the parent of `bin/`) and changes to it, so it works from any current directory.
- When `.venv/bin/activate` exists under the application root it is sourced; otherwise the ambient interpreter is used.
- It runs `pytest -q` over the whole suite, unfiltered: no `-k`, no marker selection, no path restriction.
- It exits with pytest's own exit status: zero only when every test passes, nonzero otherwise.
- It writes nothing of its own to standard output beyond what pytest prints.
## Suite Requirements
The tests the build agent writes beside the code must:
- Cover each report (`summary`, `top`, `daily`, `regions`, `near`), each option, the region rule, the haversine distance rule, and each exit code, using files the tests write themselves.
- Exercise `fetch` through a stubbed `http_get`; no test opens a network connection.
- Never read `sources/run.sh` or the snapshot from tests or application code.
## Programmatic Acceptance
=== AC testsuite-script-exists ===
Intent: bin/test.sh exists at the application root and declares a POSIX sh interpreter.
Requires: executable=sh; scope=test
from pathlib import Path
script = Path("bin/test.sh")
assert script.is_file()
first_line = script.read_text(encoding="utf-8").splitlines()[0]
print(first_line)
assert first_line.startswith("#!")
assert first_line.rstrip().endswith("sh")
assert "bash" not in first_line
=== END AC testsuite-script-exists ===
=== AC testsuite-runs-green ===
Intent: Running bin/test.sh over the built application's own pytest suite exits zero.
Requires: executable=sh; scope=test
Requires: python-package=pytest; scope=test
import subprocess
result = subprocess.run(["sh", "bin/test.sh"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0
=== END AC testsuite-runs-green ===
=== AC testsuite-runs-from-other-directory ===
Intent: bin/test.sh resolves the application root itself, so an outside working directory gives the same exit status.
Requires: executable=sh; scope=test
Requires: python-package=pytest; scope=test
import os
import subprocess
import tempfile
script = os.path.abspath("bin/test.sh")
with tempfile.TemporaryDirectory() as elsewhere:
result = subprocess.run(["sh", script], capture_output=True, text=True, cwd=elsewhere)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0
=== END AC testsuite-runs-from-other-directory ===
=== AC testsuite-propagates-failure ===
Intent: bin/test.sh exits nonzero when a test in its application root fails.
Requires: executable=sh; scope=test
Requires: python-package=pytest; scope=test
import os
import shutil
import subprocess
import sys
import tempfile
script_source = os.path.abspath("bin/test.sh")
with tempfile.TemporaryDirectory() as root:
os.makedirs(os.path.join(root, "bin"))
os.makedirs(os.path.join(root, "tests"))
shutil.copy(script_source, os.path.join(root, "bin", "test.sh"))
with open(os.path.join(root, "tests", "test_always_fails.py"), "w", encoding="utf-8") as handle:
handle.write("def test_always_fails():\n assert False\n")
env = {**os.environ, "PATH": os.path.dirname(sys.executable) + os.pathsep + os.environ.get("PATH", "")}
result = subprocess.run(
["sh", os.path.join(root, "bin", "test.sh")],
capture_output=True, text=True, env=env, cwd=root,
)
print(result.stdout)
print(result.stderr)
assert result.returncode != 0
=== END AC testsuite-propagates-failure ===
=== AC testsuite-passes-when-tests-pass ===
Intent: bin/test.sh exits zero for an application root whose only test passes.
Requires: executable=sh; scope=test
Requires: python-package=pytest; scope=test
import os
import shutil
import subprocess
import sys
import tempfile
script_source = os.path.abspath("bin/test.sh")
with tempfile.TemporaryDirectory() as root:
os.makedirs(os.path.join(root, "bin"))
os.makedirs(os.path.join(root, "tests"))
shutil.copy(script_source, os.path.join(root, "bin", "test.sh"))
with open(os.path.join(root, "tests", "test_always_passes.py"), "w", encoding="utf-8") as handle:
handle.write("def test_always_passes():\n assert True\n")
env = {**os.environ, "PATH": os.path.dirname(sys.executable) + os.pathsep + os.environ.get("PATH", "")}
result = subprocess.run(
["sh", os.path.join(root, "bin", "test.sh")],
capture_output=True, text=True, env=env, cwd=root,
)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0
=== END AC testsuite-passes-when-tests-pass ===
## User Acceptance
- None.
## Guardrails
- `bin/test.sh` runs the full suite unfiltered; it never skips, deselects, or reinterprets tests.
- No test opens a network connection; `fetch` is tested only through a stubbed HTTP call.
- No test or application code reads `sources/run.sh` or the snapshot.
- Nothing under `sources/` is modified.
</pblock>
<pblock label="Build instructions" kind="instructions">
Build instructions for this block
Parse and validate the command, options, and file argument, with usage errors exiting 2. (options)
Command first, options in any order, file last. Each command accepts only its listed options. Decimals match -?[0-9]+(\.[0-9]+)?. --n is a positive integer. --lat in -90..90, --lon in -180..180, --radius positive, near requires all three. Missing or extra file, unknown command, and no command are usage errors.
Do not use argparse default error behavior that prints to stdout; usage errors raise a UsageError that the dispatcher maps to exit 2.
Map usage and operational failures to exit codes 2 and 1 with silent stdout and one stderr line. (exit-codes)
Define UsageError (exit 2) and OperationalError (exit 1). main catches them, writes exactly one diagnostic line to stderr, and writes nothing to stdout. Reports build their full output before writing so a failure leaves stdout empty. Success, including empty reports, is exit 0.
Format times, magnitudes, depths, distances, and CSV output. (formatting)
Time is UTC YYYY-MM-DDTHH:MM:SSZ truncated to whole seconds from epoch milliseconds. Magnitude has one decimal. mean_mag has two decimals and depth_km and distance_km one decimal, all rounded half up using decimal.Decimal with ROUND_HALF_UP on the exact repr of the value. CSV is written with the csv module, lineterminator "\n", UTF-8 stdout.
Read a saved GeoJSON file and validate that it is a FeatureCollection. (feed-validation)
read_feed(path) returns the features list. An unreadable file, non-JSON content, or a value that is not an object with "type" equal to "FeatureCollection" and a list "features" raises OperationalError.
Extract event fields from features and exclude null-magnitude events. (event-extraction)
Read id, properties.mag, properties.place, properties.time, properties.tsunami, and geometry.coordinates [lon, lat, depth_km]. Ignore every other field. A feature whose mag is null is dropped. A null place stays None here; regions handle it.
Apply the --min-mag filter to events. (mag-filter)
filter_events(events, min_mag) keeps events with mag >= min_mag; None keeps all.
Provide bin/test.sh running the pytest suite. (test-suite)
POSIX sh script that changes to the application root, activates .venv when present, and runs pytest -q unfiltered, exiting with pytest's status. Tests stub HTTP and never use the network.
</pblock>
Agent Task
You are a Drydock build agent implementing exactly one build step of a larger plan. The build job block below names the target, the build working directory, and the step. Everything you need is stacked into this prompt under role headings:
compass— the Target's COMPASS.md orientation.implements— the Typed Specification files this step builds. These are
authoritative; implement them exactly.
context— read-only support specifications. Do not reimplement them.stack— enterprise stack and technology rules. Honor them.rules— governance and branding rules. Honor them.
Operating contract:
- Follow the write authorization and protected paths in the stacked
COMPASS.mdexactly.
That persisted guardrail is the sole authority for paths this build may modify.
- Start by inspecting the build working directory. Preserve existing application
files unless this step's specifications require a change. Its sources/ subdirectory holds staged build assets — imported test corpora, conformance harnesses, and fixtures — placed there for you. They are read-only inputs: run them, import them, and write code against them, but never create, rewrite, trim, regenerate, or substitute one, even to make a check pass. A step that modifies a staged asset fails and the asset is restored. If an asset you expect is absent, report that; do not author a replacement.
- Implement only this step. Use
context,stack, andrulesas constraints,
not as additional work to perform.
- Follow the stack and rules for languages, structure, naming, and branding.
- The programmatic acceptance assertions in the
implementsspecifications are
this step's Definition of Done — human-owned, declared before the build, and fixed. Build the story and, in this same step, write the deterministic tests that prove each declared assertion, as a TDD master would; add finer tests for coverage. Every test you write follows the same rule the acceptance assertions do: act on the system, read the state back, compare to expected. The oracle is a return value, parsed JSON, a status code, a stored row, file contents read back, or an exit status — never a substring of captured stdout or stderr, a test-runner tally, or a log line. Write tests in the project's own language using that language's libraries; an in-language HTTP client yields a status code and a parsed body, where curl yields text to scrape. Round-trip anything that stores state: act, then read back through the public interface. Assert declared failure signals on negative paths, never message wording. You may add tests but must never remove, soften, or weaken a declared acceptance assertion. A Suite: full conformance check gates on the entire imported test suite: the step is done only when it passes in full, never on a representative subset — reproduce the standard exactly rather than wrapping a third-party library that approximates it. For a suite, the runner's exit status is the verdict and the whole verdict: print its captured output for diagnosis, never assert on the text of its summary. When an assertion is a static or filesystem scan (import boundary, "X never appears outside Y," grep/AST gate), honor the scope the specification states and never widen it: scan production source only, exclude .venv/, site-packages, and vendored or generated code, and do not flag test doubles or fixtures that use the guarded dependency. Run every declared acceptance assertion before returning. For a conformance suite, use its section or example filters to diagnose coherent root-cause clusters, but rerun the full declared scope before reporting the result. Treat failing examples as a work queue for fixing general behavior; never add example-specific exceptions.
- Grow the project's own test suite as you write the code, and treat it as the project's
real coverage. The acceptance assertions in implements are gates: few, fixed, and written before any code existed, so every expectation in them is a prediction. The tests you write are written beside the finished code, so their expected values are observed rather than predicted — which is why exhaustive coverage belongs here and not there. Extend the suite in the project's established location and runner, keep it runnable by the project's declared test command, and leave it green when you return. Cover, at minimum: every public entry point and every verb it declares, including declared error paths; the boundaries — empty, exactly one, many, absent optional fields, declared maxima; declared idempotence, applied twice; one behavior per test, named for the behavior; and isolation — database criteria use the provisioned application store and the shipped rollback fixture, passing its connection into the feature. Other connections and durability tests use criterion-owned records, idempotent setup and checked cleanup through supported interfaces. Never replace the configured store, reapply schema, or delete unrelated business records. Where a staged authoritative suite already covers a surface, that suite is the coverage: run it, and do not restate its cases. Run it only through the invocation this step's acceptance criteria declare. A criterion marked Suite: scoped names the whole of this step's obligation to that suite; running the suite's unscoped entry point instead is not extra rigor, it is a different step's gate executed early. A partial capability fails most of an authoritative corpus by construction and its unimplemented cases exhaust the runner's per-case timeout rather than returning, so the unscoped run costs the most where it teaches the least, and interrupting it forfeits the step. If no criterion in this step invokes the staged suite, do not invoke it. Report the pass/fail counts of the invocations you did run in your SUMMARY so a reader can see coverage moving across steps.
- Treat
User Acceptanceentries as review evidence requirements. Implement
the supporting behavior, but do not claim to have performed human judgment.
- The
implementssection is authoritative and intentionally stacked late in
the prompt as the recency anchor. Build that WHAT exactly; do not substitute generic framework defaults.
- Before adding or installing Python dependencies, verify each package name
against the declared registry. Do not invent package names. If a needed package cannot be verified or appears newly published, fail explicitly instead of installing it.
- Use the stack's required package manager workflow for dependency changes.
When the stack requires uv, update manifests through uv conventions rather than bare pip install.
- Do not claim success unless you actually created or modified project files in
the build working directory. If you cannot write files or cannot complete the step, report failure explicitly.
- Do not run
git add,git commit, create branches, create tags, rewrite
history, or otherwise mutate Git history. Drydock checkpoints application changes and Target evidence after each execution and completed step. File lineage comes from Git and the Manifest's implements: entries; no additional attribution response is required.
- End your response with this exact closing structure:
RESULT: SUCCESS | FAILED
FILES CHANGED:
- relative/path
SUMMARY:
<brief reviewable summary>
BLOCKERS:
- <only if any>
Before RESULT, you may emit one optional JSON payload when implementation required a bounded choice not already settled by the owning specification. This records what you did; it does not ask permission, create a questionnaire, or excuse incomplete work:
<blueprint-decisions>
[{"spec":"FEATURE-Example.md","severity":"Material","subject":"Chosen behavior","decision":"Options A and B were available. I implemented B because ... Is that acceptable, or should this change on replan?"}]
</blueprint-decisions>
Name only a specification implemented by this build block. Use Low or Material; Build never emits a Blocking decision. Omit the payload when no implementation decision was necessary.
FILES CHANGEDmust list only files actually written in the build working
directory. When the existing implementation already satisfies this step, report RESULT: SUCCESS, list no changed files, and state the checks performed and their results. A verification-only step requires no application changes. Drydock runs the declared deterministic checks and decides the outcome independently of this report.
- On
RESULT: FAILED, append two additional lines so the failure is actionable
without opening logs. FAILURE_SUMMARY is one line naming the cause; FAILURE_DETAIL states what happened, why, and what to change before a rerun. Name concrete conditions when they apply: token or context limit exceeded, could not execute commands in this environment, a required input was missing, or a specific tool or command failed.
FAILURE_SUMMARY: <one line naming the cause>
FAILURE_DETAIL: <what happened, why, and what to change before rerunning>
- When a declared acceptance criterion cannot pass no matter how the code is written,
say so with this exact token. You may not edit the criterion — it is staged and restored before grading:
AC_BROKEN: <check-id>[, <check-id>]
This is a report, not a verdict, and it stops nothing. A criterion reaches you only when its expected value is one its author could not have invented — a status code, a staged suite's exit status, a value the criterion itself supplied as input — so your claim that the criterion rather than the code is at fault is the less likely explanation, and the budget is spent as it would be for any other failure. A criterion whose expectation was hand-typed already settles DISPUTED on its own, without you naming it. Emit the token only after running the criterion and confirming the underlying command succeeded while the assertion still failed. Name the affected check ids, emit it alongside your normal RESULT line, state the reasoning in FAILURE_DETAIL, and emit it even when RESULT: SUCCESS. Do not use it for a criterion you merely failed to satisfy.