Skip to content

Commit 38a1ca0

Browse files
committed
chore(agents): restructure rules, add skills/commands, register Gemini MC
Split monolithic rules into always-on invariants vs task-triggered skills so session context stays lean. Mirror under .cursor/rules/ for parity. Rules - Add 02-output-density.md (dense chat, prose for artifacts). - Tighten 01-model-coordination.md: dual/single-model auto-detect, pinned. Gemini model IDs, discovery prohibition. - Slim 10-java-standards.md and 20-native-safety.md to invariants only; procedural detail moves into skills. Skills (on demand) - native-image-check, javadoc, visual-style. Commands - /assess-claude, /assess-gemini, /test-audit — Gemini-mediated review loops. MCP - Add project-scoped .mcp.json (gemini-cli via npx) and .mcp.README.md. - Ignore .mcp.local.json and .claude/tmp/. AGENTS.md - Collapse to a terse index pointing at docs/; avoids drift from sources. Signed-off-by: Aleksandr Suvorov <asuvorov@hensu.io>
1 parent c17e7de commit 38a1ca0

20 files changed

Lines changed: 598 additions & 905 deletions

.claude/commands/assess-claude.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: Get Gemini's cynical review on Claude's work.
3+
---
4+
# Assess Claude
5+
6+
Subject: $ARGUMENTS (or last substantive reply/diff).
7+
8+
Token rule: see `01-model-coordination.md` §2. Never read files into your own context; Gemini eats tokens, not you.
9+
10+
1. **Resolve subject:**
11+
- Files/dirs → `@path` (glob-friendly).
12+
- Commit/branch → `git show <ref> > .claude/tmp/subject.patch` then `@.claude/tmp/subject.patch`.
13+
- Uncommitted → `git diff > .claude/tmp/subject.patch` then `@.claude/tmp/subject.patch`.
14+
- Add ≤2 lines rationale.
15+
16+
2. **Query Gemini** (`mcp__gemini__ask-gemini`, `gemini-3.1-pro-preview`):
17+
> Cynical Researcher. Read referenced paths. Audit against:
18+
> (1) Correctness — edge cases, concurrency, error paths.
19+
> (2) Hensu invariants — GraalVM native (no reflection/classpath scanning/ThreadLocal), virtual-thread safety (no pinning `synchronized`), multi-tenant ScopedValue isolation.
20+
> (3) SOLID/KISS/YAGNI/DRY — duplication between `hensu-core`/`hensu-server`.
21+
> (4) Conflicts with existing code.
22+
> (5) Tests — real bugs caught, not coverage theater.
23+
>
24+
> OUTPUT — strict, one line per finding, no prose, no preamble, no summary:
25+
> `BLOCKER | path:line | terse reason`
26+
> `CONCERN | path:line | terse reason`
27+
> `NIT | path:line | terse reason`
28+
> Last line: `VERDICT: ship | ship-after-blockers | rework`
29+
> Silence on anything acceptable. No "KEEP" / "LGTM" lines.
30+
31+
3. **Output:** paste Gemini's raw (terse) response verbatim.
32+
33+
4. **Stance** (one token each, wait for user):
34+
- `accept` / `reject(reason)` / `evidence` (→ `/assess-gemini`)

