ollama_agent 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/.cursor/skills/ruby-code-review-levels/SKILL.md +115 -0
- data/.cursor/skills/self-improvement-sandbox-safety/SKILL.md +65 -0
- data/.env.example +25 -0
- data/CHANGELOG.md +40 -0
- data/README.md +135 -4
- data/docs/ARCHITECTURE.md +42 -0
- data/docs/PERFORMANCE.md +22 -0
- data/docs/SESSIONS.md +48 -0
- data/docs/TOOLS.md +53 -0
- data/docs/TOOL_RUNTIME.md +154 -0
- data/docs/superpowers/plans/2026-03-26-production-ready-ollama-agent.md +2454 -0
- data/docs/superpowers/specs/2026-03-26-production-ready-ollama-agent-design.md +400 -0
- data/lib/ollama_agent/agent/agent_config.rb +53 -0
- data/lib/ollama_agent/agent/client_wiring.rb +76 -0
- data/lib/ollama_agent/agent/prompt_wiring.rb +55 -0
- data/lib/ollama_agent/agent/session_wiring.rb +53 -0
- data/lib/ollama_agent/agent.rb +148 -73
- data/lib/ollama_agent/agent_prompt.rb +31 -1
- data/lib/ollama_agent/chat_stream_carry.rb +88 -0
- data/lib/ollama_agent/chat_stream_thinking_format.rb +29 -0
- data/lib/ollama_agent/cli.rb +394 -4
- data/lib/ollama_agent/console.rb +177 -5
- data/lib/ollama_agent/context/manager.rb +100 -0
- data/lib/ollama_agent/context/token_counter.rb +33 -0
- data/lib/ollama_agent/diff_path_validator.rb +32 -10
- data/lib/ollama_agent/env_config.rb +44 -0
- data/lib/ollama_agent/external_agents/TODO-plan.md +1948 -0
- data/lib/ollama_agent/external_agents/argv_interp.rb +21 -0
- data/lib/ollama_agent/external_agents/default_agents.yml +60 -0
- data/lib/ollama_agent/external_agents/delegate_logger.rb +31 -0
- data/lib/ollama_agent/external_agents/delegate_timeout_status.rb +12 -0
- data/lib/ollama_agent/external_agents/env_helpers.rb +38 -0
- data/lib/ollama_agent/external_agents/path_validator.rb +32 -0
- data/lib/ollama_agent/external_agents/probe.rb +122 -0
- data/lib/ollama_agent/external_agents/registry.rb +50 -0
- data/lib/ollama_agent/external_agents/runner.rb +118 -0
- data/lib/ollama_agent/external_agents.rb +9 -0
- data/lib/ollama_agent/global_dotenv.rb +39 -0
- data/lib/ollama_agent/model_env.rb +26 -0
- data/lib/ollama_agent/ollama_chat_thinking_stream.rb +41 -0
- data/lib/ollama_agent/ollama_connection.rb +6 -1
- data/lib/ollama_agent/patch_risk.rb +81 -0
- data/lib/ollama_agent/patch_support.rb +27 -1
- data/lib/ollama_agent/path_sandbox.rb +62 -0
- data/lib/ollama_agent/prompt_skills/clean_ruby.md +131 -0
- data/lib/ollama_agent/prompt_skills/code_review.md +112 -0
- data/lib/ollama_agent/prompt_skills/design_patterns.md +56 -0
- data/lib/ollama_agent/prompt_skills/manifest.yml +25 -0
- data/lib/ollama_agent/prompt_skills/ollama_agent_patterns.md +132 -0
- data/lib/ollama_agent/prompt_skills/rails_best_practices.md +41 -0
- data/lib/ollama_agent/prompt_skills/rails_style.md +138 -0
- data/lib/ollama_agent/prompt_skills/rspec.md +280 -0
- data/lib/ollama_agent/prompt_skills/rubocop.md +7 -0
- data/lib/ollama_agent/prompt_skills/ruby_style.md +121 -0
- data/lib/ollama_agent/prompt_skills/solid.md +270 -0
- data/lib/ollama_agent/prompt_skills/solid_ruby.md +223 -0
- data/lib/ollama_agent/prompt_skills.rb +169 -0
- data/lib/ollama_agent/repo_list.rb +4 -1
- data/lib/ollama_agent/resilience/audit_logger.rb +79 -0
- data/lib/ollama_agent/resilience/retry_middleware.rb +45 -0
- data/lib/ollama_agent/resilience/retry_policy.rb +51 -0
- data/lib/ollama_agent/ruby_index_tool_support.rb +17 -6
- data/lib/ollama_agent/runner.rb +123 -0
- data/lib/ollama_agent/sandboxed_tools/delegate_external.rb +62 -0
- data/lib/ollama_agent/sandboxed_tools/file_read_write.rb +100 -0
- data/lib/ollama_agent/sandboxed_tools/search_text.rb +60 -0
- data/lib/ollama_agent/sandboxed_tools.rb +55 -116
- data/lib/ollama_agent/search_backend.rb +93 -0
- data/lib/ollama_agent/self_improvement/analyzer.rb +34 -0
- data/lib/ollama_agent/self_improvement/improver.rb +340 -0
- data/lib/ollama_agent/self_improvement/modes.rb +25 -0
- data/lib/ollama_agent/self_improvement/ruby_mastery_context.rb +66 -0
- data/lib/ollama_agent/self_improvement.rb +5 -0
- data/lib/ollama_agent/session/session.rb +8 -0
- data/lib/ollama_agent/session/store.rb +68 -0
- data/lib/ollama_agent/streaming/console_streamer.rb +29 -0
- data/lib/ollama_agent/streaming/hooks.rb +39 -0
- data/lib/ollama_agent/tool_arguments.rb +13 -1
- data/lib/ollama_agent/tool_content_parser.rb +1 -1
- data/lib/ollama_agent/tool_runtime/executor.rb +34 -0
- data/lib/ollama_agent/tool_runtime/json_extractor.rb +62 -0
- data/lib/ollama_agent/tool_runtime/loop.rb +72 -0
- data/lib/ollama_agent/tool_runtime/memory.rb +32 -0
- data/lib/ollama_agent/tool_runtime/ollama_json_planner.rb +98 -0
- data/lib/ollama_agent/tool_runtime/plan_extractor.rb +12 -0
- data/lib/ollama_agent/tool_runtime/registry.rb +60 -0
- data/lib/ollama_agent/tool_runtime/tool.rb +24 -0
- data/lib/ollama_agent/tool_runtime.rb +24 -0
- data/lib/ollama_agent/tools/registry.rb +55 -0
- data/lib/ollama_agent/tools_schema.rb +74 -1
- data/lib/ollama_agent/user_prompt.rb +35 -0
- data/lib/ollama_agent/version.rb +1 -1
- data/lib/ollama_agent.rb +25 -0
- data/reproduce_429.rb +40 -0
- data/sig/ollama_agent.rbs +111 -1
- metadata +78 -2
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: solid
|
|
3
|
+
description: Transforms junior-level code into senior-engineer quality software through SOLID principles, TDD, clean code practices, and professional software design. Use when writing code, implementing features, refactoring, planning architecture, designing systems, reviewing code, debugging, creating tests, or making design decisions.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Solid Skills: Professional Software Engineering
|
|
7
|
+
|
|
8
|
+
You are now operating as a senior software engineer. Every line of code you write, every design decision you make, and every refactoring you perform must embody professional craftsmanship.
|
|
9
|
+
|
|
10
|
+
## When This Skill Applies
|
|
11
|
+
|
|
12
|
+
**ALWAYS use this skill when:**
|
|
13
|
+
- Writing ANY code (features, fixes, utilities)
|
|
14
|
+
- Refactoring existing code
|
|
15
|
+
- Planning or designing architecture
|
|
16
|
+
- Reviewing code quality
|
|
17
|
+
- Debugging issues
|
|
18
|
+
- Creating tests
|
|
19
|
+
- Making design decisions
|
|
20
|
+
|
|
21
|
+
## Core Philosophy
|
|
22
|
+
|
|
23
|
+
> "Code is to create products for users & customers. Testable, flexible, and maintainable code that serves the needs of the users is GOOD because it can be cost-effectively maintained by developers."
|
|
24
|
+
|
|
25
|
+
The goal of software: Enable developers to **discover, understand, add, change, remove, test, debug, deploy**, and **monitor** features efficiently.
|
|
26
|
+
|
|
27
|
+
## The Non-Negotiable Process
|
|
28
|
+
|
|
29
|
+
### 1. ALWAYS Start with Tests (TDD)
|
|
30
|
+
|
|
31
|
+
**Red-Green-Refactor is not optional:**
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
1. RED - Write a failing test that describes the behavior
|
|
35
|
+
2. GREEN - Write the SIMPLEST code to make it pass
|
|
36
|
+
3. REFACTOR - Clean up, remove duplication (Rule of Three)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**The Three Laws of TDD:**
|
|
40
|
+
1. You cannot write production code unless it makes a failing test pass
|
|
41
|
+
2. You cannot write more test code than is sufficient to fail
|
|
42
|
+
3. You cannot write more production code than is sufficient to pass
|
|
43
|
+
|
|
44
|
+
**Design happens during REFACTORING, not during coding.**
|
|
45
|
+
|
|
46
|
+
See: [references/tdd.md](references/tdd.md)
|
|
47
|
+
|
|
48
|
+
### 2. Apply SOLID Principles Rigorously
|
|
49
|
+
|
|
50
|
+
Every class, every module, every function:
|
|
51
|
+
|
|
52
|
+
| Principle | Question to Ask |
|
|
53
|
+
| ------------------------------- | ------------------------------------------------- |
|
|
54
|
+
| **S**RP - Single Responsibility | "Does this have ONE reason to change?" |
|
|
55
|
+
| **O**CP - Open/Closed | "Can I extend without modifying?" |
|
|
56
|
+
| **L**SP - Liskov Substitution | "Can subtypes replace base types safely?" |
|
|
57
|
+
| **I**SP - Interface Segregation | "Are clients forced to depend on unused methods?" |
|
|
58
|
+
| **D**IP - Dependency Inversion | "Do high-level modules depend on abstractions?" |
|
|
59
|
+
|
|
60
|
+
See: [references/solid-principles.md](references/solid-principles.md)
|
|
61
|
+
|
|
62
|
+
### 3. Write Clean, Human-Readable Code
|
|
63
|
+
|
|
64
|
+
**Naming (in order of priority):**
|
|
65
|
+
1. **Consistency** - Same concept = same name everywhere
|
|
66
|
+
2. **Understandability** - Domain language, not technical jargon
|
|
67
|
+
3. **Specificity** - Precise, not vague (avoid `data`, `info`, `manager`)
|
|
68
|
+
4. **Brevity** - Short but not cryptic
|
|
69
|
+
5. **Searchability** - Unique, greppable names
|
|
70
|
+
|
|
71
|
+
**Structure:**
|
|
72
|
+
- One level of indentation per method
|
|
73
|
+
- No `else` keyword when possible (early returns)
|
|
74
|
+
- When validating untrusted strings against an object/map, use `Object.hasOwn(...)` (or `Object.prototype.hasOwnProperty.call(...)`) — do not use the `in` operator, which matches prototype keys
|
|
75
|
+
- **ALWAYS wrap primitives in domain objects** - IDs, emails, money amounts, etc.
|
|
76
|
+
- First-class collections (wrap arrays in classes)
|
|
77
|
+
- One dot per line (Law of Demeter)
|
|
78
|
+
- Keep entities small (< 50 lines for classes, < 10 for methods)
|
|
79
|
+
- No more than two instance variables per class
|
|
80
|
+
|
|
81
|
+
**Value Objects are MANDATORY for:**
|
|
82
|
+
```typescript
|
|
83
|
+
// ALWAYS create value objects for:
|
|
84
|
+
class UserId { constructor(private readonly value: string) {} }
|
|
85
|
+
class Email { constructor(private readonly value: string) { /* validate */ } }
|
|
86
|
+
class Money { constructor(private readonly amount: number, private readonly currency: string) {} }
|
|
87
|
+
class OrderId { constructor(private readonly value: string) {} }
|
|
88
|
+
|
|
89
|
+
// NEVER use raw primitives for domain concepts:
|
|
90
|
+
// BAD: function createOrder(userId: string, email: string)
|
|
91
|
+
// GOOD: function createOrder(userId: UserId, email: Email)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
See: [references/clean-code.md](references/clean-code.md)
|
|
95
|
+
|
|
96
|
+
### 4. Design with Responsibility in Mind
|
|
97
|
+
|
|
98
|
+
**Ask these questions for every class:**
|
|
99
|
+
1. "What pattern is this?" (Entity, Service, Repository, Factory, etc.)
|
|
100
|
+
2. "Is it doing too much?" (Check object calisthenics)
|
|
101
|
+
|
|
102
|
+
**Object Stereotypes:**
|
|
103
|
+
- **Information Holder** - Holds data, minimal behavior
|
|
104
|
+
- **Structurer** - Manages relationships between objects
|
|
105
|
+
- **Service Provider** - Performs work, stateless operations
|
|
106
|
+
- **Coordinator** - Orchestrates multiple services
|
|
107
|
+
- **Controller** - Makes decisions, delegates work
|
|
108
|
+
- **Interfacer** - Transforms data between systems
|
|
109
|
+
|
|
110
|
+
See: [references/object-design.md](references/object-design.md)
|
|
111
|
+
|
|
112
|
+
### 5. Manage Complexity Ruthlessly
|
|
113
|
+
|
|
114
|
+
**Essential complexity** = inherent to the problem domain
|
|
115
|
+
**Accidental complexity** = introduced by our solutions
|
|
116
|
+
|
|
117
|
+
**Detect complexity through:**
|
|
118
|
+
- Change amplification (small change = many files)
|
|
119
|
+
- Cognitive load (hard to understand)
|
|
120
|
+
- Unknown unknowns (surprises in behavior)
|
|
121
|
+
|
|
122
|
+
**Fight complexity with:**
|
|
123
|
+
- YAGNI - Don't build what you don't need NOW
|
|
124
|
+
- KISS - Simplest solution that works
|
|
125
|
+
- DRY - But only after Rule of Three (wait for 3 duplications)
|
|
126
|
+
|
|
127
|
+
See: [references/complexity.md](references/complexity.md)
|
|
128
|
+
|
|
129
|
+
### 6. Architect for Change
|
|
130
|
+
|
|
131
|
+
**Vertical Slicing:**
|
|
132
|
+
- Features as end-to-end slices
|
|
133
|
+
- Each feature self-contained
|
|
134
|
+
|
|
135
|
+
**Horizontal Decoupling:**
|
|
136
|
+
- Layers don't know about each other's internals
|
|
137
|
+
- Dependencies point inward (toward domain)
|
|
138
|
+
|
|
139
|
+
**The Dependency Rule:**
|
|
140
|
+
- Source code dependencies point toward high-level policies
|
|
141
|
+
- Infrastructure depends on domain, never reverse
|
|
142
|
+
|
|
143
|
+
See: [references/architecture.md](references/architecture.md)
|
|
144
|
+
|
|
145
|
+
## The Four Elements of Simple Design (XP)
|
|
146
|
+
|
|
147
|
+
In priority order:
|
|
148
|
+
1. **Runs all the tests** - Must work correctly
|
|
149
|
+
2. **Expresses intent** - Readable, reveals purpose
|
|
150
|
+
3. **No duplication** - DRY (but Rule of Three)
|
|
151
|
+
4. **Minimal** - Fewest classes, methods possible
|
|
152
|
+
|
|
153
|
+
## Code Smell Detection
|
|
154
|
+
|
|
155
|
+
**Stop and refactor when you see:**
|
|
156
|
+
|
|
157
|
+
| Smell | Solution |
|
|
158
|
+
| ---------------------- | --------------------------------------- |
|
|
159
|
+
| Long Method | Extract methods, compose method pattern |
|
|
160
|
+
| Large Class | Extract class, single responsibility |
|
|
161
|
+
| Long Parameter List | Introduce parameter object |
|
|
162
|
+
| Divergent Change | Split into focused classes |
|
|
163
|
+
| Shotgun Surgery | Move related code together |
|
|
164
|
+
| Feature Envy | Move method to the envied class |
|
|
165
|
+
| Data Clumps | Extract class for grouped data |
|
|
166
|
+
| Primitive Obsession | Wrap in value objects |
|
|
167
|
+
| Switch Statements | Replace with polymorphism |
|
|
168
|
+
| Parallel Inheritance | Merge hierarchies |
|
|
169
|
+
| Speculative Generality | YAGNI - remove unused abstractions |
|
|
170
|
+
|
|
171
|
+
See: [references/code-smells.md](references/code-smells.md)
|
|
172
|
+
|
|
173
|
+
## Design Patterns Awareness
|
|
174
|
+
|
|
175
|
+
**Creational:** Singleton, Factory, Builder, Prototype
|
|
176
|
+
**Structural:** Adapter, Bridge, Decorator, Composite, Proxy
|
|
177
|
+
**Behavioral:** Strategy, Observer, Template Method, Command
|
|
178
|
+
|
|
179
|
+
**Warning:** Don't force patterns. Let them emerge from refactoring.
|
|
180
|
+
|
|
181
|
+
See: [references/design-patterns.md](references/design-patterns.md)
|
|
182
|
+
|
|
183
|
+
## Testing Strategy
|
|
184
|
+
|
|
185
|
+
**Test Types (from inner to outer):**
|
|
186
|
+
1. **Unit Tests** - Single class/function, fast, isolated
|
|
187
|
+
2. **Integration Tests** - Multiple components together
|
|
188
|
+
3. **E2E/Acceptance Tests** - Full system, user perspective
|
|
189
|
+
|
|
190
|
+
**Arrange-Act-Assert Pattern:**
|
|
191
|
+
```typescript
|
|
192
|
+
// Arrange - Set up test state
|
|
193
|
+
const calculator = new Calculator();
|
|
194
|
+
|
|
195
|
+
// Act - Execute the behavior
|
|
196
|
+
const result = calculator.add(2, 3);
|
|
197
|
+
|
|
198
|
+
// Assert - Verify the outcome
|
|
199
|
+
expect(result).toBe(5);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Test Naming:** Use concrete examples, not abstract statements
|
|
203
|
+
```typescript
|
|
204
|
+
// BAD: 'can add numbers'
|
|
205
|
+
// GOOD: 'when adding 2 + 3, returns 5'
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
See: [references/testing.md](references/testing.md)
|
|
209
|
+
|
|
210
|
+
## Behavioral Principles
|
|
211
|
+
|
|
212
|
+
- **Tell, Don't Ask** - Command objects, don't query and decide
|
|
213
|
+
- **Design by Contract** - Preconditions, postconditions, invariants
|
|
214
|
+
- **Hollywood Principle** - "Don't call us, we'll call you" (IoC)
|
|
215
|
+
- **Law of Demeter** - Only talk to immediate friends
|
|
216
|
+
|
|
217
|
+
## Pre-Code Checklist
|
|
218
|
+
|
|
219
|
+
Before writing ANY code, answer:
|
|
220
|
+
|
|
221
|
+
1. [ ] Do I understand the requirement? (Write acceptance criteria first)
|
|
222
|
+
2. [ ] What test will I write first?
|
|
223
|
+
3. [ ] What is the simplest solution?
|
|
224
|
+
4. [ ] What patterns might apply? (Don't force them)
|
|
225
|
+
5. [ ] Am I solving a real problem or a hypothetical one?
|
|
226
|
+
|
|
227
|
+
## During-Code Checklist
|
|
228
|
+
|
|
229
|
+
While coding, continuously ask:
|
|
230
|
+
|
|
231
|
+
1. [ ] Is this the simplest thing that could work?
|
|
232
|
+
2. [ ] Does this class have a single responsibility?
|
|
233
|
+
3. [ ] Am I depending on abstractions or concretions?
|
|
234
|
+
4. [ ] Can I name this more clearly?
|
|
235
|
+
5. [ ] Is there duplication I should extract? (Rule of Three)
|
|
236
|
+
|
|
237
|
+
## Post-Code Checklist
|
|
238
|
+
|
|
239
|
+
After the code works:
|
|
240
|
+
|
|
241
|
+
1. [ ] Do all tests pass?
|
|
242
|
+
2. [ ] Is there any dead code to remove?
|
|
243
|
+
3. [ ] Can I simplify any complex conditions?
|
|
244
|
+
4. [ ] Are names still accurate after changes?
|
|
245
|
+
5. [ ] Would a junior understand this in 6 months?
|
|
246
|
+
|
|
247
|
+
## Red Flags - Stop and Rethink
|
|
248
|
+
|
|
249
|
+
- Writing code without a test
|
|
250
|
+
- Class with more than 2 instance variables
|
|
251
|
+
- Method longer than 10 lines
|
|
252
|
+
- More than one level of indentation
|
|
253
|
+
- Using `else` when early return works
|
|
254
|
+
- Hardcoding values that should be configurable
|
|
255
|
+
- Creating abstractions before the third duplication
|
|
256
|
+
- Adding features "just in case"
|
|
257
|
+
- Depending on concrete implementations
|
|
258
|
+
- God classes that know everything
|
|
259
|
+
|
|
260
|
+
## Remember
|
|
261
|
+
|
|
262
|
+
> "A little bit of duplication is 10x better than the wrong abstraction."
|
|
263
|
+
|
|
264
|
+
> "Focus on WHAT needs to happen, not HOW it needs to happen."
|
|
265
|
+
|
|
266
|
+
> "Design principles become second nature through practice. Eventually, you won't think about SOLID - you'll just write SOLID code."
|
|
267
|
+
|
|
268
|
+
The journey: Code-first → Best-practice-first → Pattern-first → Responsibility-first → **Systems Thinking**
|
|
269
|
+
|
|
270
|
+
Your goal is to reach systems thinking - where principles are internalized and you focus on optimizing the entire development process.
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: solid-ruby
|
|
3
|
+
description: Ruby-focused. Transforms junior-level code into senior-engineer quality software through SOLID, TDD, and clean code. Examples and references use Ruby/RSpec. Use when writing or refactoring Ruby code, planning architecture, reviewing code, or creating tests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Solid Skills: Professional Software Engineering (Ruby)
|
|
7
|
+
|
|
8
|
+
**This skill is Ruby-oriented.** All code examples and reference docs use Ruby (and RSpec for tests). The principles (SOLID, TDD, clean code, design patterns) apply to any object-oriented language—these examples are in Ruby.
|
|
9
|
+
|
|
10
|
+
You are now operating as a senior software engineer. Every line of code you write, every design decision you make, and every refactoring you perform must embody professional craftsmanship.
|
|
11
|
+
|
|
12
|
+
## When This Skill Applies
|
|
13
|
+
|
|
14
|
+
**ALWAYS use this skill when:**
|
|
15
|
+
- Writing ANY Ruby code (features, fixes, utilities)
|
|
16
|
+
- Refactoring existing Ruby code
|
|
17
|
+
- Planning or designing architecture
|
|
18
|
+
- Reviewing code quality
|
|
19
|
+
- Debugging issues
|
|
20
|
+
- Creating tests (RSpec, Minitest)
|
|
21
|
+
- Making design decisions
|
|
22
|
+
|
|
23
|
+
## Core Philosophy
|
|
24
|
+
|
|
25
|
+
> "Code is to create products for users & customers. Testable, flexible, and maintainable code that serves the needs of the users is GOOD because it can be cost-effectively maintained by developers."
|
|
26
|
+
|
|
27
|
+
The goal of software: Enable developers to **discover, understand, add, change, remove, test, debug, deploy**, and **monitor** features efficiently.
|
|
28
|
+
|
|
29
|
+
## The Non-Negotiable Process
|
|
30
|
+
|
|
31
|
+
### 1. ALWAYS Start with Tests (TDD)
|
|
32
|
+
|
|
33
|
+
**Red-Green-Refactor is not optional:**
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
1. RED - Write a failing test that describes the behavior
|
|
37
|
+
2. GREEN - Write the SIMPLEST code to make it pass
|
|
38
|
+
3. REFACTOR - Clean up, remove duplication (Rule of Three)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**The Three Laws of TDD:**
|
|
42
|
+
1. You cannot write production code unless it makes a failing test pass
|
|
43
|
+
2. You cannot write more test code than is sufficient to fail
|
|
44
|
+
3. You cannot write more production code than is sufficient to pass
|
|
45
|
+
|
|
46
|
+
**Design happens during REFACTORING, not during coding.**
|
|
47
|
+
|
|
48
|
+
See: [references/tdd.md](references/tdd.md)
|
|
49
|
+
|
|
50
|
+
### 2. Apply SOLID Principles Rigorously
|
|
51
|
+
|
|
52
|
+
Every class, every module, every method:
|
|
53
|
+
|
|
54
|
+
| Principle | Question to Ask |
|
|
55
|
+
| ------------------------------- | ------------------------------------------------- |
|
|
56
|
+
| **S**RP - Single Responsibility | "Does this have ONE reason to change?" |
|
|
57
|
+
| **O**CP - Open/Closed | "Can I extend without modifying?" |
|
|
58
|
+
| **L**SP - Liskov Substitution | "Can subtypes replace base types safely?" |
|
|
59
|
+
| **I**SP - Interface Segregation | "Are clients forced to depend on unused methods?" |
|
|
60
|
+
| **D**IP - Dependency Inversion | "Do high-level modules depend on abstractions?" |
|
|
61
|
+
|
|
62
|
+
See: [references/solid-principles.md](references/solid-principles.md)
|
|
63
|
+
|
|
64
|
+
### 3. Write Clean, Human-Readable Code
|
|
65
|
+
|
|
66
|
+
**Naming (in order of priority):**
|
|
67
|
+
1. **Consistency** - Same concept = same name everywhere
|
|
68
|
+
2. **Understandability** - Domain language, not technical jargon
|
|
69
|
+
3. **Specificity** - Precise, not vague (avoid `data`, `info`, `manager`)
|
|
70
|
+
4. **Brevity** - Short but not cryptic
|
|
71
|
+
5. **Searchability** - Unique, greppable names
|
|
72
|
+
|
|
73
|
+
**Structure:**
|
|
74
|
+
- One level of indentation per method
|
|
75
|
+
- Guard clauses and early returns; avoid `else` when possible
|
|
76
|
+
- **Wrap primitives in value objects** - IDs, emails, money amounts, etc.
|
|
77
|
+
- First-class collections (wrap arrays in dedicated classes)
|
|
78
|
+
- One dot per line (Law of Demeter)
|
|
79
|
+
- Keep classes small (< 50 lines), methods small (< 10 lines)
|
|
80
|
+
- No more than two instance variables per class
|
|
81
|
+
|
|
82
|
+
**Value Objects in Ruby:**
|
|
83
|
+
```ruby
|
|
84
|
+
# ALWAYS create value objects for domain concepts:
|
|
85
|
+
class UserId
|
|
86
|
+
def initialize(value) = @value = value.freeze
|
|
87
|
+
attr_reader :value
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class Email
|
|
91
|
+
def initialize(value)
|
|
92
|
+
raise InvalidEmail unless value.match?(/\A[^@]+@[^@]+\z/)
|
|
93
|
+
@value = value.freeze
|
|
94
|
+
end
|
|
95
|
+
attr_reader :value
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class Money
|
|
99
|
+
def initialize(amount, currency)
|
|
100
|
+
@amount = amount
|
|
101
|
+
@currency = currency.freeze
|
|
102
|
+
end
|
|
103
|
+
attr_reader :amount, :currency
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# NEVER use raw primitives for domain concepts:
|
|
107
|
+
# BAD: def create_order(user_id:, email:)
|
|
108
|
+
# GOOD: def create_order(user_id: UserId, email: Email)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
See: [references/clean-code.md](references/clean-code.md)
|
|
112
|
+
|
|
113
|
+
### 4. Design with Responsibility in Mind
|
|
114
|
+
|
|
115
|
+
**Ask these questions for every class:**
|
|
116
|
+
1. "What pattern is this?" (Entity, Service, Repository, Factory, etc.)
|
|
117
|
+
2. "Is it doing too much?" (Check object calisthenics)
|
|
118
|
+
|
|
119
|
+
**Object Stereotypes:**
|
|
120
|
+
- **Information Holder** - Holds data, minimal behavior
|
|
121
|
+
- **Structurer** - Manages relationships between objects
|
|
122
|
+
- **Service Provider** - Performs work, stateless operations
|
|
123
|
+
- **Coordinator** - Orchestrates multiple services
|
|
124
|
+
- **Controller** - Makes decisions, delegates work
|
|
125
|
+
- **Interfacer** - Transforms data between systems
|
|
126
|
+
|
|
127
|
+
See: [references/object-design.md](references/object-design.md)
|
|
128
|
+
|
|
129
|
+
### 5. Manage Complexity Ruthlessly
|
|
130
|
+
|
|
131
|
+
**Essential complexity** = inherent to the problem domain
|
|
132
|
+
**Accidental complexity** = introduced by our solutions
|
|
133
|
+
|
|
134
|
+
**Fight complexity with:**
|
|
135
|
+
- YAGNI - Don't build what you don't need NOW
|
|
136
|
+
- KISS - Simplest solution that works
|
|
137
|
+
- DRY - But only after Rule of Three (wait for 3 duplications)
|
|
138
|
+
|
|
139
|
+
See: [references/complexity.md](references/complexity.md)
|
|
140
|
+
|
|
141
|
+
### 6. Architect for Change
|
|
142
|
+
|
|
143
|
+
**Vertical Slicing:** Features as end-to-end slices; each feature self-contained.
|
|
144
|
+
|
|
145
|
+
**Dependency Rule:** Dependencies point toward high-level policies. Infrastructure depends on domain, never reverse. Prefer dependency injection and interfaces (abstract classes or duck-typed contracts).
|
|
146
|
+
|
|
147
|
+
See: [references/architecture.md](references/architecture.md)
|
|
148
|
+
|
|
149
|
+
## The Four Elements of Simple Design (XP)
|
|
150
|
+
|
|
151
|
+
1. **Runs all the tests** - Must work correctly
|
|
152
|
+
2. **Expresses intent** - Readable, reveals purpose
|
|
153
|
+
3. **No duplication** - DRY (but Rule of Three)
|
|
154
|
+
4. **Minimal** - Fewest classes, methods possible
|
|
155
|
+
|
|
156
|
+
## Code Smell Detection
|
|
157
|
+
|
|
158
|
+
**Stop and refactor when you see:** Long Method, Large Class, Long Parameter List, Divergent Change, Shotgun Surgery, Feature Envy, Data Clumps, Primitive Obsession, Switch/type checks (replace with polymorphism), Speculative Generality.
|
|
159
|
+
|
|
160
|
+
See: [references/code-smells.md](references/code-smells.md)
|
|
161
|
+
|
|
162
|
+
## Design Patterns Awareness
|
|
163
|
+
|
|
164
|
+
**Creational:** Singleton, Factory, Builder
|
|
165
|
+
**Structural:** Adapter, Decorator, Composite
|
|
166
|
+
**Behavioral:** Strategy, Observer, Template Method, Command
|
|
167
|
+
|
|
168
|
+
Don't force patterns. Let them emerge from refactoring.
|
|
169
|
+
|
|
170
|
+
See: [references/design-patterns.md](references/design-patterns.md)
|
|
171
|
+
|
|
172
|
+
## Testing Strategy (RSpec)
|
|
173
|
+
|
|
174
|
+
**Arrange-Act-Assert:**
|
|
175
|
+
```ruby
|
|
176
|
+
# Arrange - Set up test state
|
|
177
|
+
calculator = Calculator.new
|
|
178
|
+
|
|
179
|
+
# Act - Execute the behavior
|
|
180
|
+
result = calculator.add(2, 3)
|
|
181
|
+
|
|
182
|
+
# Assert - Verify the outcome
|
|
183
|
+
expect(result).to eq(5)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Test naming:** Use concrete examples, not abstract statements.
|
|
187
|
+
```ruby
|
|
188
|
+
# BAD: it 'can add numbers'
|
|
189
|
+
# GOOD: it 'returns 5 when adding 2 and 3'
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
See: [references/testing.md](references/testing.md)
|
|
193
|
+
|
|
194
|
+
## Behavioral Principles
|
|
195
|
+
|
|
196
|
+
- **Tell, Don't Ask** - Command objects; don't query and decide
|
|
197
|
+
- **Law of Demeter** - Only talk to immediate friends (one dot per line)
|
|
198
|
+
- **Design by Contract** - Preconditions, postconditions, invariants
|
|
199
|
+
|
|
200
|
+
## Pre-Code Checklist
|
|
201
|
+
|
|
202
|
+
1. [ ] Do I understand the requirement? (Write acceptance criteria first)
|
|
203
|
+
2. [ ] What test will I write first?
|
|
204
|
+
3. [ ] What is the simplest solution?
|
|
205
|
+
4. [ ] Am I solving a real problem or a hypothetical one?
|
|
206
|
+
|
|
207
|
+
## Red Flags - Stop and Rethink
|
|
208
|
+
|
|
209
|
+
- Writing code without a test
|
|
210
|
+
- Class with more than 2 instance variables
|
|
211
|
+
- Method longer than 10 lines
|
|
212
|
+
- More than one level of indentation
|
|
213
|
+
- Using `else` when early return works
|
|
214
|
+
- Creating abstractions before the third duplication
|
|
215
|
+
- Depending on concrete classes instead of injecting dependencies
|
|
216
|
+
|
|
217
|
+
## Remember
|
|
218
|
+
|
|
219
|
+
> "A little bit of duplication is 10x better than the wrong abstraction."
|
|
220
|
+
|
|
221
|
+
> "Focus on WHAT needs to happen, not HOW it needs to happen."
|
|
222
|
+
|
|
223
|
+
Your goal: internalize these principles so you write SOLID, testable Ruby by habit.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "yaml"
|
|
4
|
+
|
|
5
|
+
module OllamaAgent
|
|
6
|
+
# Bundled Markdown skills under lib/ollama_agent/prompt_skills plus optional paths (env / Agent kwargs).
|
|
7
|
+
# rubocop:disable Metrics/ModuleLength -- single cohesive loader; split only if it grows further
|
|
8
|
+
module PromptSkills
|
|
9
|
+
BUNDLED_DIR = File.join(__dir__, "prompt_skills")
|
|
10
|
+
MANIFEST_PATH = File.join(BUNDLED_DIR, "manifest.yml")
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def strip_frontmatter(text)
|
|
15
|
+
return "" if text.nil?
|
|
16
|
+
|
|
17
|
+
s = text.to_s
|
|
18
|
+
lines = s.lines
|
|
19
|
+
return s unless lines.first&.strip == "---"
|
|
20
|
+
|
|
21
|
+
closing = (1...lines.size).find { |i| lines[i].strip == "---" }
|
|
22
|
+
return s if closing.nil?
|
|
23
|
+
|
|
24
|
+
lines[(closing + 1)..].join.lstrip
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def read_skill_file(path)
|
|
28
|
+
strip_frontmatter(File.read(path, encoding: Encoding::UTF_8))
|
|
29
|
+
rescue Errno::ENOENT
|
|
30
|
+
""
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# rubocop:disable Metrics/ParameterLists -- mirrors Agent keyword surface
|
|
34
|
+
def compose(base:, skills_enabled: nil, skills_include: nil, skills_exclude: nil,
|
|
35
|
+
skill_paths: nil, external_skills_enabled: nil)
|
|
36
|
+
parts = [base.to_s.strip]
|
|
37
|
+
if bundled_enabled?(skills_enabled)
|
|
38
|
+
bundled = bundled_text(skills_include: skills_include, skills_exclude: skills_exclude)
|
|
39
|
+
parts << bundled unless bundled.empty?
|
|
40
|
+
end
|
|
41
|
+
ext = external_text(skill_paths: skill_paths, external_skills_enabled: external_skills_enabled)
|
|
42
|
+
parts << ext unless ext.empty?
|
|
43
|
+
parts.reject(&:empty?).join("\n\n---\n\n")
|
|
44
|
+
end
|
|
45
|
+
# rubocop:enable Metrics/ParameterLists
|
|
46
|
+
|
|
47
|
+
def bundled_enabled?(skills_enabled)
|
|
48
|
+
truthy?(skills_enabled, default: true)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def external_enabled?(external_skills_enabled)
|
|
52
|
+
truthy?(external_skills_enabled, default: true)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def external_text(skill_paths: nil, external_skills_enabled: nil)
|
|
56
|
+
return "" unless external_enabled?(external_skills_enabled)
|
|
57
|
+
|
|
58
|
+
merged = merge_skill_paths(skill_paths)
|
|
59
|
+
bodies = merged.flat_map { |segment| bodies_for_path_segment(segment) }
|
|
60
|
+
bodies.reject(&:empty?).join("\n\n---\n\n")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def bodies_for_path_segment(segment)
|
|
64
|
+
path = File.expand_path(segment)
|
|
65
|
+
return [read_skill_file(path)] if File.file?(path)
|
|
66
|
+
return [] unless File.directory?(path)
|
|
67
|
+
|
|
68
|
+
Dir.glob(File.join(path, "*.md")).map { |f| read_skill_file(f) }
|
|
69
|
+
end
|
|
70
|
+
private_class_method :bodies_for_path_segment
|
|
71
|
+
|
|
72
|
+
def bundled_text(skills_include: nil, skills_exclude: nil)
|
|
73
|
+
entries = manifest_entries
|
|
74
|
+
return "" if entries.empty?
|
|
75
|
+
|
|
76
|
+
filter_ids(entries, skills_include: skills_include, skills_exclude: skills_exclude).filter_map do |entry|
|
|
77
|
+
body = read_skill_file(File.join(BUNDLED_DIR, entry.fetch("file")))
|
|
78
|
+
next if body.empty?
|
|
79
|
+
|
|
80
|
+
"## #{entry.fetch("id")}\n\n#{body}"
|
|
81
|
+
end.join("\n\n---\n\n")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def merge_skill_paths(paths)
|
|
85
|
+
env = split_paths(ENV.fetch("OLLAMA_AGENT_SKILL_PATHS", nil))
|
|
86
|
+
extra =
|
|
87
|
+
case paths
|
|
88
|
+
when nil then []
|
|
89
|
+
when Array then paths.compact.map(&:to_s)
|
|
90
|
+
else split_paths(paths.to_s)
|
|
91
|
+
end
|
|
92
|
+
(env + extra).uniq
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def split_paths(raw)
|
|
96
|
+
return [] if raw.nil?
|
|
97
|
+
|
|
98
|
+
s = raw.to_s.strip
|
|
99
|
+
return [] if s.empty?
|
|
100
|
+
|
|
101
|
+
s.split(File::PATH_SEPARATOR).map(&:strip).reject(&:empty?)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def truthy?(value, default:)
|
|
105
|
+
return default if value.nil?
|
|
106
|
+
|
|
107
|
+
case value
|
|
108
|
+
when true then true
|
|
109
|
+
when false then false
|
|
110
|
+
else
|
|
111
|
+
parse_string_truthy(value.to_s, default: default)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def parse_string_truthy(str, default:)
|
|
116
|
+
s = str.strip.downcase
|
|
117
|
+
return default if s.empty?
|
|
118
|
+
|
|
119
|
+
return false if %w[0 false no off].include?(s)
|
|
120
|
+
return true if %w[1 true yes on].include?(s)
|
|
121
|
+
|
|
122
|
+
default
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def parse_id_list(raw)
|
|
126
|
+
return nil if raw.nil?
|
|
127
|
+
|
|
128
|
+
s = raw.to_s.strip
|
|
129
|
+
return nil if s.empty?
|
|
130
|
+
|
|
131
|
+
s.split(",").map(&:strip).reject(&:empty?).map(&:downcase)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def env_truthy(env_key, default: true)
|
|
135
|
+
raw = ENV.fetch(env_key, nil)
|
|
136
|
+
return default if raw.nil? || raw.to_s.strip.empty?
|
|
137
|
+
|
|
138
|
+
parse_string_truthy(raw.to_s, default: default)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# rubocop:disable Metrics/AbcSize -- straightforward filter + optional reorder
|
|
142
|
+
def filter_ids(entries, skills_include: nil, skills_exclude: nil)
|
|
143
|
+
include_list = parse_id_list(skills_include)
|
|
144
|
+
exclude_ids = parse_id_list(skills_exclude) || []
|
|
145
|
+
|
|
146
|
+
ordered = entries.dup
|
|
147
|
+
if include_list
|
|
148
|
+
id_index = include_list.each_with_index.to_h
|
|
149
|
+
ordered = ordered.select { |e| id_index.key?(e.fetch("id").downcase) }
|
|
150
|
+
ordered.sort_by! { |e| id_index[e.fetch("id").downcase] }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
ordered.reject { |e| exclude_ids.include?(e.fetch("id").downcase) }
|
|
154
|
+
end
|
|
155
|
+
# rubocop:enable Metrics/AbcSize
|
|
156
|
+
|
|
157
|
+
def manifest_entries
|
|
158
|
+
return [] unless File.file?(MANIFEST_PATH)
|
|
159
|
+
|
|
160
|
+
data = YAML.safe_load(
|
|
161
|
+
File.read(MANIFEST_PATH, encoding: Encoding::UTF_8),
|
|
162
|
+
permitted_classes: [],
|
|
163
|
+
aliases: true
|
|
164
|
+
)
|
|
165
|
+
Array(data&.fetch("skills", nil))
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
# rubocop:enable Metrics/ModuleLength
|
|
169
|
+
end
|
|
@@ -21,7 +21,10 @@ module OllamaAgent
|
|
|
21
21
|
paths = collect_relative_paths(base, cap)
|
|
22
22
|
return "(no files listed)" if paths.empty?
|
|
23
23
|
|
|
24
|
-
paths.sort.join("\n")
|
|
24
|
+
body = paths.sort.join("\n")
|
|
25
|
+
return body unless paths.size >= cap
|
|
26
|
+
|
|
27
|
+
"#{body}\n(list truncated at #{cap} entries; pass max_entries or narrow directory)"
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
def collect_relative_paths(base, cap)
|