@ikieaneh/opencode-kit 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@ikieaneh/opencode-kit",
3
+ "version": "0.5.0",
4
+ "description": "Standardized OpenCode orchestration framework \u2014 contract-based, rules-enforced, zero-touch agent workflow. Install as plugin.",
5
+ "license": "MIT",
6
+ "author": "RizkiRachman",
7
+ "type": "module",
8
+ "main": ".opencode/plugins/opencode-kit.js",
9
+ "exports": {
10
+ ".": {
11
+ "import": ".opencode/plugins/opencode-kit.js"
12
+ }
13
+ },
14
+ "bin": {
15
+ "opencode-kit": "./src/cli.js"
16
+ },
17
+ "files": [
18
+ ".opencode/plugins/",
19
+ ".claude-plugin/",
20
+ "src/",
21
+ "rules/",
22
+ "templates/",
23
+ "skills/"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "keywords": [
29
+ "opencode",
30
+ "opencode-plugin",
31
+ "orchestration",
32
+ "workflow",
33
+ "agents",
34
+ "enforcement",
35
+ "contract",
36
+ "scoring",
37
+ "adr"
38
+ ],
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/RizkiRachman/opencode-kit"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/RizkiRachman/opencode-kit/issues"
45
+ },
46
+ "homepage": "https://github.com/RizkiRachman/opencode-kit#readme"
47
+ }
@@ -0,0 +1,123 @@
1
+ {
2
+ "version": "0.1.0",
3
+ "strict": true,
4
+ "description": "Machine-enforceable rules for OpenCode agents. CRITICAL = BLOCK agent. HIGH = FLAG orchestrator. LOW = advisory.",
5
+
6
+ "state_machine": {
7
+ "transitions": [
8
+ { "from": "INIT", "to": "PLAN", "require_score": null },
9
+ { "from": "PLAN", "to": "PLAN_SCORED", "require_score": null },
10
+ { "from": "PLAN_SCORED", "to": "EXECUTE", "require_score": 70 },
11
+ { "from": "EXECUTE", "to": "EXECUTE_SCORED", "require_score": null },
12
+ { "from": "EXECUTE_SCORED", "to": "REVIEW", "require_score": 70 },
13
+ { "from": "REVIEW", "to": "REVIEW_SCORED", "require_score": null },
14
+ { "from": "REVIEW_SCORED", "to": "COMPLETE", "require_score": 70 },
15
+ { "from": "*", "to": "BLOCKED", "condition": "score < 50 OR retry_attempts >= 3" },
16
+ { "from": "BLOCKED", "to": "INIT", "condition": "user_intervention" }
17
+ ]
18
+ },
19
+
20
+ "rules": [
21
+ {
22
+ "id": "PREFLIGHT_001",
23
+ "severity": "CRITICAL",
24
+ "description": "Agent MUST load contract.json before any tool call",
25
+ "condition": "first_action_not_contract_load",
26
+ "action": "BLOCK",
27
+ "message": "⛔ PREFLIGHT FAILED: contract.json not loaded. Run: lean-ctx ctx_knowledge recall --query \"orchestration-contract\""
28
+ },
29
+ {
30
+ "id": "PREFLIGHT_002",
31
+ "severity": "CRITICAL",
32
+ "description": "Agent MUST NOT work on main branch",
33
+ "condition": "git_branch_is_main",
34
+ "action": "BLOCK",
35
+ "message": "⛔ PREFLIGHT FAILED: Current branch is main. Create a feature branch first."
36
+ },
37
+ {
38
+ "id": "PREFLIGHT_003",
39
+ "severity": "CRITICAL",
40
+ "description": "Agent MUST validate contract.state before proceeding",
41
+ "condition": "contract_state_mismatch",
42
+ "action": "BLOCK",
43
+ "message": "⛔ STATE FAILED: Contract state is ${actual}. Expected one of: ${expected}"
44
+ },
45
+ {
46
+ "id": "IMPACT_001",
47
+ "severity": "CRITICAL",
48
+ "description": "Agent MUST run gitnexus_impact before editing any symbol",
49
+ "condition": "edit_without_impact_analysis",
50
+ "action": "BLOCK",
51
+ "message": "⛔ IMPACT FAILED: Edit attempted without gitnexus_impact analysis. Run: gitnexus_impact({target, direction: \"upstream\"})"
52
+ },
53
+ {
54
+ "id": "PERSIST_001",
55
+ "severity": "HIGH",
56
+ "description": "Agent MUST persist contract after every delegation/phase change",
57
+ "condition": "delegation_without_persist",
58
+ "action": "FLAG",
59
+ "message": "⚠️ PERSIST WARNING: Contract not persisted after delegation. Run: lean-ctx ctx_knowledge remember category architecture key orchestration-contract value <updated JSON>"
60
+ },
61
+ {
62
+ "id": "SCORE_001",
63
+ "severity": "HIGH",
64
+ "description": "Scoring MUST be computed after each subagent returns",
65
+ "condition": "delegation_returned_without_scoring",
66
+ "action": "FLAG",
67
+ "message": "⚠️ SCORE WARNING: Subagent output not scored. Run scoring pipeline (Tier 1 rules + Tier 2 judge)"
68
+ },
69
+ {
70
+ "id": "WRITE_001",
71
+ "severity": "CRITICAL",
72
+ "description": "Agent MUST follow writing order: Port → Service → Mapper → Adapter → Constants → Events → Tests",
73
+ "condition": "writing_order_violation",
74
+ "action": "FLAG",
75
+ "message": "⚠️ WRITING ORDER: Files created in wrong order. Expected order: port → service → mapper → adapter → constants → events → tests"
76
+ },
77
+ {
78
+ "id": "BRANCH_001",
79
+ "severity": "HIGH",
80
+ "description": "Agent MUST push feature branch before significant work",
81
+ "condition": "significant_work_without_push",
82
+ "action": "FLAG",
83
+ "message": "⚠️ BRANCH WARNING: Feature branch exists but not pushed. Run: git push -u origin $(git branch --show-current)"
84
+ },
85
+ {
86
+ "id": "LEARN_001",
87
+ "severity": "HIGH",
88
+ "description": "Learner agent MUST update ALL 11 memory systems in post-flight matrix",
89
+ "condition": "learner_skipped_memory_system",
90
+ "action": "FLAG",
91
+ "message": "⚠️ LEARNER WARNING: Not all memory systems updated. See AGENTS.md §1.7 for full matrix."
92
+ },
93
+ {
94
+ "id": "SCORE_002",
95
+ "severity": "HIGH",
96
+ "description": "Tier 2 LLM judge MUST use the canonical judge prompt from rules.json scoring.tier2.judge_prompt or templates/judge-prompt.md",
97
+ "condition": "judge_prompt_not_from_canonical_source",
98
+ "action": "FLAG",
99
+ "message": "⚠️ SCORE WARNING: Judge prompt must use canonical source. See .opencode/rules/rules.json scoring.tier2.judge_prompt"
100
+ }
101
+ ],
102
+
103
+ "scoring": {
104
+ "tier1": {
105
+ "schema_valid_deduction": 15,
106
+ "permissions_violated_deduction": 40,
107
+ "blast_radius_high_deduction": 40,
108
+ "writing_order_wrong_deduction": 15,
109
+ "required_fields_missing_deduction": 15,
110
+ "subtotal_threshold": 70
111
+ },
112
+ "tier2": {
113
+ "enabled": true,
114
+ "judge_prompt": "You are an impartial judge evaluating an AI agent's output. Score 0-100 based on: (1) Requirements fulfillment 0-40, (2) Governance compliance 0-30, (3) Completeness 0-20, (4) Edge cases and risks 0-10. Return JSON: { score: N, rationale: '...', missing_items: [...] }"
115
+ },
116
+ "thresholds": {
117
+ "pass": 70,
118
+ "retry": 50,
119
+ "max_attempts": 3,
120
+ "escalation": 50
121
+ }
122
+ }
123
+ }
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env bash
2
+ # opencode-kit rules validation — validate agent actions against rules.json
3
+ # Usage: bash rules/validation.sh [--strict]
4
+ # --strict: treat HIGH rules as BLOCK (default: FLAG only)
5
+ set -euo pipefail
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
8
+ . "$SCRIPT_DIR/src/platform.sh"
9
+
10
+ RULES_FILE=".opencode/rules/rules.json"
11
+ CONTRACT_FILE=".opencode/orchestration/contract.json"
12
+
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ CYAN='\033[0;36m'
17
+ NC='\033[0m'
18
+
19
+ STRICT="${1:-}"
20
+
21
+ echo "[opencode-kit] 🔍 Rules Validation"
22
+ echo ""
23
+
24
+ # --- Check rules.json exists ---
25
+ if [ ! -f "$RULES_FILE" ]; then
26
+ echo -e "${RED}❌ $RULES_FILE not found. Cannot validate.${NC}"
27
+ exit 1
28
+ fi
29
+
30
+ # --- Check contract.json exists ---
31
+ if [ ! -f "$CONTRACT_FILE" ]; then
32
+ echo -e "${RED}❌ $CONTRACT_FILE not found. Cannot validate state.${NC}"
33
+ exit 1
34
+ fi
35
+
36
+ # --- Parse rules.json using python or jq ---
37
+ if [ -n "$PYTHON_CMD" ]; then
38
+ PARSE_CMD="$PYTHON_CMD -c"
39
+ elif command -v jq &>/dev/null; then
40
+ PARSE_CMD="jq -r"
41
+ else
42
+ echo -e "${RED}❌ Neither Python nor jq found. Cannot parse rules.json.${NC}"
43
+ exit 1
44
+ fi
45
+
46
+ echo " Rules file: $RULES_FILE"
47
+ echo " Contract: $CONTRACT_FILE"
48
+ echo ""
49
+
50
+ TOTAL_VIOLATIONS=0
51
+ CRITICAL_VIOLATIONS=0
52
+ HIGH_VIOLATIONS=0
53
+
54
+ # --- Validate 1: Branch rule ---
55
+ echo -e "${CYAN}[PREFLIGHT_002]${NC} Branch validation..."
56
+ BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
57
+ if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
58
+ echo -e "${RED} ❌ VIOLATION: On '$BRANCH' branch${NC}"
59
+ echo " → Create a feature branch: git checkout -b feature/<YYYYMMDD>-<description>"
60
+ CRITICAL_VIOLATIONS=$((CRITICAL_VIOLATIONS + 1))
61
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + 1))
62
+ else
63
+ echo " ✅ Branch: $BRANCH (safe)"
64
+ fi
65
+
66
+ # --- Validate 2: Contract state ---
67
+ echo -e "${CYAN}[STATE_001]${NC} Contract state validation..."
68
+ STATE=$($PYTHON_CMD -c "
69
+ import json
70
+ with open('$CONTRACT_FILE') as f: d=json.load(f)
71
+ print(d.get('state','UNKNOWN'))
72
+ " 2>/dev/null)
73
+ VALID_STATES="INIT PLAN PLAN_SCORED EXECUTE EXECUTE_SCORED REVIEW REVIEW_SCORED COMPLETE BLOCKED"
74
+ if echo "$VALID_STATES" | grep -qw "$STATE"; then
75
+ echo " ✅ State: $STATE (valid)"
76
+ else
77
+ echo -e "${RED} ❌ VIOLATION: Invalid state '$STATE'${NC}"
78
+ echo " → Valid states: $VALID_STATES"
79
+ CRITICAL_VIOLATIONS=$((CRITICAL_VIOLATIONS + 1))
80
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + 1))
81
+ fi
82
+
83
+ # --- Validate 3: Contract has required fields ---
84
+ echo -e "${CYAN}[SCHEMA_001]${NC} Contract schema validation..."
85
+ $PYTHON_CMD -c "
86
+ import json, sys
87
+ with open('$CONTRACT_FILE') as f: d=json.load(f)
88
+ errors = []
89
+ if not d.get('requirements',{}).get('goal'): errors.append('requirements.goal is empty')
90
+ if d.get('score',{}).get('combined') is None: errors.append('score.combined is missing')
91
+ if d.get('state') not in ['INIT','PLAN','PLAN_SCORED','EXECUTE','EXECUTE_SCORED','REVIEW','REVIEW_SCORED','COMPLETE','BLOCKED']:
92
+ errors.append('state is invalid')
93
+ if errors:
94
+ print('VIOLATION:' + '; '.join(errors))
95
+ sys.exit(1)
96
+ else:
97
+ print('OK')
98
+ " 2>&1 || true
99
+ # (soft check — don't block)
100
+
101
+ # --- Validate 4: gitnexus impact check (if git diff shows changes) ---
102
+ echo -e "${CYAN}[IMPACT_001]${NC} Impact analysis check..."
103
+ if git diff --stat HEAD 2>/dev/null | grep -q .; then
104
+ echo -e "${YELLOW} ⚠️ Uncommitted changes detected — run gitnexus_impact before editing${NC}"
105
+ HIGH_VIOLATIONS=$((HIGH_VIOLATIONS + 1))
106
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + 1))
107
+ else
108
+ echo " ✅ No uncommitted changes (or changes already analyzed)"
109
+ fi
110
+
111
+ # --- Validate 5: Contract persisted check (lean-ctx) ---
112
+ echo -e "${CYAN}[PERSIST_001]${NC} Persistence check..."
113
+ if command -v lean-ctx &>/dev/null; then
114
+ if lean-ctx ctx_knowledge recall --query "orchestration-contract" &>/dev/null; then
115
+ echo " ✅ Contract persisted in lean-ctx"
116
+ else
117
+ echo -e "${YELLOW} ⚠️ Contract NOT found in lean-ctx — persist after changes${NC}"
118
+ HIGH_VIOLATIONS=$((HIGH_VIOLATIONS + 1))
119
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + 1))
120
+ fi
121
+ else
122
+ echo -e "${YELLOW} ⚠️ lean-ctx not available — cannot verify persistence${NC}"
123
+ fi
124
+
125
+ # --- Summary ---
126
+ echo ""
127
+ echo "[opencode-kit] 📊 Validation Summary"
128
+ echo " CRITICAL violations: $CRITICAL_VIOLATIONS"
129
+ echo " HIGH violations: $HIGH_VIOLATIONS"
130
+ echo " Total violations: $TOTAL_VIOLATIONS"
131
+ echo ""
132
+
133
+ if [ "$TOTAL_VIOLATIONS" -eq 0 ]; then
134
+ echo -e "${GREEN}[opencode-kit] ✅ All rules validated. No violations.${NC}"
135
+ exit 0
136
+ elif [ "$CRITICAL_VIOLATIONS" -gt 0 ]; then
137
+ echo -e "${RED}[opencode-kit] ❌ CRITICAL violations found. Run preflight.sh to identify blockers.${NC}"
138
+ exit 1
139
+ elif [ "$STRICT" = "--strict" ] && [ "$HIGH_VIOLATIONS" -gt 0 ]; then
140
+ echo -e "${YELLOW}[opencode-kit] ⛔ HIGH violations in strict mode. Fix before proceeding.${NC}"
141
+ exit 1
142
+ else
143
+ echo -e "${YELLOW}[opencode-kit] ⚠️ HIGH violations found (FLAG only — non-blocking).${NC}"
144
+ exit 0
145
+ fi
@@ -0,0 +1,42 @@
1
+ ---
2
+ description: Auto-generate Architecture Decision Records when making architectural decisions. Logs to contract.json decisions.adr_log[].
3
+ ---
4
+
5
+ # ADR Generator
6
+
7
+ When making an architectural decision, record it in `contract.json` → `decisions.adr_log[]`.
8
+
9
+ ## ADR Format
10
+
11
+ ```json
12
+ {
13
+ "id": "ADR-003",
14
+ "date": "2026-06-11",
15
+ "title": "Decision title",
16
+ "context": "Why this decision was needed",
17
+ "decision": "What was decided",
18
+ "alternatives": "What was considered and rejected",
19
+ "consequences": "Positive and negative effects"
20
+ }
21
+ ```
22
+
23
+ ## When to Record
24
+
25
+ - Any non-trivial architectural choice
26
+ - Any rejected approach that future agents might propose again
27
+ - Any convention or rule change
28
+ - When asked "is this decision recorded?"
29
+
30
+ ## Auto-ID
31
+
32
+ - Read existing `adr_log[]` from contract
33
+ - Next ID = max ADR-NNN + 1
34
+ - If no existing log, start at ADR-001
35
+
36
+ ## CLI Alternative
37
+
38
+ ```sh
39
+ bash src/adr.sh --title "..." --context "..." --decision "..." --alternatives "..." --consequences "..."
40
+ ```
41
+
42
+ The CLI script handles ID assignment, duplicate detection, and contract injection automatically.
@@ -0,0 +1,44 @@
1
+ ---
2
+ description: Post-execution learning agent. Extract lessons, persist knowledge, update memory systems.
3
+ ---
4
+
5
+ # Learner Agent
6
+
7
+ Run after every completed task. You are the last agent — you make learning durable.
8
+
9
+ ## Mandatory: Update ALL Memory Systems
10
+
11
+ | System | Tool | What to Do |
12
+ |--------|------|------------|
13
+ | lean-ctx knowledge | `ctx_knowledge remember` | Persist gotchas, patterns, decisions |
14
+ | STATE.md | Append | Append completed work, update focus |
15
+ | Orchestration contract | `ctx_knowledge remember` | Set state=COMPLETE, append lessons |
16
+ | gitnexus | `npx gitnexus analyze` | Re-index code intelligence |
17
+ | Handoff pack | memory-mcp | Label: `handoff.learner.<task_id>` |
18
+ | ctx_session | `ctx_session save` | Persist conversation |
19
+
20
+ ## Extract Three Categories
21
+
22
+ ### What went well (1-3)
23
+ - Decisions/patterns that led to smooth execution
24
+ - Should this be a permanent pattern?
25
+
26
+ ### What went wrong (1-3)
27
+ - Where was time/tokens wasted?
28
+ - What blocked progress or required rework?
29
+
30
+ ### What to change next time (1-2)
31
+ - Concrete, actionable — not vague advice
32
+ - "Always load contract before edits" not "be more careful"
33
+
34
+ ## Output Format
35
+
36
+ ```json
37
+ {
38
+ "lessons_learned": ["What went well: ...", "What went wrong: ..."],
39
+ "knowledge_updates": [
40
+ { "category": "gotchas", "key": "...", "value": "...", "severity": "warning" }
41
+ ],
42
+ "next_session_tips": "..."
43
+ }
44
+ ```
@@ -0,0 +1,41 @@
1
+ ---
2
+ description: MANDATORY — Load orchestration contract before any work. Validates state, branch, phase.
3
+ ---
4
+
5
+ # Orchestration Template
6
+
7
+ **MANDATORY on EVERY task start.** Forces agent to load contract from lean-ctx BEFORE any work.
8
+
9
+ ## Contract Protocol
10
+
11
+ 1. **LOAD** — Run: `lean-ctx ctx_knowledge recall --query "orchestration-contract"`
12
+ - If found: extract state, session, requirements, decisions, governance
13
+ - If NOT found: check `.opencode/orchestration/contract.json` → create fresh
14
+
15
+ 2. **VALIDATE** — Check state transition is legal per rules.json state_machine
16
+ - If illegal: set state=BLOCKED, persist, STOP
17
+
18
+ 3. **PERSIST** — After every delegation or phase change:
19
+ ```
20
+ lean-ctx ctx_knowledge remember \
21
+ category architecture \
22
+ key orchestration-contract \
23
+ value "<updated JSON>"
24
+ ```
25
+
26
+ ## State Machine
27
+
28
+ ```
29
+ INIT → PLAN → PLAN_SCORED → EXECUTE → EXECUTE_SCORED → REVIEW → REVIEW_SCORED → COMPLETE
30
+
31
+ BLOCKED (any phase) → user intervention → retry
32
+ ```
33
+
34
+ **Transition Rules:**
35
+ - Each phase transition requires score ≥ 70 to proceed
36
+ - Score < 50 → BLOCKED
37
+ - Max 3 retry attempts
38
+
39
+ ## Rules References
40
+ - `rules.json` — machine-readable enforcement rules
41
+ - `contract.json` — shared state contract
@@ -0,0 +1,26 @@
1
+ ---
2
+ description: Quality assurance — test strategy, coverage analysis, edge case detection, regression prevention.
3
+ ---
4
+
5
+ # QA Expert
6
+
7
+ ## Test Standards
8
+
9
+ - **One assertion per test** — each test validates exactly one behavior
10
+ - **Cover all branches** — happy path, empty, null, boundary, error
11
+ - **Test alongside code** — write tests in same phase as implementation, not after
12
+
13
+ ## Edge Cases to Check
14
+
15
+ - Null/empty inputs for every param
16
+ - Boundary values (max length, pagination limits, date ranges)
17
+ - Concurrent access (if shared state exists)
18
+ - Timeout failures, network retries
19
+ - Malformed data (bad JSON, wrong types)
20
+
21
+ ## Coverage Goals
22
+
23
+ - Domain services: ≥ 95% instruction coverage
24
+ - Adapters (web/persistence): ≥ 85%
25
+ - Mappers: ≥ 100% (trivial mappings can still break)
26
+ - Overall project: ≥ 90%
@@ -0,0 +1,43 @@
1
+ ---
2
+ description: Score every subagent output after delegation. Tier 1 (rule checks) + Tier 2 (LLM judge) + verdict.
3
+ ---
4
+
5
+ # Scoring Pipeline
6
+
7
+ After every subagent delegation returns, run three-tier scoring before proceeding.
8
+
9
+ ## Tier 1 — Rule-Based Checks
10
+
11
+ Start at 100. Deduct for each violation:
12
+
13
+ | Check | Deduction |
14
+ |-------|:---------:|
15
+ | Schema valid (required fields present) | -15 |
16
+ | Permissions violated (forbidden patterns) | -40 |
17
+ | Blast radius unsafe (HIGH/CRITICAL) | -40 |
18
+ | Writing order wrong | -15 |
19
+ | Required fields missing | -15 |
20
+
21
+ If subtotal < 70 → skip Tier 2, use subtotal as combined score.
22
+
23
+ ## Tier 2 — LLM Judge
24
+
25
+ Use prompt from `.opencode/rules/rules.json` → `scoring.tier2.judge_prompt`:
26
+
27
+ ```
28
+ Score 0-100 on:
29
+ - Fulfills requirements? (0-40)
30
+ - Follows governance? (0-30)
31
+ - Completeness? (0-20)
32
+ - Edge cases covered? (0-10)
33
+ ```
34
+
35
+ Return JSON: `{ "score": N, "rationale": "...", "missing_items": [...] }`
36
+
37
+ ## Tier 3 — Verdict
38
+
39
+ | Score | Verdict | Action |
40
+ |:-----:|---------|--------|
41
+ | ≥ 70 | PASS | Advance to next phase |
42
+ | 50–69 | RETRY | Fix issues (if attempt < max) |
43
+ | < 50 | BLOCKED | Escalate to user |
@@ -0,0 +1,28 @@
1
+ ---
2
+ description: System analysis — architecture evaluation, dependency mapping, impact analysis, execution trace.
3
+ ---
4
+
5
+ # System Analyst
6
+
7
+ ## Before Touching Code
8
+
9
+ 1. **Trace the execution flow**: Use `gitnexus_query` to find processes related to the change
10
+ 2. **Map dependencies**: Run `gitnexus_impact({target, direction: "upstream"})` — report blast radius
11
+ 3. **Check the knowledge graph**: `graphify query "<question>"` — find how components connect
12
+ 4. **Identify communities**: What functional areas does this touch?
13
+
14
+ ## Impact Analysis Guide
15
+
16
+ | Risk Level | Meaning | Action |
17
+ |:----------:|---------|--------|
18
+ | LOW | 0-3 consumers | Safe to change |
19
+ | MEDIUM | 4-9 consumers | Flag orchestrator |
20
+ | HIGH | 10+ consumers | BLOCK — get approval |
21
+ | CRITICAL | Core infrastructure | BLOCK — design review required |
22
+
23
+ ## Architecture Checklist
24
+
25
+ - [ ] Hexagonal boundaries respected? (domain doesn't import infrastructure)
26
+ - [ ] No JPA annotations in domain models?
27
+ - [ ] Ports return nullable, not Optional?
28
+ - [ ] Writing order correct? (Port → Service → Mapper → Adapter → Constants → Events → Tests)
@@ -0,0 +1,32 @@
1
+ ---
2
+ description: Guidelines for efficient token usage — read strategically, batch operations, minimize context.
3
+ ---
4
+
5
+ # Token Optimization
6
+
7
+ ## Reading Strategy
8
+
9
+ - **Search before read**: use `gitnexus_query` or `grep` before reading files
10
+ - **Read sections, not whole files**: use `ctx_read(path, mode: "lines:N-M")`
11
+ - **Use `ctx_read` compression modes**: `map` for structure, `signatures` for signatures, `full` only when needed
12
+ - **Cache re-reads**: `ctx_read` is cached — subsequent reads of unchanged files cost ~13 tok
13
+
14
+ ## Batching
15
+
16
+ - **Batch independent reads**: Use `ctx_multi_read` to read multiple files in one call
17
+ - **Batch independent writes**: Use `write` calls in parallel
18
+ - **Batch grep patterns**: Combine related patterns in a single grep call
19
+
20
+ ## Delegation
21
+
22
+ - **Delegate discovery to @explorer** — 2x faster, 1/2 cost for codebase search
23
+ - **Delegate docs to @librarian** — 10x better at finding API docs
24
+ - **Delegate bounded work to @fixer** — 2x faster, 1/2 cost for bounded edits
25
+ - **Delegate analysis to @observer** — isolates large binary files from context
26
+
27
+ ## Anti-Patterns
28
+
29
+ - ❌ Reading full files you only need a snippet of
30
+ - ❌ Grep + read individual results instead of batch reading
31
+ - ❌ Keeping large context when only the summary is needed
32
+ - ❌ Re-reading the same file in multiple tool calls
@@ -0,0 +1,60 @@
1
+ ---
2
+ description: Run verification commands before claiming work is complete. Evidence before assertions.
3
+ ---
4
+
5
+ # Verification Before Completion
6
+
7
+ **Never claim work is complete without running verification first.**
8
+
9
+ ## Verification Order
10
+
11
+ For any code change, run in order:
12
+
13
+ ### 1. Formatting
14
+ ```bash
15
+ mvn spotless:apply # or equivalent formatter
16
+ ```
17
+
18
+ ### 2. Compilation
19
+ ```bash
20
+ mvn compile
21
+ # Expected: BUILD SUCCESS
22
+ ```
23
+
24
+ ### 3. Architecture (if ArchUnit present)
25
+ ```bash
26
+ mvn test -Dtest="*Architecture*"
27
+ # Expected: all 7 ArchUnit rules pass
28
+ ```
29
+
30
+ ### 4. Unit Tests
31
+ ```bash
32
+ mvn test
33
+ # Expected: 0 failures, 0 errors
34
+ ```
35
+
36
+ ### 5. Full Verification
37
+ ```bash
38
+ mvn verify
39
+ # Expected: BUILD SUCCESS
40
+ ```
41
+
42
+ ### 6. Static Analysis (if configured)
43
+ ```bash
44
+ # SpotBugs, PMD CPD, OWASP dependency check
45
+ ```
46
+
47
+ ## Evidence Rules
48
+
49
+ - ❌ "Tests should pass" → running isn't evidence
50
+ - ❌ "I didn't break anything" → verification is evidence
51
+ - ✅ Show the actual output for each command
52
+ - ✅ If a test fails, report the specific failure, don't bury it
53
+
54
+ ## Checklist
55
+
56
+ - [ ] Formatting passes (spotless)
57
+ - [ ] Compiles without errors
58
+ - [ ] All tests pass (0 failures, 0 errors)
59
+ - [ ] No new warnings (or documented)
60
+ - [ ] `gitnexus_detect_changes()` confirms expected scope only