Skip to content

Commit a24c99e

Browse files
committed
wip
1 parent 6055d54 commit a24c99e

File tree

1 file changed

+184
-73
lines changed

1 file changed

+184
-73
lines changed

AGENTS.md

Lines changed: 184 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
11
# Codex Agent Playbook
22

3-
Welcome, Codex Agent! Your persistence, curiosity, and craftsmanship make a difference. Take your time, work methodically, validate thoroughly, and iterate. This repository is large and tests can take time — that’s expected and supported.
3+
Welcome, AI Agent! Your persistence, curiosity, and craftsmanship make a difference. Take your time, work methodically, validate thoroughly, and iterate. This repository is large and tests can take time — that’s expected and supported.
44

5-
> **Timebox:** Aim to complete each autonomous run in **15–30 minutes**. Prefer small, verifiable steps and targeted module builds for fast feedback.
5+
> **Timebox:** Aim to complete each autonomous run in **15–30 minutes**.
66
77
## Purpose & Contract
8-
- **Bold goal:** deliver correct, minimal, well‑tested changes with clear handoff.
8+
- **Bold goal:** deliver correct, minimal, well‑tested changes with clear handoff. No monkey‑patching or band‑aid fixes — always fix the underlying problem at its source.
99
- **Bias to action:** when inputs are ambiguous, choose a reasonable path, state assumptions, and proceed.
1010
- **Ask only when blocked or irreversible:** escalate only if truly blocked (permissions, missing deps, conflicting requirements) or if a choice is high‑risk/irreversible.
1111
- **Definition of Done**
12-
- Code formatted and imports sorted.
13-
- Compiles with a quick profile / targeted modules.
14-
- Relevant module tests pass; failures triaged or crisply explained.
15-
- Only necessary files changed; headers correct for new files.
16-
- Clear final summary: what changed, why, where, how verified, next steps.
12+
- Code formatted and imports sorted.
13+
- Compiles with a quick profile / targeted modules.
14+
- Relevant module tests pass; failures triaged or crisply explained.
15+
- Only necessary files changed; headers correct for new files.
16+
- Clear final summary: what changed, why, where, how verified, next steps.
17+
18+
### No Monkey‑Patching or Band‑Aid Fixes (Non‑Negotiable)
19+
20+
This repository requires durable, root‑cause fixes. Superficial changes that mask symptoms, mute tests, or add ad‑hoc toggles are not acceptable.
21+
22+
What this means in practice
23+
- Find and fix the root cause in the correct layer/module.
24+
- Add or adjust targeted tests that fail before the fix and pass after.
25+
- Keep changes minimal and surgical; do not widen APIs/configs to “make tests green”.
26+
- Maintain consistency with existing style and architecture; prefer refactoring over hacks.
27+
28+
Strictly avoid
29+
- Sleeping/timeouts to hide race conditions or flakiness.
30+
- Broad catch‑and‑ignore or logging‑and‑continue of exceptions.
31+
- Muting, deleting, or weakening assertions in tests to pass builds.
32+
- Reflection or internal state manipulation to bypass proper interfaces.
33+
- Feature flags/toggles that disable validation or logic instead of fixing it.
34+
- Changing public APIs or configs without necessity and clear rationale tied to the root cause.
35+
36+
Preferred approach (fast and rigorous)
37+
- Reproduce the issue and isolate the smallest failing test (class → method).
38+
- Trace to the true source; fix it in the right module.
39+
- Add focused tests covering the behavior and any critical edge cases.
40+
- Run tight, targeted verifies for the impacted module(s) and broaden scope only if needed.
41+
42+
Review bar and enforcement
43+
- Treat this policy as a blocking requirement. Changes that resemble workarounds will be rejected.
44+
- Your final handoff must demonstrate: failing test before the fix, explanation of the root cause, minimal fix at source, and passing targeted tests after.
1745

1846
## Environment
1947
- **JDK:** 11 (minimum). The project builds and runs on Java 11+.
@@ -27,58 +55,58 @@ Welcome, Codex Agent! Your persistence, curiosity, and craftsmanship make a diff
2755

2856
**Rule of thumb**
2957
- ✅ Use `-am` **only** for compile/verify with tests skipped (e.g. `-Pquick`).:
30-
- `mvn -o -pl <module> -am -Pquick verify`
58+
- `mvn -o -pl <module> -am -Pquick verify`
3159
- ❌ Do **not** use `-am` with `verify` when tests are enabled.
3260