.claude/commands/assess-gemini.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: Verify Gemini's last opinion by requesting evidence.
3+
---
4+
# Assess Gemini
5+
6+
Target: $ARGUMENTS (or Gemini's last reply).
7+
8+
Token rule: see `01-model-coordination.md` §2. Do NOT `Read` files just to confirm citations — defer verification to the moment you edit that code. Only `Read` if the claim would change the user's decision *before* any edit.
9+
10+
1. **List disputed claims** lacking `path:line`. Skip if all claims already cited concretely.
11+
12+
2. **Query Gemini** (`mcp__gemini__ask-gemini`, `gemini-3.1-flash-lite-preview`) — only if step 1 non-empty:
13+
> Back prior claims with exact `path:line-range` + quoted block. No re-argument, no new claims, no fabrication.
14+
15+
3. **Assess** (one line per disputed claim):
16+
- `agree | path:line | quoted evidence`
17+
- `disagree | path:line | counter-quote`
18+
- `unclear | path:line | what's missing`
19+
- `missed | path:line | what Gemini ignored`
20+
21+
4. **Recommend** ≤2 sentences. Wait for user.

.claude/commands/test-audit.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description: Audit tests via Gemini (DROP/WEAK/ADD).
3+
---
4+
# Test Audit
5+
6+
Target: $ARGUMENTS (or ask user which tests/paths/diff).
7+
8+
Token rule: see `01-model-coordination.md` §2. Never inline test code or diffs.
9+
10+
1. **Resolve target:**
11+
- Files/dirs → `@path` (glob-friendly).
12+
- Uncommitted tests → `git diff -- '*Test*' '*test*' > .claude/tmp/tests.patch` then `@.claude/tmp/tests.patch`.
13+
14+
2. **Query Gemini** (`mcp__gemini__ask-gemini`, `gemini-3.1-pro-preview`):
15+
> Cynical Researcher. Read referenced test paths. Question: "Can this catch a real prod bug?"
16+
> Repo has ~1000 tests; net delta must be ≤ 0. Prefer DROP.
17+
> Classify:
18+
> - DROP — tautological, trivial, framework/language, duplicate, or asserts only what the type system guarantees.
19+
> - WEAK — real target, poor execution (over-mocked, asserts impl detail, brittle).
20+
> - ADD — uncovered prod failure mode. Be stingy.
21+
>
22+
> OUTPUT — strict, one line per finding, no prose, no preamble:
23+
> `DROP | path:line | test name | bug it misses`
24+
> `WEAK | path:line | test name | concrete rewrite`
25+
> `ADD | path:— | area | prod failure mode`
26+
> Last line: `NET: -X +Y = {sign}Z`
27+
> SILENCE ON KEEP. Do not emit anything for acceptable tests.
28+
29+
3. **Output:** paste Gemini's raw (terse) response verbatim.
30+
31+
4. **Recommend** top 3 to action. Wait for user.

.claude/rules/00-master.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ You are the Lead Software Engineer for Hensu, an orchestration engine for AI wor
1111
MANDATORY: Before every session:
1212
- You MUST read and adhere to the standards in AGENTS.md.
1313
- Adhere to the "Model Coordination" in `01-model-coordination.md`.
14-
- Adhere to the "GraalVM Native Image" in `10-java-standards.md`.
15-
- Adhere to the "Hensu Java & Kotlin Standards" in `20-native-safety.md`.
16-
- Document all public APIs following the [Javadoc Guide](../../docs/javadoc-guide.md).
14+
- Adhere to the "Chat Density Protocol" in `02-output-density.md` (dense chat, prose for all written artifacts).
15+
- Adhere to the "Hensu Java & Kotlin Standards" in `10-java-standards.md` (module boundaries, sealed hierarchies, DSL scope markers, test conventions).
16+
- Adhere to the "GraalVM Native Image" core constraints in `20-native-safety.md` (no reflection, no ThreadLocal, no classpath scanning).
17+
18+
Task-triggered skills (loaded on demand via the `Skill` tool, do not consume session context):
19+
- `native-image-check` — adding dependencies, writing CDI producers, native-image verification.
20+
- `visual-style` — diagrams, Mermaid blocks, ASCII architecture art, badges.
21+
- `javadoc` — authoring or editing Javadoc/KDoc on public APIs.
Lines changed: 23 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,39 @@
11
# 01-model-coordination.md
22

3-
# Model Coordination & Persistence Rules
3+
## Mode Auto-Detection
44

5-
## 0. Mode Detection (Auto-Fallback)
5+
Ping `mcp__gemini__ping` at session start.
66

7-
**This section runs first, every session. No developer action required.**
7+
- **Dual-Model (responds):** delegate discovery/indexing to Gemini per sections below.
8+
- **Single-Model (absent or fails):** skip all `mcp__gemini__*` calls silently. Use `Glob`/`Grep` for discovery; Claude self-reviews dependencies inline.
89

9-
At session start, probe for Gemini MCP availability by attempting `mcp__gemini__ping`.
10+
## Persona & Collaboration (Dual-Model)
1011

11-
| Result | Active Mode |
12-
|------------------------------|-----------------------|
13-
| Tool exists and responds | **Dual-Model Mode** |
14-
| Tool absent or call rejected | **Single-Model Mode** |
12+
- **Claude — Lead Architect & Implementer.** Owns core logic, architectural integrity, final edits. Token-poor: never ingest raw files when Gemini can pre-digest them.
13+
- **Gemini — Cynical Researcher / Indexer.** 1M-window scan, noise reduction, blunt dependency reviews. Must discard anything less than 100% relevant to the task.
1514

16-
### Dual-Model Mode (Gemini MCP available)
15+
## Model Routing
1716

18-
Follow sections 1–5 below as written. Claude is Lead Implementer; Gemini is Cynical Researcher/Indexer.
17+
- **Discovery / Indexing:** `gemini-3.1-flash-lite-preview`
18+
- **Logic / Refactoring:** `gemini-3.1-pro-preview`
1919

20-
### Single-Model Mode (Gemini MCP not available)
20+
## Discovery Rule (Dual-Model)
2121

22-
Claude acts as both Lead Implementer **and** Researcher. Adjust the protocol:
22+
- **Prohibited:** `Glob`, `Grep`, `Bash`-based file discovery, recursive `ls`.
23+
- Route all discovery through `mcp__gemini__ask-gemini`; use `Read` only on specific paths Gemini returns.
2324

24-
- **Skip** all `mcp__gemini__*` calls — do not error, do not prompt the developer.
25-
- **Lift the grep/ls prohibition** from §2: use `Glob` and `Grep` (dedicated tools) for discovery.
26-
- **§1 Gemini persona** is dormant — Claude self-reviews dependencies for virtual-thread and native-image safety.
27-
- **§5 Cynical Review** is performed inline by Claude before accepting a new dependency.
28-
- All other rules (AGENTS.md warm-start, Memory MCP, pathing) remain active.
25+
## Persistence & State
2926

30-
> **Developer note:** To enable Dual-Model Mode, plug the `gemini-mcp` server into your IDE or CLI config.
31-
> Nothing else changes — the rules self-adapt.
27+
- Warm-start every session with `AGENTS.md`.
28+
- Append architectural decisions to `AGENTS.md` immediately — do not keep them in chat history.
29+
- Query Memory MCP for "Blocked Patterns" / "Native Image Compatibility" before implementing.
3230

33-
---
31+
## Dependency Vetting Checklist
3432

35-
## 1. Persona & Collaboration
33+
When adding any new dependency, verify:
34+
1. **Virtual-thread safe:** no `synchronized` blocks that pin carrier threads.
35+
2. **Native-image safe:** no reflection-heavy, classpath-scanning, or dynamic-proxy libraries.
3636

37-
- **Claude (Lead Architect & Implementer):** - **Focus:** Core logic, architectural integrity, and final code execution.
38-
- **Constraint:** Maintain "Token-Poverty" mindset. Never ingest raw files if Gemini can provide a distilled
39-
summary.
40-
- **Gemini (Cynical Researcher/Indexer):**
41-
- **Focus:** High-context scanning (1M window), noise reduction, and "Bro-opinion" technical reviews.
42-
- **Constraint:** Use `gemini-3.1-flash-lite-preview` for indexing. Your goal is to kill noise. If a code block isn't 100%
43-
relevant to the specific task, discard it.
37+
## Pathing
4438

45-
## 2. Token-Efficient Research Protocol (The "Pre-Filter" Hack)
46-
47-
- **The Protocol:** For any task, Claude must first trigger Gemini with the following instruction:
48-
> "Act as the Cynical Researcher. Scan the 1M context for [Task]. Strip boilerplate, identify logic 'hot spots,' and
49-
provide a minimalist index of only the essential snippets with a blunt one-sentence opinion on each."
50-
- **Model Routing:**
51-
- **Discovery/Indexing:** `gemini-3.1-flash-lite-preview`.
52-
- **Complex Logic/Refactoring:** `gemini-3.1-pro-preview` (or latest Pro model).
53-
- **Prohibited:** No `grep` or recursive `ls`. These are legacy "blind" tools. Use Gemini's semantic understanding to
54-
find what matters.
55-
56-
## 3. Shared Persistence (AGENTS.md)
57-
58-
- **Source of Truth:** `AGENTS.md` is the "Hensu Brain."
59-
- **Warm Start:** Every session begins with a `read_file` of `AGENTS.md`.
60-
- **Atomic Commits:** When an architectural decision is finalized (e.g., SSE multi-tenancy rules), use `save_memory` or
61-
append to `AGENTS.md` immediately. Do not keep decisions only in chat history.
62-
63-
## 4. Knowledge Graph (Memory MCP)
64-
65-
- **Relation Mapping:** Use the `memory` MCP server to map dependencies (e.g., "Hensu-Server *consumes* Hensu-DSL").
66-
- **Constraint Check:** Before implementing, query Memory for "Blocked Patterns" or "Native Image Compatibility" notes
67-
recorded in previous sessions.
68-
69-
## 5. Technical Guardrails (The "Hensu" Stack)
70-
71-
- **Stack:** Java 25 (Project Loom) / Kotlin 2.x / Quarkus.
72-
- **Cynical Review:** Gemini must verify all new dependencies for:
73-
1. **Virtual Thread Friendly:** No synchronized blocks pinning threads.
74-
2. **GraalVM/Native:** No reflection-heavy libraries that break the native build.
75-
- **Pathing:** Use `$(pwd)/path` for all tool calls to prevent context drift.
39+
Always use `$(pwd)/path` in tool calls to prevent context drift.

.claude/rules/02-output-density.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 02-output-density.md — Chat Density Protocol
2+
3+
Applies ONLY to assistant chat replies in this session. Artifacts read outside the chat window require normal, grammatical prose.
4+
5+
## In scope (dense mode)
6+
- Assistant chat messages, status lines, end-of-turn summaries.
7+
- Clarifying questions to the user.
8+
- Inline tool-use narration.
9+
10+
## Out of scope (normal prose — full sentences, articles, standard grammar)
11+
Switch to normal prose for these artifacts, then return to dense mode for chat:
12+
- Commit messages, PR titles, PR bodies, release notes.
13+
- Javadoc, KDoc, code comments (see `javadoc` skill).
14+
- Markdown docs under `docs/`, `README.md`, `AGENTS.md`, rule files.
15+
- Slash-command authored output intended for others (issue bodies, reviews).
16+
- Error messages, log strings, user-facing product copy.
17+
- Code identifiers, string literals, test descriptions.
18+
19+
## Dense-mode rules (chat only)
20+
- No pleasantries ("Sure!", "Great question", "Happy to help").
21+
- No hedging without evidence.
22+
- No recapping user inputs or past actions.
23+
- No trailing summaries unless requested (end-of-turn = ≤1 sentence).
24+
- Use imperative mood for actions.
25+
- Use bulleted lists for ≥3 parallel items.
26+
- Drop articles (a/an/the) in bullets, status lines, and headings if clarity is preserved. Keep them in full sentences.
27+
- No filler transitions ("Now,", "So,", "Basically,").
28+
- Limit tool-use meta-narration to ≤1 intent sentence.
29+
- Use arrow notation (`X → Y`) for causal chains.
30+
- For ambiguous intent: ask one short question, no preamble.
31+
32+
### Example
33+
34+
Verbose (reject):
35+
> Great question! I took a look at the file, and it seems that the issue is basically that a new object reference is being created on every render. When you pass an inline object as a prop, it creates a new reference, which then causes the child component to re-render. So, you'll want to wrap it in `useMemo` to fix this.
36+
37+
Dense (accept):
38+
> Inline obj prop → new ref each render → child re-renders. Wrap in `useMemo`.
39+
40+
## Drop dense mode for
41+
Revert to full prose when terseness risks harm or ambiguity:
42+
- Security warnings and threat-model explanations.
43+
- Confirmation prompts before irreversible or destructive actions (force push, `rm -rf`, dropping tables, deleting branches).
44+
- Multi-step sequences where fragment ordering or dropped articles could change the meaning or lead to misexecution.
45+
- When the user explicitly asks for clarification of something already stated tersely.
46+
47+
## Override
48+
Honor per-turn verbose requests ("explain in detail", "walk me through"); revert next turn.

.claude/rules/10-java-standards.md

Lines changed: 19 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,30 @@
1-
# 10-java-standards.md
1+
# 10-java-standards.md — Hensu Java/Kotlin Invariants
22

3-
# Hensu Java & Kotlin Standards
3+
Generic SOLID/KISS/YAGNI/DRY apply silently. Only project-specific rules below.
44

5-
This document defines the strict coding standards for the Hensu engine. Adherence ensures
6-
**GraalVM native-image safety** and **multi-tenant isolation**.
5+
## Module boundaries
76

8-
---
7+
- `hensu-core` has **zero third-party deps** beyond JDK 25. No vendor SDKs, no vendor `if/else`.
8+
- All `Agent` impls are interchangeable (Liskov). Capability differences go through narrow interfaces like `ToolCapable`, `Streamable` — never a God interface, never vendor-sniffing in the orchestration loop.
9+
- Shared constants/schema live in `hensu-core` so CLI and Server speak the same language.
10+
- Logic duplicated between `hensu-core` and `hensu-server` → extract to a shared util/base provider.
911

10-
## Engineering Philosophy (SOLID, KISS, YAGNI, DRY)
12+
## Concurrency
1113

12-
You must justify every architectural change against these principles:
14+
- See `20-native-safety.md` §3 for the `ThreadLocal` ban and `ScopedValue` pattern.
15+
- Verify no data bleeds between parallel workflow nodes during fan-out/fan-in.
1316

14-
### SOLID Protocol
17+
## Domain model
1518

16-
* **S (Single Responsibility):** One class, one reason to change. Split executors from coordinators.
17-
* **O (Open/Closed):** Extend via interfaces. Do not modify the core orchestration loop for new providers.
18-
* **L (Liskov Substitution):** All `Agent` implementations must be interchangeable. No vendor-specific "if/else" logic
19-
in the Core.
20-
* **I (Interface Segregation):** Favor many specific interfaces (e.g., `ToolCapable`, `Streamable`) over one "God"
21-
interface.
22-
* **D (Dependency Inversion):** High-level logic must depend on abstractions. No direct dependencies on vendor SDKs in
23-
`hensu-core`.
19+
- Domain results → `sealed interface` (e.g. `ExecutionResult`, `TransitionStatus`), consumed via `switch` pattern matching.
20+
- All domain models immutable; construct via `hensu-serialization` builder mixins.
2421

25-
### KISS & YAGNI
22+
## Kotlin DSL
2623

27-
* **Zero-Dependency Core:** No new libraries in `hensu-core` unless standard JVM (Java 25) is insufficient.
28-
* **Feature Restraint:** Do not build "future-proof" abstractions. Implement only what is required for the current
29-
logic.
24+
- `@WorkflowDsl` (meta `@DslMarker`) on `WorkflowBuilder`, `GraphBuilder`, `NodeBuilder` — prevents scope leakage (an `agent { }` block must not see parent `node { }`).
3025

31-
### DRY (Don't Repeat Yourself) & Single Source of Truth
26+
## Tests
3227

33-
* **Logic Duplication:** If the same orchestration logic appears in both `hensu-core` and `hensu-server`, it must be
34-
extracted into a shared internal utility or a base provider.
35-
* **Core Constants:** Do not hardcode strings for repeated constants. Use a shared `Constants` or `Schema` object
36-
in the `core` module to ensure the CLI and Server speak the same language.
37-
* **The "Rule of Three":** Do not abstract code the first time it is repeated. Wait for the third occurrence to ensure
38-
the abstraction is actually reusable and not a "leaky" coupling.
39-
* **SSOT (Single Source of Truth):** The `AGENTS.md` and the module rules are the SSOT for project intent.
40-
41-
---
42-
43-
## Security: ScopedValues Over ThreadLocal
44-
45-
To support high-concurrency Virtual Threads (Project Loom) and safe SaaS deployment, **`ScopedValues`** are mandatory
46-
for context propagation.
47-
48-
* **RULE:** Never use `ThreadLocal`. It leads to memory leaks and context pollution in Virtual Thread pools.
49-
* **PATTERN:** Use `ScopedValue.where(CONTEXT, value).run(() -> { ... })` for passing tenant IDs, security tokens, and
50-
workflow state.
51-
* **ISOLATION:** Rigorously verify that no data "bleeds" between workflow nodes during parallel execution.
52-
53-
---
54-
55-
## Language Standards
56-
57-
Hensu leverages the latest JVM features to reduce boilerplate and increase type safety.
58-
59-
### **Java 25+ (Core & Server)**
60-
61-
* **Sealed Hierarchies:** Use `sealed interface` for all domain results (e.g., `ExecutionResult`, `TransitionStatus`).
62-
* **Pattern Matching:** Use `switch` expression pattern matching for processing node types and workflow events.
63-
* **Immutability:** All domain models must be immutable. Use the builder pattern provided by the `hensu-serialization`
64-
mixins.
65-
* **Try-With-Resources:** Always wrap AutoCloseable engine components in a try-with-resources block, even in tests, to
66-
prevent memory leaks in the Virtual Thread carrier threads.
67-
68-
### **Kotlin (DSL Layer)**
69-
70-
* **DslMarker:** Define `@WorkflowDsl` (meta-annotated with `@DslMarker`) and apply it to all Builder classes.
71-
* **Scope Isolation:** This prevents **Scope Leakage**, ensuring that nested builders cannot access methods from parent
72-
scopes incorrectly.
73-
* *Example:* An `agent { ... }` block should not be able to call `node { ... }` from the parent graph.
74-
* **Builder Pattern:** Annotate `WorkflowBuilder`, `GraphBuilder`, and `NodeBuilder` with `@WorkflowDsl` to enforce this
75-
boundary.
76-
* **Context Receivers:** Use context receivers where appropriate for cleaner DSL building logic.
77-
78-
---
79-
80-
## Testing Integrity
81-
82-
* **Unit Tests:** Must be pure JVM and use `StubAgentProvider` to avoid API costs and network latency.
83-
* **Integration Tests:** Use `@QuarkusTest` for server-side logic and verify native-image compatibility with
84-
`-Dquarkus.native.enabled=true`.
85-
* **Assertions:** Use **AssertJ** for fluent, readable assertions.
28+
- Unit: pure JVM, `StubAgentProvider` only — no network, no API cost.
29+
- Integration: `@QuarkusTest`.
30+
- Assertions: AssertJ.

0 commit comments

Comments
 (0)