loki-mode 4.2.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/LICENSE +21 -0
- package/README.md +691 -0
- package/SKILL.md +191 -0
- package/VERSION +1 -0
- package/autonomy/.loki/dashboard/index.html +2634 -0
- package/autonomy/CONSTITUTION.md +508 -0
- package/autonomy/README.md +201 -0
- package/autonomy/config.example.yaml +152 -0
- package/autonomy/loki +526 -0
- package/autonomy/run.sh +3636 -0
- package/bin/loki-mode.js +26 -0
- package/bin/postinstall.js +60 -0
- package/docs/ACKNOWLEDGEMENTS.md +234 -0
- package/docs/COMPARISON.md +325 -0
- package/docs/COMPETITIVE-ANALYSIS.md +333 -0
- package/docs/INSTALLATION.md +547 -0
- package/docs/auto-claude-comparison.md +276 -0
- package/docs/cursor-comparison.md +225 -0
- package/docs/dashboard-guide.md +355 -0
- package/docs/screenshots/README.md +149 -0
- package/docs/screenshots/dashboard-agents.png +0 -0
- package/docs/screenshots/dashboard-tasks.png +0 -0
- package/docs/thick2thin.md +173 -0
- package/package.json +48 -0
- package/references/advanced-patterns.md +453 -0
- package/references/agent-types.md +243 -0
- package/references/agents.md +1043 -0
- package/references/business-ops.md +550 -0
- package/references/competitive-analysis.md +216 -0
- package/references/confidence-routing.md +371 -0
- package/references/core-workflow.md +275 -0
- package/references/cursor-learnings.md +207 -0
- package/references/deployment.md +604 -0
- package/references/lab-research-patterns.md +534 -0
- package/references/mcp-integration.md +186 -0
- package/references/memory-system.md +467 -0
- package/references/openai-patterns.md +647 -0
- package/references/production-patterns.md +568 -0
- package/references/prompt-repetition.md +192 -0
- package/references/quality-control.md +437 -0
- package/references/sdlc-phases.md +410 -0
- package/references/task-queue.md +361 -0
- package/references/tool-orchestration.md +691 -0
- package/skills/00-index.md +120 -0
- package/skills/agents.md +249 -0
- package/skills/artifacts.md +174 -0
- package/skills/github-integration.md +218 -0
- package/skills/model-selection.md +125 -0
- package/skills/parallel-workflows.md +526 -0
- package/skills/patterns-advanced.md +188 -0
- package/skills/production.md +292 -0
- package/skills/quality-gates.md +180 -0
- package/skills/testing.md +149 -0
- package/skills/troubleshooting.md +109 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Prompt Repetition Pattern Reference
|
|
2
|
+
|
|
3
|
+
Research-backed technique from arXiv 2512.14982v1: "Prompt Repetition Improves Non-Reasoning LLMs"
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
**Key Finding:** Repeating prompts improves accuracy from 21.33% → 97.33% on position-dependent tasks without latency penalty.
|
|
10
|
+
|
|
11
|
+
**Why It Works:** Causal language models process tokens sequentially without future context. Repetition enables bidirectional attention within the parallelizable prefill stage.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## When to Apply
|
|
16
|
+
|
|
17
|
+
### ✅ USE Prompt Repetition For:
|
|
18
|
+
- **Haiku agents** (non-reasoning model)
|
|
19
|
+
- **Structured tasks** (unit tests, linting, formatting)
|
|
20
|
+
- **Position-dependent operations** (finding items in lists, parsing structured data)
|
|
21
|
+
- **Simple bug fixes** (typos, imports, syntax errors)
|
|
22
|
+
|
|
23
|
+
### ❌ DO NOT Use For:
|
|
24
|
+
- **Opus agents** (reasoning model - neutral/slightly negative effect)
|
|
25
|
+
- **Sonnet agents** (reasoning model - neutral effect)
|
|
26
|
+
- **Complex reasoning tasks** (architecture decisions, planning)
|
|
27
|
+
- **Creative generation** (doesn't help with open-ended tasks)
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Implementation Pattern
|
|
32
|
+
|
|
33
|
+
### Basic Repetition (2x)
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
# Standard prompt (no repetition)
|
|
37
|
+
Task(
|
|
38
|
+
model="haiku",
|
|
39
|
+
description="Run unit tests",
|
|
40
|
+
prompt="Execute all unit tests in tests/ directory and report results"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# With prompt repetition (2x)
|
|
44
|
+
base_prompt = "Execute all unit tests in tests/ directory and report results"
|
|
45
|
+
repeated_prompt = f"{base_prompt}\n\n{base_prompt}"
|
|
46
|
+
|
|
47
|
+
Task(
|
|
48
|
+
model="haiku",
|
|
49
|
+
description="Run unit tests",
|
|
50
|
+
prompt=repeated_prompt
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Enhanced Repetition (3x)
|
|
55
|
+
|
|
56
|
+
For tasks requiring attention to position-dependent elements:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
# 3x repetition for complex structured tasks
|
|
60
|
+
base_prompt = "Find all TODO comments in codebase and categorize by priority"
|
|
61
|
+
repeated_prompt = f"{base_prompt}\n\n{base_prompt}\n\n{base_prompt}"
|
|
62
|
+
|
|
63
|
+
Task(
|
|
64
|
+
model="haiku",
|
|
65
|
+
description="Categorize TODOs",
|
|
66
|
+
prompt=repeated_prompt
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Performance Impact
|
|
73
|
+
|
|
74
|
+
### Benchmarks from Research Paper
|
|
75
|
+
|
|
76
|
+
| Model | Task | Baseline | 2x Repetition | 3x Repetition |
|
|
77
|
+
|-------|------|----------|---------------|---------------|
|
|
78
|
+
| Gemini 2.0 Flash-Lite | NameIndex | 21.33% | 97.33% | 98.67% |
|
|
79
|
+
| GPT-4o | NameIndex | 56.67% | 86.67% | 90.00% |
|
|
80
|
+
| Claude 3 Sonnet | NameIndex | 48.00% | 82.67% | 85.33% |
|
|
81
|
+
| Deepseek V3 | NameIndex | 62.67% | 88.00% | 91.33% |
|
|
82
|
+
|
|
83
|
+
**Aggregate Results:**
|
|
84
|
+
- Wins: 47/70 tests improved
|
|
85
|
+
- Losses: 0/70 tests degraded
|
|
86
|
+
- Neutral: 23/70 tests unchanged
|
|
87
|
+
|
|
88
|
+
### Latency Impact
|
|
89
|
+
|
|
90
|
+
**Zero latency penalty** - repetition occurs in parallelizable prefill stage, not sequential generation.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Loki Mode Integration
|
|
95
|
+
|
|
96
|
+
### Automatic Application
|
|
97
|
+
|
|
98
|
+
Loki Mode automatically applies prompt repetition for Haiku agents on eligible tasks:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
def prepare_task_prompt(task, model):
|
|
102
|
+
"""Prepare prompt with optional repetition based on model and task type."""
|
|
103
|
+
base_prompt = task.prompt
|
|
104
|
+
|
|
105
|
+
# Apply repetition for Haiku on structured tasks
|
|
106
|
+
if model == "haiku" and is_structured_task(task):
|
|
107
|
+
# 2x repetition for standard tasks
|
|
108
|
+
if task.complexity == "simple":
|
|
109
|
+
return f"{base_prompt}\n\n{base_prompt}"
|
|
110
|
+
|
|
111
|
+
# 3x repetition for position-critical tasks
|
|
112
|
+
elif requires_position_accuracy(task):
|
|
113
|
+
return f"{base_prompt}\n\n{base_prompt}\n\n{base_prompt}"
|
|
114
|
+
|
|
115
|
+
return base_prompt # No repetition for reasoning models
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def is_structured_task(task):
|
|
119
|
+
"""Determine if task benefits from prompt repetition."""
|
|
120
|
+
structured_keywords = [
|
|
121
|
+
"test", "lint", "format", "parse", "find", "list",
|
|
122
|
+
"extract", "categorize", "count", "filter"
|
|
123
|
+
]
|
|
124
|
+
return any(kw in task.description.lower() for kw in structured_keywords)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def requires_position_accuracy(task):
|
|
128
|
+
"""Check if task requires precise position/order handling."""
|
|
129
|
+
position_keywords = [
|
|
130
|
+
"order", "sequence", "position", "index", "nth",
|
|
131
|
+
"first", "last", "middle", "between"
|
|
132
|
+
]
|
|
133
|
+
return any(kw in task.description.lower() for kw in position_keywords)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Manual Override
|
|
137
|
+
|
|
138
|
+
Disable repetition for specific tasks:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
Task(
|
|
142
|
+
model="haiku",
|
|
143
|
+
description="Generate creative names",
|
|
144
|
+
prompt="Suggest 10 creative product names",
|
|
145
|
+
metadata={"disable_prompt_repetition": True}
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Research Citations
|
|
152
|
+
|
|
153
|
+
**Paper:** Leviathan, Y., Kalman, M., & Matias, Y. (2025). *Prompt Repetition Improves Non-Reasoning LLMs*. arXiv:2512.14982v1.
|
|
154
|
+
|
|
155
|
+
**Key Quotes:**
|
|
156
|
+
- "Prompt repetition wins 47 out of 70 tests, with 0 losses"
|
|
157
|
+
- "No increase in output lengths or generation times"
|
|
158
|
+
- "Results neutral to slightly positive when reasoning enabled"
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Best Practices
|
|
163
|
+
|
|
164
|
+
1. **Always repeat for Haiku** on structured tasks (unit tests, linting, parsing)
|
|
165
|
+
2. **Never repeat for Opus/Sonnet** (reasoning models see no benefit)
|
|
166
|
+
3. **Use 2x repetition** as default (diminishing returns beyond 3x)
|
|
167
|
+
4. **Test with/without** repetition on critical tasks to validate improvement
|
|
168
|
+
5. **Monitor token usage** - input tokens increase 2-3x (but still cost-effective due to accuracy gains)
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Cost-Benefit Analysis
|
|
173
|
+
|
|
174
|
+
### Example: Unit Test Execution
|
|
175
|
+
|
|
176
|
+
**Without Repetition:**
|
|
177
|
+
- Accuracy: 65%
|
|
178
|
+
- Input tokens: 500
|
|
179
|
+
- Retries needed: 2-3
|
|
180
|
+
- Total cost: 500 + (500 × 2) = 1500 tokens
|
|
181
|
+
|
|
182
|
+
**With 2x Repetition:**
|
|
183
|
+
- Accuracy: 95%
|
|
184
|
+
- Input tokens: 1000 (2x)
|
|
185
|
+
- Retries needed: 0-1
|
|
186
|
+
- Total cost: 1000 + (1000 × 0.5) = 1500 tokens
|
|
187
|
+
|
|
188
|
+
**Result:** Same cost, 46% higher accuracy.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
**Version:** 1.0.0 | **Research Source:** arXiv 2512.14982v1 (2025)
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
# Quality Control Reference
|
|
2
|
+
|
|
3
|
+
Quality gates, code review process, and severity blocking rules.
|
|
4
|
+
Enhanced with 2025 research on anti-sycophancy, heterogeneous teams, and OpenAI Agents SDK patterns.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Core Principle: Guardrails, Not Just Acceleration
|
|
9
|
+
|
|
10
|
+
**CRITICAL:** Speed without quality controls creates "AI slop" - semi-functional code that accumulates technical debt. Loki Mode enforces strict quality guardrails.
|
|
11
|
+
|
|
12
|
+
**Research Insight:** Heterogeneous review teams outperform homogeneous ones by 4-6% (A-HMAD, 2025).
|
|
13
|
+
**OpenAI Insight:** "Think of guardrails as a layered defense mechanism. Multiple specialized guardrails create resilient agents."
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Guardrails & Tripwires System (OpenAI SDK Pattern)
|
|
18
|
+
|
|
19
|
+
### Input Guardrails (Run Before Execution)
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
# Layer 1: Validate task scope and safety
|
|
23
|
+
@input_guardrail(blocking=True)
|
|
24
|
+
async def validate_task_scope(input, context):
|
|
25
|
+
# Check if task within project bounds
|
|
26
|
+
if references_external_paths(input):
|
|
27
|
+
return GuardrailResult(
|
|
28
|
+
tripwire_triggered=True,
|
|
29
|
+
reason="Task references paths outside project"
|
|
30
|
+
)
|
|
31
|
+
# Check for destructive operations
|
|
32
|
+
if contains_destructive_operation(input):
|
|
33
|
+
return GuardrailResult(
|
|
34
|
+
tripwire_triggered=True,
|
|
35
|
+
reason="Destructive operation requires human approval"
|
|
36
|
+
)
|
|
37
|
+
return GuardrailResult(tripwire_triggered=False)
|
|
38
|
+
|
|
39
|
+
# Layer 2: Detect prompt injection
|
|
40
|
+
@input_guardrail(blocking=True)
|
|
41
|
+
async def detect_injection(input, context):
|
|
42
|
+
if has_injection_patterns(input):
|
|
43
|
+
return GuardrailResult(
|
|
44
|
+
tripwire_triggered=True,
|
|
45
|
+
reason="Potential prompt injection detected"
|
|
46
|
+
)
|
|
47
|
+
return GuardrailResult(tripwire_triggered=False)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Output Guardrails (Run After Execution)
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# Validate code quality before accepting
|
|
54
|
+
@output_guardrail
|
|
55
|
+
async def validate_code_output(output, context):
|
|
56
|
+
if output.type == "code":
|
|
57
|
+
issues = run_static_analysis(output.content)
|
|
58
|
+
critical = [i for i in issues if i.severity == "critical"]
|
|
59
|
+
if critical:
|
|
60
|
+
return GuardrailResult(
|
|
61
|
+
tripwire_triggered=True,
|
|
62
|
+
reason=f"Critical issues: {critical}"
|
|
63
|
+
)
|
|
64
|
+
return GuardrailResult(tripwire_triggered=False)
|
|
65
|
+
|
|
66
|
+
# Check for secrets in output
|
|
67
|
+
@output_guardrail
|
|
68
|
+
async def check_secrets(output, context):
|
|
69
|
+
if contains_secrets(output.content):
|
|
70
|
+
return GuardrailResult(
|
|
71
|
+
tripwire_triggered=True,
|
|
72
|
+
reason="Output contains potential secrets"
|
|
73
|
+
)
|
|
74
|
+
return GuardrailResult(tripwire_triggered=False)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Execution Modes
|
|
78
|
+
|
|
79
|
+
| Mode | Behavior | Use When |
|
|
80
|
+
|------|----------|----------|
|
|
81
|
+
| **Blocking** | Guardrail completes before agent starts | Expensive models, sensitive ops |
|
|
82
|
+
| **Parallel** | Guardrail runs with agent | Fast checks, acceptable token loss |
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
# Blocking: prevents token consumption on fail
|
|
86
|
+
@input_guardrail(blocking=True, run_in_parallel=False)
|
|
87
|
+
async def expensive_validation(input): pass
|
|
88
|
+
|
|
89
|
+
# Parallel: faster but may waste tokens
|
|
90
|
+
@input_guardrail(blocking=True, run_in_parallel=True)
|
|
91
|
+
async def fast_validation(input): pass
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Tripwire Handling
|
|
95
|
+
|
|
96
|
+
When a guardrail triggers its tripwire, execution halts immediately:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
try:
|
|
100
|
+
result = await run_agent(task)
|
|
101
|
+
except InputGuardrailTripwireTriggered as e:
|
|
102
|
+
log_blocked_attempt(e)
|
|
103
|
+
return early_exit(reason=str(e))
|
|
104
|
+
except OutputGuardrailTripwireTriggered as e:
|
|
105
|
+
rollback_changes()
|
|
106
|
+
return retry_with_constraints(e.constraints)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Layered Defense Strategy
|
|
110
|
+
|
|
111
|
+
```yaml
|
|
112
|
+
guardrail_layers:
|
|
113
|
+
layer_1_input:
|
|
114
|
+
- scope_validation # Is task within bounds?
|
|
115
|
+
- pii_detection # Contains sensitive data?
|
|
116
|
+
- injection_detection # Prompt injection attempt?
|
|
117
|
+
|
|
118
|
+
layer_2_pre_execution:
|
|
119
|
+
- cost_estimation # Will this exceed budget?
|
|
120
|
+
- dependency_check # Are dependencies available?
|
|
121
|
+
- conflict_detection # Conflicts with in-progress work?
|
|
122
|
+
|
|
123
|
+
layer_3_output:
|
|
124
|
+
- static_analysis # Code quality issues?
|
|
125
|
+
- secret_detection # Secrets in output?
|
|
126
|
+
- spec_compliance # Matches OpenAPI spec?
|
|
127
|
+
|
|
128
|
+
layer_4_post_action:
|
|
129
|
+
- test_validation # Tests pass?
|
|
130
|
+
- review_approval # Review passed?
|
|
131
|
+
- deployment_safety # Safe to deploy?
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
See `references/openai-patterns.md` for full guardrails implementation.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Quality Gates
|
|
139
|
+
|
|
140
|
+
**Never ship code without passing all quality gates:**
|
|
141
|
+
|
|
142
|
+
### 1. Static Analysis (Automated)
|
|
143
|
+
- CodeQL security scanning
|
|
144
|
+
- ESLint/Pylint/Rubocop for code style
|
|
145
|
+
- Unused variable/import detection
|
|
146
|
+
- Duplicated logic detection
|
|
147
|
+
- Type checking (TypeScript/mypy/etc)
|
|
148
|
+
|
|
149
|
+
### 2. 3-Reviewer Parallel System (AI-driven)
|
|
150
|
+
|
|
151
|
+
Every code change goes through 3 specialized reviewers **simultaneously**:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
IMPLEMENT -> BLIND REVIEW (parallel) -> DEBATE (if disagreement) -> AGGREGATE -> FIX -> RE-REVIEW
|
|
155
|
+
|
|
|
156
|
+
+-- code-reviewer (Sonnet) - Code quality, patterns, best practices
|
|
157
|
+
+-- business-logic-reviewer (Sonnet) - Requirements, edge cases, UX
|
|
158
|
+
+-- security-reviewer (Sonnet) - Vulnerabilities, OWASP Top 10
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Important:**
|
|
162
|
+
- ALWAYS launch all 3 reviewers in a single message (3 Task calls)
|
|
163
|
+
- ALWAYS specify model: "sonnet" for each reviewer
|
|
164
|
+
- ALWAYS use blind review mode (reviewers cannot see each other's findings initially)
|
|
165
|
+
- NEVER dispatch reviewers sequentially (always parallel - 3x faster)
|
|
166
|
+
- NEVER aggregate before all 3 reviewers complete
|
|
167
|
+
|
|
168
|
+
### Anti-Sycophancy Protocol (CONSENSAGENT Research)
|
|
169
|
+
|
|
170
|
+
**Problem:** Reviewers may reinforce each other's findings instead of critically engaging.
|
|
171
|
+
|
|
172
|
+
**Solution: Blind Review + Devil's Advocate**
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# Phase 1: Independent blind review
|
|
176
|
+
reviews = []
|
|
177
|
+
for reviewer in [code_reviewer, business_reviewer, security_reviewer]:
|
|
178
|
+
review = Task(
|
|
179
|
+
subagent_type="general-purpose",
|
|
180
|
+
model="opus",
|
|
181
|
+
prompt=f"""
|
|
182
|
+
{reviewer.prompt}
|
|
183
|
+
|
|
184
|
+
CRITICAL: Be skeptical. Your job is to find problems.
|
|
185
|
+
List specific concerns with file:line references.
|
|
186
|
+
Do NOT rubber-stamp. Finding zero issues is suspicious.
|
|
187
|
+
"""
|
|
188
|
+
)
|
|
189
|
+
reviews.append(review)
|
|
190
|
+
|
|
191
|
+
# Phase 2: Check for disagreement
|
|
192
|
+
if has_disagreement(reviews):
|
|
193
|
+
# Structured debate - max 2 rounds
|
|
194
|
+
debate_result = structured_debate(reviews, max_rounds=2)
|
|
195
|
+
else:
|
|
196
|
+
# All agreed - run devil's advocate
|
|
197
|
+
devil_review = Task(
|
|
198
|
+
subagent_type="general-purpose",
|
|
199
|
+
model="opus",
|
|
200
|
+
prompt="""
|
|
201
|
+
The other reviewers found no issues. Your job is to be contrarian.
|
|
202
|
+
Find problems they missed. Challenge assumptions.
|
|
203
|
+
If truly nothing wrong, explain why each potential issue category is covered.
|
|
204
|
+
"""
|
|
205
|
+
)
|
|
206
|
+
reviews.append(devil_review)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Heterogeneous Team Composition
|
|
210
|
+
|
|
211
|
+
**Each reviewer has distinct personality/focus:**
|
|
212
|
+
|
|
213
|
+
| Reviewer | Model | Expertise | Personality |
|
|
214
|
+
|----------|-------|-----------|-------------|
|
|
215
|
+
| Code Quality | Opus | SOLID, patterns, maintainability | Perfectionist |
|
|
216
|
+
| Business Logic | Opus | Requirements, edge cases, UX | Pragmatic |
|
|
217
|
+
| Security | Opus | OWASP, auth, injection | Paranoid |
|
|
218
|
+
|
|
219
|
+
This diversity prevents groupthink and catches more issues.
|
|
220
|
+
|
|
221
|
+
### 3. Severity-Based Blocking
|
|
222
|
+
|
|
223
|
+
| Severity | Action | Continue? |
|
|
224
|
+
|----------|--------|-----------|
|
|
225
|
+
| **Critical** | BLOCK - Fix immediately | NO |
|
|
226
|
+
| **High** | BLOCK - Fix immediately | NO |
|
|
227
|
+
| **Medium** | BLOCK - Fix before proceeding | NO |
|
|
228
|
+
| **Low** | Add `// TODO(review): ...` comment | YES |
|
|
229
|
+
| **Cosmetic** | Add `// FIXME(nitpick): ...` comment | YES |
|
|
230
|
+
|
|
231
|
+
**Critical/High/Medium = BLOCK and fix before proceeding**
|
|
232
|
+
**Low/Cosmetic = Add TODO/FIXME comment, continue**
|
|
233
|
+
|
|
234
|
+
### 4. Test Coverage Gates
|
|
235
|
+
- Unit tests: 100% pass, >80% coverage
|
|
236
|
+
- Integration tests: 100% pass
|
|
237
|
+
- E2E tests: critical flows pass
|
|
238
|
+
|
|
239
|
+
### 5. Rulesets (Blocking Merges)
|
|
240
|
+
- No secrets in code
|
|
241
|
+
- No unhandled exceptions
|
|
242
|
+
- No SQL injection vulnerabilities
|
|
243
|
+
- No XSS vulnerabilities
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Code Review Protocol
|
|
248
|
+
|
|
249
|
+
### Launching Reviewers (Parallel)
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
# CORRECT: Launch all 3 in parallel
|
|
253
|
+
Task(subagent_type="general-purpose", model="opus",
|
|
254
|
+
description="Code quality review",
|
|
255
|
+
prompt="Review for code quality, patterns, SOLID principles...")
|
|
256
|
+
|
|
257
|
+
Task(subagent_type="general-purpose", model="opus",
|
|
258
|
+
description="Business logic review",
|
|
259
|
+
prompt="Review for requirements alignment, edge cases, UX...")
|
|
260
|
+
|
|
261
|
+
Task(subagent_type="general-purpose", model="opus",
|
|
262
|
+
description="Security review",
|
|
263
|
+
prompt="Review for vulnerabilities, OWASP Top 10...")
|
|
264
|
+
|
|
265
|
+
# WRONG: Sequential reviewers (3x slower)
|
|
266
|
+
# Don't do: await reviewer1; await reviewer2; await reviewer3;
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### After Fixes
|
|
270
|
+
|
|
271
|
+
- ALWAYS re-run ALL 3 reviewers after fixes (not just the one that found the issue)
|
|
272
|
+
- Wait for all reviews to complete before aggregating results
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Structured Prompting for Subagents
|
|
277
|
+
|
|
278
|
+
**Every subagent dispatch MUST include:**
|
|
279
|
+
|
|
280
|
+
```markdown
|
|
281
|
+
## GOAL (What success looks like)
|
|
282
|
+
[High-level objective, not just the action]
|
|
283
|
+
Example: "Refactor authentication for maintainability and testability"
|
|
284
|
+
NOT: "Refactor the auth file"
|
|
285
|
+
|
|
286
|
+
## CONSTRAINTS (What you cannot do)
|
|
287
|
+
- No third-party dependencies without approval
|
|
288
|
+
- Maintain backwards compatibility with v1.x API
|
|
289
|
+
- Keep response time under 200ms
|
|
290
|
+
- Follow existing error handling patterns
|
|
291
|
+
|
|
292
|
+
## CONTEXT (What you need to know)
|
|
293
|
+
- Related files: [list with brief descriptions]
|
|
294
|
+
- Architecture decisions: [relevant ADRs or patterns]
|
|
295
|
+
- Previous attempts: [what was tried, why it failed]
|
|
296
|
+
- Dependencies: [what this depends on, what depends on this]
|
|
297
|
+
|
|
298
|
+
## OUTPUT FORMAT (What to deliver)
|
|
299
|
+
- [ ] Pull request with Why/What/Trade-offs description
|
|
300
|
+
- [ ] Unit tests with >90% coverage
|
|
301
|
+
- [ ] Update API documentation
|
|
302
|
+
- [ ] Performance benchmark results
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Task Completion Report
|
|
308
|
+
|
|
309
|
+
**Every completed task MUST include decision documentation:**
|
|
310
|
+
|
|
311
|
+
```markdown
|
|
312
|
+
## Task Completion Report
|
|
313
|
+
|
|
314
|
+
### WHY (Problem & Solution Rationale)
|
|
315
|
+
- **Problem**: [What was broken/missing/suboptimal]
|
|
316
|
+
- **Root Cause**: [Why it happened]
|
|
317
|
+
- **Solution Chosen**: [What we implemented]
|
|
318
|
+
- **Alternatives Considered**:
|
|
319
|
+
1. [Option A]: Rejected because [reason]
|
|
320
|
+
2. [Option B]: Rejected because [reason]
|
|
321
|
+
|
|
322
|
+
### WHAT (Changes Made)
|
|
323
|
+
- **Files Modified**: [with line ranges and purpose]
|
|
324
|
+
- `src/auth.ts:45-89` - Extracted token validation to separate function
|
|
325
|
+
- `src/auth.test.ts:120-156` - Added edge case tests
|
|
326
|
+
- **APIs Changed**: [breaking vs non-breaking]
|
|
327
|
+
- **Behavior Changes**: [what users will notice]
|
|
328
|
+
- **Dependencies Added/Removed**: [with justification]
|
|
329
|
+
|
|
330
|
+
### TRADE-OFFS (Gains & Costs)
|
|
331
|
+
- **Gained**:
|
|
332
|
+
- Better testability (extracted pure functions)
|
|
333
|
+
- 40% faster token validation
|
|
334
|
+
- Reduced cyclomatic complexity from 15 to 6
|
|
335
|
+
- **Cost**:
|
|
336
|
+
- Added 2 new functions (increased surface area)
|
|
337
|
+
- Requires migration for custom token validators
|
|
338
|
+
- **Neutral**:
|
|
339
|
+
- No performance change for standard use cases
|
|
340
|
+
|
|
341
|
+
### RISKS & MITIGATIONS
|
|
342
|
+
- **Risk**: Existing custom validators may break
|
|
343
|
+
- **Mitigation**: Added backwards-compatibility shim, deprecation warning
|
|
344
|
+
- **Risk**: New validation logic untested at scale
|
|
345
|
+
- **Mitigation**: Gradual rollout with feature flag, rollback plan ready
|
|
346
|
+
|
|
347
|
+
### TEST RESULTS
|
|
348
|
+
- Unit: 24/24 passed (coverage: 92%)
|
|
349
|
+
- Integration: 8/8 passed
|
|
350
|
+
- Performance: p99 improved from 145ms -> 87ms
|
|
351
|
+
|
|
352
|
+
### NEXT STEPS (if any)
|
|
353
|
+
- [ ] Monitor error rates for 24h post-deploy
|
|
354
|
+
- [ ] Create follow-up task to remove compatibility shim in v3.0
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Preventing "AI Slop"
|
|
360
|
+
|
|
361
|
+
### Warning Signs
|
|
362
|
+
- Tests pass but code quality degraded
|
|
363
|
+
- Copy-paste duplication instead of abstraction
|
|
364
|
+
- Over-engineered solutions to simple problems
|
|
365
|
+
- Missing error handling
|
|
366
|
+
- No logging/observability
|
|
367
|
+
- Generic variable names (data, temp, result)
|
|
368
|
+
- Magic numbers without constants
|
|
369
|
+
- Commented-out code
|
|
370
|
+
- TODO comments without GitHub issues
|
|
371
|
+
|
|
372
|
+
### When Detected
|
|
373
|
+
1. Fail the task immediately
|
|
374
|
+
2. Add to failed queue with detailed feedback
|
|
375
|
+
3. Re-dispatch with stricter constraints
|
|
376
|
+
4. Update CONTINUITY.md with anti-pattern to avoid
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Quality Gate Hooks
|
|
381
|
+
|
|
382
|
+
### Pre-Write Hook (BLOCKING)
|
|
383
|
+
```bash
|
|
384
|
+
#!/bin/bash
|
|
385
|
+
# .loki/hooks/pre-write.sh
|
|
386
|
+
# Blocks writes that violate rules
|
|
387
|
+
|
|
388
|
+
# Check for secrets
|
|
389
|
+
if grep -rE "(password|secret|key).*=.*['\"][^'\"]{8,}" "$1"; then
|
|
390
|
+
echo "BLOCKED: Potential secret detected"
|
|
391
|
+
exit 1
|
|
392
|
+
fi
|
|
393
|
+
|
|
394
|
+
# Check for console.log in production
|
|
395
|
+
if grep -n "console.log" "$1" | grep -v "test"; then
|
|
396
|
+
echo "BLOCKED: Remove console.log statements"
|
|
397
|
+
exit 1
|
|
398
|
+
fi
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Post-Write Hook (AUTO-FIX)
|
|
402
|
+
```bash
|
|
403
|
+
#!/bin/bash
|
|
404
|
+
# .loki/hooks/post-write.sh
|
|
405
|
+
# Auto-fixes after writes
|
|
406
|
+
|
|
407
|
+
# Format code
|
|
408
|
+
npx prettier --write "$1"
|
|
409
|
+
|
|
410
|
+
# Fix linting issues
|
|
411
|
+
npx eslint --fix "$1"
|
|
412
|
+
|
|
413
|
+
# Type check
|
|
414
|
+
npx tsc --noEmit
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## Constitution Reference
|
|
420
|
+
|
|
421
|
+
Quality gates are enforced by `autonomy/CONSTITUTION.md`:
|
|
422
|
+
|
|
423
|
+
**Pre-Commit (BLOCKING):**
|
|
424
|
+
- Linting (auto-fix enabled)
|
|
425
|
+
- Type checking (strict mode)
|
|
426
|
+
- Contract tests (80% coverage minimum)
|
|
427
|
+
- Spec validation (Spectral)
|
|
428
|
+
|
|
429
|
+
**Post-Implementation (AUTO-FIX):**
|
|
430
|
+
- Static analysis (ESLint, Prettier, TSC)
|
|
431
|
+
- Security scan (Semgrep, Snyk)
|
|
432
|
+
- Performance check (Lighthouse score 90+)
|
|
433
|
+
|
|
434
|
+
**Runtime Invariants:**
|
|
435
|
+
- `SPEC_BEFORE_CODE`: Implementation tasks require spec reference
|
|
436
|
+
- `TASK_HAS_COMMIT`: Completed tasks have git commit SHA
|
|
437
|
+
- `QUALITY_GATES_PASSED`: Completed tasks passed all quality checks
|