3361
**Two-step pattern (fast + safe)**
3462
1) **Compile deps fast (skip tests):**
3563
`mvn -o -pl <module> -am -Pquick verify`
36-
2) **Run tests :**
37-
`mvn -o -pl <module> verify | tail -500`
64+
2) **Run tests:**
65+
`mvn -o -pl <module> verify | tail -500`
3866

3967
It is illegal to `-am` when running tests!
4068
It is illegal to `-q` when running tests!
4169

4270
## Quick Start (First 10 Minutes)
4371
1. **Discover**
44-
- List modules: inspect root `pom.xml` (aggregator) and the module tree (see “Maven Module Overview” below).
45-
- Search fast with ripgrep: `rg -n "<symbol or string>"`
72+
- List modules: inspect root `pom.xml` (aggregator) and the module tree (see “Maven Module Overview” below).
73+
- Search fast with ripgrep: `rg -n "<symbol or string>"`
4674
2. **Build sanity (fast, skip tests)**
47-
- **Preferred:** `mvn -o -Pquick install | tail -200`
48-
- **Alternative:** `mvn -o -Pquick verify | tail -200`
75+
- **Preferred:** `mvn -o -Pquick install | tail -200`
76+
- **Alternative:** `mvn -o -Pquick verify | tail -200`
4977
3. **Format (Java, imports, XML)**
50-
- `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
78+
- `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
5179
4. **Targeted tests (tight loops)**
52-
- By module (incl. deps): `mvn -o -pl <module> verify | tail -500`
53-
- Single class: `mvn -o -pl <module> -Dtest=ClassName verify | tail -500`
54-
- Single method: `mvn -o -pl <module> -Dtest=ClassName#method verify | tail -500`
80+
- By module (incl. deps): `mvn -o -pl <module> verify | tail -500`
81+
- Single class: `mvn -o -pl <module> -Dtest=ClassName verify | tail -500`
82+
- Single method: `mvn -o -pl <module> -Dtest=ClassName#method verify | tail -500`
5583
5. **Inspect failures**
56-
- **Unit (Surefire):** `<module>/target/surefire-reports/`
57-
- **IT (Failsafe):** `<module>/target/failsafe-reports/`
84+
- **Unit (Surefire):** `<module>/target/surefire-reports/`
85+
- **IT (Failsafe):** `<module>/target/failsafe-reports/`
5886

5987
It is illegal to `-am` when running tests!
6088
It is illegal to `-q` when running tests!
6189

6290

6391
## Working Loop
6492
- **Plan**
65-
- Break task into **small, verifiable steps**; keep one step in progress.
66-
- Announce a short preamble before long actions (builds/tests).
67-
- Decide and proceed autonomously; document assumptions inline.
93+
- Break task into **small, verifiable steps**; keep one step in progress.
94+
- Announce a short preamble before long actions (builds/tests).
95+
- Decide and proceed autonomously; document assumptions inline.
6896
- **Change**
69-
- Make minimal, surgical edits. Keep style and structure consistent.
97+
- Make minimal, surgical edits. Keep style and structure consistent.
7098
- **Format**
71-
- `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
99+
- `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
72100
- **Compile (fast)**
73-
- **Iterate locally:** `mvn -o -pl <module> -am -Pquick verify | tail -500`
101+
- **Iterate locally:** `mvn -o -pl <module> -am -Pquick verify | tail -500`
74102
- **Test**
75-
- Start with the smallest scope that exercises your change (class → module).
76-
- For integration‑impacted changes, run module `verify` (includes ITs).
103+
- Start with the smallest scope that exercises your change (class → module).
104+
- For integration‑impacted changes, run module `verify` (includes ITs).
77105
- **Triage**
78-
- Read reports; fix root cause; expand scope **only when needed**.
106+
- Read reports; fix root cause; expand scope **only when needed**.
79107
- **Iterate**
80-
- Keep moving without waiting for permission between steps. Escalate only at blocking points.
81-
- Repeat until **Definition of Done** is satisfied.
108+
- Keep moving without waiting for permission between steps. Escalate only at blocking points.
109+
- Repeat until **Definition of Done** is satisfied.
82110

83111
It is illegal to `-am` when running tests!
84112
It is illegal to `-q` when running tests!
@@ -94,33 +122,116 @@ It is illegal to `-q` when running tests!
94122
- **Prefer module tests you touched:** `-pl <module>`
95123
- **Narrow further** to a class/method for tight loops; then broaden to the module.
96124
- **Expand scope** when:
97-
- Your change crosses module boundaries, or
98-
- Neighbor module failures indicate integration impact.
125+
- Your change crosses module boundaries, or
126+
- Neighbor module failures indicate integration impact.
99127
- **Read reports**
100-
- Surefire (unit): `target/surefire-reports/`
101-
- Failsafe (IT): `target/failsafe-reports/`
128+
- Surefire (unit): `target/surefire-reports/`
129+
- Failsafe (IT): `target/failsafe-reports/`
102130
- **Helpful flags**
103-
- `-Dtest=Class#method` (unit selection)
104-
- `-Dit.test=ITClass#method` (integration selection)
105-
- `-DtrimStackTrace=false` (full traces)
106-
- `-DskipITs` (focus on unit tests)
107-
- `-DfailIfNoTests=false` (when selecting a class that has no tests on some platforms)
131+
- `-Dtest=Class#method` (unit selection)
132+
- `-Dit.test=ITClass#method` (integration selection)
133+
- `-DtrimStackTrace=false` (full traces)
134+
- `-DskipITs` (focus on unit tests)
135+
- `-DfailIfNoTests=false` (when selecting a class that has no tests on some platforms)
136+
137+
## Assertions: Make invariants explicit
138+
139+
Assertions are executable claims about what must be true. They’re the fastest way to surface “impossible” states and to localize bugs at the line that crossed a boundary it had no business crossing. Use them both as **temporary tripwires** during investigation and as **permanent contracts** once an invariant is known to matter.
140+
141+
**Two useful flavors**
142+
143+
- **Temporary tripwires (debug asserts):** Add while hunting a failing test or weird behavior. Keep them cheap, contextual, and local to the suspect path. Remove after the mystery is solved **or** convert to permanent checks if the invariant is genuinely important.
144+
- **Permanent contracts:** Encode **preconditions** (valid inputs), **postconditions** (valid outputs), and **invariants** (state that must always hold). These stay and prevent regressions.
145+
146+
**Where to add assertions**
147+
148+
- At **module boundaries** and **after parsing/external calls** (validate assumptions about returned/decoded data).
149+
- Around **state transitions** (illegal transitions should fail loudly).
150+
- In **concurrency hotspots** (e.g., “lock must be held”, “no concurrent mutation”).
151+
- Before/after **caching, batching, or memoization** (keys, sizes, ordering, monotonicity).
152+
- For **exhaustive enums** in `switch` statements (treat unexpected values as hard errors).
153+
154+
**How to write good assertions**
155+
156+
- One fact per assert. Fail **fast**, fail **usefully**.
157+
- Include **stable context** in the message (ids, sizes, states) so the failure is self‑explanatory.
158+
- Avoid side effects in the condition or message. Assertions may be disabled in some runtimes.
159+
- Keep them **cheap**: no I/O, heavy allocations, or deep logging in the message.
160+
- Don’t use asserts for **user‑facing validation**. Raise exceptions for expected bad inputs.
161+
162+
**Java specifics**
163+
164+
- **Enable VM assertions in tests.** Tests must run with `-ea` so `assert` is active.
165+
- Use **`assert`** for debug‑only invariants that “cannot happen.” Use **exceptions** for runtime guarantees:
166+
- Preconditions: `IllegalArgumentException` / `Objects.requireNonNull` (or Guava `Preconditions` if present).
167+
- Invariants: `IllegalStateException`.
168+
- Prefer treating unexpected enum values as **hard errors** rather than adding a quiet `default` path.
169+
170+
**Concrete examples**
171+
172+
Precondition (permanent)
173+
```java
174+
void setPort(int port) {
175+
if (port < 1 || port > 65_535) {
176+
throw new IllegalArgumentException("port out of range: " + port);
177+
}
178+
this.port = port;
179+
}
180+
```
181+
182+
Invariant (permanent)
183+
```java
184+
void advance(State next) {
185+
if (!allowedTransitions.get(state).contains(next)) {
186+
throw new IllegalStateException("Illegal transition " + state + "" + next);
187+
}
188+
state = next;
189+
}
190+
```
191+
192+
Debug tripwire (temporary; remove or convert later)
193+
```java
194+
// Narrow a flaky failure around ordering
195+
assert isSorted(results) : "unsorted results, size=" + results.size() + " ids=" + ids(results);
196+
```
197+
198+
Unreachable (hard error)
199+
```java
200+
switch (kind) {
201+
case A: return handleA();
202+
case B: return handleB();
203+
default:
204+
throw new IllegalStateException("Unhandled kind: " + kind);
205+
}
206+
```
207+
208+
Concurrency assumption
209+
```java
210+
synchronized void put(String k, String v) {
211+
assert Thread.holdsLock(this) : "put must hold instance monitor";
212+
// ...
213+
}
214+
```
215+
216+
217+
House rule: Asserts are allowed and encouraged. Removing or weakening an assertion to “make it pass” is strictly forbidden — fix the cause, not the guardrail.
218+
108219

109220
## Triage Playbook
110221
- **Missing dep/plugin offline**
111-
- Remedy: **rerun the exact command without `-o`** once to fetch; then return offline.
222+
- Remedy: **rerun the exact command without `-o`** once to fetch; then return offline.
112223
- **Compilation errors**
113-
- Fix imports, generics, visibility; re‑run quick verify (skip tests) in the **module**.
224+
- Fix imports, generics, visibility; re‑run quick verify (skip tests) in the **module**.
114225
- **Flaky/slow tests**
115-
- Run the specific failing test; read its report; stabilize root cause before broad runs.
226+
- Run the specific failing test; read its report; stabilize root cause before broad runs.
116227
- **Formatting failures**
117-
- Run formatter/import/XML sort; re‑verify.
228+
- Run formatter/import/XML sort; re‑verify.
118229
- **License header missing**
119-
- Add header for **new** files only (see “Source File Headers”); **do not** change years on existing files.
230+
- Add header for **new** files only (see “Source File Headers”); **do not** change years on existing files.
120231

121232
## Code Formatting
122233
- **Always run before finalizing:**
123-
- `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
234+
- `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
124235
- **Style:** no wildcard imports; 120‑char width; curly braces always; LF line endings.
125236
- **Tip:** formatting/import sort may be validated during `verify`. Running the commands proactively avoids CI/style failures.
126237

@@ -147,36 +258,36 @@ Do **not** modify existing headers’ years.
147258
## Pre‑Commit Checklist
148259
- **Format:** `mvn -o -q -T 2C formatter:format impsort:sort xml-format:xml-format`
149260
- **Compile (fast path):** `mvn -o -Pquick verify | tail -200`
150-
- **Tests (targeted):** `mvn -o -pl <module> verify | tail -500` (broaden scope if needed)
261+
- **Tests (targeted):** `mvn -o -pl <module> verify | tail -500` (broaden scope if needed)
151262
- **Reports:** zero new failures in `target/surefire-reports/` or `target/failsafe-reports/`, or explain precisely.
152263

153264
## Navigation & Search
154265
- Fast file search: `rg --files`
155266
- Fast content search: `rg -n "<pattern>"`
156267
- Read big files in chunks:
157-
- `sed -n '1,200p' path/to/File.java`
158-
- `sed -n '201,400p' path/to/File.java`
268+
- `sed -n '1,200p' path/to/File.java`
269+
- `sed -n '201,400p' path/to/File.java`
159270

160271
## Autonomy Rules (Act > Ask)
161272
- **Default:** act with assumptions. Document assumptions in your plan and final answer.
162273
- **Keep going:** chain steps without waiting for permission; send short progress updates before long actions.
163274
- **Ask only when:**
164-
- Blocked by sandbox/approvals/network policy or missing secrets.
165-
- The decision is destructive/irreversible, repo‑wide, or impacts public APIs.
166-
- Adding dependencies, changing build profiles, or altering licensing.
275+
- Blocked by sandbox/approvals/network policy or missing secrets.
276+
- The decision is destructive/irreversible, repo‑wide, or impacts public APIs.
277+
- Adding dependencies, changing build profiles, or altering licensing.
167278
- **Prefer reversible moves:** take the smallest local change that unblocks progress; validate with targeted tests before expanding scope.
168279
- **Choose defaults**
169-
- **Tests:** start with `-pl <module>`, then `-Dtest=Class#method` / `-Dit.test=ITClass#method`.
170-
- **Build:** use `-o` quick/profiled commands; briefly drop `-o` to fetch missing deps, then return offline.
171-
- **Formatting:** run formatter/impsort/xml‑format proactively before verify.
172-
- **Reports:** read surefire/failsafe locally; expand scope only when necessary.
280+
- **Tests:** start with `-pl <module>`, then `-Dtest=Class#method` / `-Dit.test=ITClass#method`.
281+
- **Build:** use `-o` quick/profiled commands; briefly drop `-o` to fetch missing deps, then return offline.
282+
- **Formatting:** run formatter/impsort/xml‑format proactively before verify.
283+
- **Reports:** read surefire/failsafe locally; expand scope only when necessary.
173284
- **Error handling**
174-
- On compile/test failure: fix root cause locally, rerun targeted tests, then broaden.
175-
- On flaky tests: rerun class/method; stabilize cause before repo‑wide runs.
176-
- On formatting/license issues: apply prescribed commands/headers immediately.
285+
- On compile/test failure: fix root cause locally, rerun targeted tests, then broaden.
286+
- On flaky tests: rerun class/method; stabilize cause before repo‑wide runs.
287+
- On formatting/license issues: apply prescribed commands/headers immediately.
177288
- **Communication**
178-
- **Preambles:** 1–2 sentences grouping upcoming actions.
179-
- **Updates:** inform to maintain visibility; do **not** request permission unless in “Ask only when” above.
289+
- **Preambles:** 1–2 sentences grouping upcoming actions.
290+
- **Updates:** inform to maintain visibility; do **not** request permission unless in “Ask only when” above.
180291

181292
## Answer Template (Use This)
182293
- **What changed:** summary of approach and rationale.
@@ -189,23 +300,23 @@ Do **not** modify existing headers’ years.
189300

190301
## Running Tests
191302
- By module:
192-
- `mvn -o -pl core/sail/shacl verify | tail -500`
303+
- `mvn -o -pl core/sail/shacl verify | tail -500`
193304
- Entire repo:
194-
- `mvn -o verify` (long; only when appropriate)
305+
- `mvn -o verify` (long; only when appropriate)
195306
- Useful flags:
196-
- `-Dtest=ClassName`
197-
- `-Dtest=ClassName#method`
198-
- `-Dit.test=ITClass#method`
199-
- `-DtrimStackTrace=false`
307+
- `-Dtest=ClassName`
308+
- `-Dtest=ClassName#method`
309+
- `-Dit.test=ITClass#method`
310+
- `-DtrimStackTrace=false`
200311

201312
## Build
202313
- **Build without tests (fast path):**
203-
- `mvn -o -Pquick verify`
314+
- `mvn -o -Pquick verify`
204315
- **Verify with tests:**
205-
- Targeted module(s): `mvn -o -pl <module> verify`
206-
- Entire repo: `mvn -o verify` (use only when appropriate)
316+
- Targeted module(s): `mvn -o -pl <module> verify`
317+
- Entire repo: `mvn -o verify` (use only when appropriate)
207318
- **When offline fails due to missing deps:**
208-
- Re‑run the **exact** command **without** `-o` once to fetch, then return to `-o`.
319+
- Re‑run the **exact** command **without** `-o` once to fetch, then return to `-o`.
209320

210321
## Maven Module Overview
211322

@@ -255,7 +366,7 @@ rdf4j: root project
255366
├── queryalgebra: Query algebra model and evaluation.
256367
│ ├── model: A generic query algebra for RDF queries.
257368
│ ├── evaluation: Evaluation strategy API and implementations for the query algebra model.
258-
│ └── geosparql: Query algbebra implementations to support the evaluation of GeoSPARQL.
369+
│ └── geosparql: Query algebra implementations to support the evaluation of GeoSPARQL.
259370
├── queryparser: Query parser API and implementations.
260371
│ ├── api: Query language parsers API.
261372
│ └── sparql: Query language parser implementation for SPARQL.

0 commit comments

Comments
 (0)