htm 0.0.10 → 0.0.14
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/.dictate.toml +46 -0
- data/.envrc +2 -0
- data/CHANGELOG.md +86 -3
- data/README.md +86 -7
- data/Rakefile +14 -2
- data/bin/htm_mcp.rb +621 -0
- data/config/database.yml +20 -13
- data/db/migrate/00010_add_soft_delete_to_associations.rb +29 -0
- data/db/migrate/00011_add_performance_indexes.rb +21 -0
- data/db/migrate/00012_add_tags_trigram_index.rb +18 -0
- data/db/migrate/00013_enable_lz4_compression.rb +43 -0
- data/db/schema.sql +49 -92
- data/docs/api/index.md +1 -1
- data/docs/api/yard/HTM.md +2 -4
- data/docs/architecture/index.md +1 -1
- data/docs/development/index.md +1 -1
- data/docs/getting-started/index.md +1 -1
- data/docs/guides/index.md +1 -1
- data/docs/images/telemetry-architecture.svg +153 -0
- data/docs/telemetry.md +391 -0
- data/examples/README.md +171 -1
- data/examples/cli_app/README.md +1 -1
- data/examples/cli_app/htm_cli.rb +1 -1
- data/examples/mcp_client.rb +529 -0
- data/examples/sinatra_app/app.rb +1 -1
- data/examples/telemetry/README.md +147 -0
- data/examples/telemetry/SETUP_README.md +169 -0
- data/examples/telemetry/demo.rb +498 -0
- data/examples/telemetry/grafana/dashboards/htm-metrics.json +457 -0
- data/lib/htm/configuration.rb +261 -70
- data/lib/htm/database.rb +46 -22
- data/lib/htm/embedding_service.rb +24 -14
- data/lib/htm/errors.rb +15 -1
- data/lib/htm/jobs/generate_embedding_job.rb +19 -0
- data/lib/htm/jobs/generate_propositions_job.rb +103 -0
- data/lib/htm/jobs/generate_tags_job.rb +24 -0
- data/lib/htm/loaders/markdown_chunker.rb +79 -0
- data/lib/htm/loaders/markdown_loader.rb +41 -15
- data/lib/htm/long_term_memory/fulltext_search.rb +138 -0
- data/lib/htm/long_term_memory/hybrid_search.rb +324 -0
- data/lib/htm/long_term_memory/node_operations.rb +209 -0
- data/lib/htm/long_term_memory/relevance_scorer.rb +355 -0
- data/lib/htm/long_term_memory/robot_operations.rb +34 -0
- data/lib/htm/long_term_memory/tag_operations.rb +428 -0
- data/lib/htm/long_term_memory/vector_search.rb +109 -0
- data/lib/htm/long_term_memory.rb +51 -1153
- data/lib/htm/models/node.rb +35 -2
- data/lib/htm/models/node_tag.rb +31 -0
- data/lib/htm/models/robot_node.rb +31 -0
- data/lib/htm/models/tag.rb +44 -0
- data/lib/htm/proposition_service.rb +169 -0
- data/lib/htm/query_cache.rb +214 -0
- data/lib/htm/sql_builder.rb +178 -0
- data/lib/htm/tag_service.rb +16 -6
- data/lib/htm/tasks.rb +8 -2
- data/lib/htm/telemetry.rb +224 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm.rb +64 -3
- data/lib/tasks/doc.rake +1 -1
- data/lib/tasks/htm.rake +259 -13
- data/mkdocs.yml +96 -96
- metadata +75 -18
- data/.aigcm_msg +0 -1
- data/.claude/settings.local.json +0 -92
- data/CLAUDE.md +0 -603
- data/examples/cli_app/temp.log +0 -93
- data/lib/htm/loaders/paragraph_chunker.rb +0 -112
- data/notes/ARCHITECTURE_REVIEW.md +0 -1167
- data/notes/IMPLEMENTATION_SUMMARY.md +0 -606
- data/notes/MULTI_FRAMEWORK_IMPLEMENTATION.md +0 -451
- data/notes/next_steps.md +0 -100
- data/notes/plan.md +0 -627
- data/notes/tag_ontology_enhancement_ideas.md +0 -222
- data/notes/timescaledb_removal_summary.md +0 -200
data/notes/plan.md
DELETED
|
@@ -1,627 +0,0 @@
|
|
|
1
|
-
# HTM Multi-Framework Support Implementation Plan
|
|
2
|
-
|
|
3
|
-
**Goal:** Enable HTM gem to work seamlessly in CLI, Sinatra, and Rails applications
|
|
4
|
-
|
|
5
|
-
**Date:** 2025-11-09
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Executive Summary
|
|
10
|
-
|
|
11
|
-
The HTM gem is currently well-architected but uses simple `Thread.new` for background jobs, which is insufficient for production web applications. This plan outlines the changes needed to support three application types:
|
|
12
|
-
|
|
13
|
-
1. **Standalone CLI Applications** - Synchronous job execution, progress feedback
|
|
14
|
-
2. **Sinatra-based Web Apps** - Sidekiq/inline job backends, thread safety
|
|
15
|
-
3. **Rails-based Web Apps** - ActiveJob integration, Rails conventions
|
|
16
|
-
|
|
17
|
-
## Current State Analysis
|
|
18
|
-
|
|
19
|
-
### Strengths
|
|
20
|
-
- Library-based design (not monolithic)
|
|
21
|
-
- Environment detection (`RAILS_ENV || RACK_ENV`)
|
|
22
|
-
- Configurable logger, embedding, and tag services
|
|
23
|
-
- Connection pooling configured
|
|
24
|
-
- ActiveRecord for database abstraction
|
|
25
|
-
|
|
26
|
-
### Critical Gap
|
|
27
|
-
Background job processing uses `Thread.new` (lib/htm.rb:278-280, 298-300), which:
|
|
28
|
-
- Threads may die when request completes in some Rack servers
|
|
29
|
-
- No job persistence/retry
|
|
30
|
-
- No monitoring/observability
|
|
31
|
-
- Not suitable for production web applications
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## Required Changes by Application Type
|
|
36
|
-
|
|
37
|
-
### 1. Standalone CLI Applications ✅ Mostly Ready
|
|
38
|
-
|
|
39
|
-
**Current Support:**
|
|
40
|
-
- Already works via `examples/basic_usage.rb`
|
|
41
|
-
- Direct database connection via `HTM_DBURL`
|
|
42
|
-
- Synchronous operation possible
|
|
43
|
-
|
|
44
|
-
**Needs:**
|
|
45
|
-
- **Job Processing Option**: Add synchronous mode for CLI
|
|
46
|
-
- **Progress Indicators**: CLI-friendly output for background operations
|
|
47
|
-
- **Executable Binary**: Optional `exe/htm` for CLI commands
|
|
48
|
-
- **Documentation**: CLI usage guide with examples
|
|
49
|
-
|
|
50
|
-
**Implementation Priority:** Medium
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
### 2. Sinatra-based Web Applications ⚠️ Needs Work
|
|
55
|
-
|
|
56
|
-
**Current Support:**
|
|
57
|
-
- Library can be required
|
|
58
|
-
- Configuration system works
|
|
59
|
-
|
|
60
|
-
**Critical Needs:**
|
|
61
|
-
|
|
62
|
-
**A. Background Job Integration** ⭐ **CRITICAL**
|
|
63
|
-
- Pluggable job backend (Sidekiq, inline, thread)
|
|
64
|
-
- Thread safety verification
|
|
65
|
-
- Connection pooling validation
|
|
66
|
-
|
|
67
|
-
**B. Rack Middleware** (Optional but Recommended)
|
|
68
|
-
- Automatic HTM instance per request
|
|
69
|
-
- Session-based robot identification
|
|
70
|
-
|
|
71
|
-
**C. Example Sinatra App**
|
|
72
|
-
- Full working example with Sidekiq
|
|
73
|
-
- Best practices documentation
|
|
74
|
-
|
|
75
|
-
**Implementation Priority:** **HIGH**
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
### 3. Rails-based Web Applications ⚠️ Needs Significant Work
|
|
80
|
-
|
|
81
|
-
**Current Support:**
|
|
82
|
-
- ActiveRecord already used internally
|
|
83
|
-
- Environment detection works
|
|
84
|
-
- Rake tasks exist
|
|
85
|
-
|
|
86
|
-
**Critical Needs:**
|
|
87
|
-
|
|
88
|
-
**A. ActiveJob Integration** ⭐ **CRITICAL**
|
|
89
|
-
- Job classes inheriting from ActiveJob::Base
|
|
90
|
-
- Queue configuration
|
|
91
|
-
- Rails job conventions
|
|
92
|
-
|
|
93
|
-
**B. Rails Connection Sharing**
|
|
94
|
-
- Detect and use Rails' database connection
|
|
95
|
-
- Avoid duplicate connection pools
|
|
96
|
-
|
|
97
|
-
**C. Rails Engine/Railtie**
|
|
98
|
-
- Auto-configuration on Rails boot
|
|
99
|
-
- Logger integration
|
|
100
|
-
- Rake tasks auto-loading
|
|
101
|
-
|
|
102
|
-
**D. Rails Generator**
|
|
103
|
-
- `rails generate htm:install` command
|
|
104
|
-
- Creates initializer and migrations
|
|
105
|
-
|
|
106
|
-
**E. Test Environment Handling**
|
|
107
|
-
- Synchronous job execution in tests
|
|
108
|
-
- Test helpers
|
|
109
|
-
|
|
110
|
-
**F. Example Rails App**
|
|
111
|
-
- Full Rails 7 application
|
|
112
|
-
- Best practices
|
|
113
|
-
|
|
114
|
-
**Implementation Priority:** **HIGH**
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## Cross-Cutting Improvements
|
|
119
|
-
|
|
120
|
-
### 1. Pluggable Job Backend ⭐ **HIGHEST PRIORITY**
|
|
121
|
-
|
|
122
|
-
**Create abstraction for background jobs:**
|
|
123
|
-
|
|
124
|
-
```ruby
|
|
125
|
-
# lib/htm/job_adapter.rb
|
|
126
|
-
module HTM
|
|
127
|
-
module JobAdapter
|
|
128
|
-
def self.enqueue(job_class, **params)
|
|
129
|
-
case HTM.configuration.job_backend
|
|
130
|
-
when :active_job
|
|
131
|
-
job_class.perform_later(**params)
|
|
132
|
-
when :sidekiq
|
|
133
|
-
job_class.perform_async(**params)
|
|
134
|
-
when :inline
|
|
135
|
-
job_class.perform(**params)
|
|
136
|
-
when :thread
|
|
137
|
-
Thread.new { job_class.perform(**params) }
|
|
138
|
-
else
|
|
139
|
-
raise "Unknown job backend: #{HTM.configuration.job_backend}"
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Configuration:**
|
|
147
|
-
```ruby
|
|
148
|
-
HTM.configure do |c|
|
|
149
|
-
c.job_backend = :active_job # or :sidekiq, :inline, :thread
|
|
150
|
-
end
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
**Auto-detection:**
|
|
154
|
-
- Detect ActiveJob if defined
|
|
155
|
-
- Detect Sidekiq if defined
|
|
156
|
-
- Use :inline for test environments
|
|
157
|
-
- Default to :thread for standalone apps
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
### 2. Environment Auto-Detection
|
|
162
|
-
|
|
163
|
-
```ruby
|
|
164
|
-
# lib/htm/configuration.rb
|
|
165
|
-
def initialize
|
|
166
|
-
@job_backend = detect_job_backend
|
|
167
|
-
@logger = detect_logger
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
private
|
|
171
|
-
|
|
172
|
-
def detect_job_backend
|
|
173
|
-
if defined?(ActiveJob)
|
|
174
|
-
:active_job
|
|
175
|
-
elsif defined?(Sidekiq)
|
|
176
|
-
:sidekiq
|
|
177
|
-
elsif ENV['RACK_ENV'] == 'test' || ENV['RAILS_ENV'] == 'test'
|
|
178
|
-
:inline
|
|
179
|
-
else
|
|
180
|
-
:thread
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
def detect_logger
|
|
185
|
-
if defined?(Rails)
|
|
186
|
-
Rails.logger
|
|
187
|
-
elsif defined?(Sinatra::Base)
|
|
188
|
-
Sinatra::Base.logger
|
|
189
|
-
else
|
|
190
|
-
default_logger
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
|
-
### 3. Thread Safety Audit
|
|
198
|
-
|
|
199
|
-
**Verify these components are thread-safe:**
|
|
200
|
-
- `HTM::WorkingMemory` - Per-instance state ✅
|
|
201
|
-
- `HTM::LongTermMemory` - Uses connection pool ✅
|
|
202
|
-
- `HTM::Configuration` - Global singleton ⚠️
|
|
203
|
-
|
|
204
|
-
**Add thread-safety tests:**
|
|
205
|
-
```ruby
|
|
206
|
-
# test/thread_safety_test.rb
|
|
207
|
-
def test_concurrent_remember
|
|
208
|
-
threads = 10.times.map do |i|
|
|
209
|
-
Thread.new { htm.remember("Message #{i}") }
|
|
210
|
-
end
|
|
211
|
-
threads.each(&:join)
|
|
212
|
-
assert_equal 10, HTM::Models::Node.count
|
|
213
|
-
end
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
### 4. Rails-Specific Database Integration
|
|
219
|
-
|
|
220
|
-
**Create abstract base class:**
|
|
221
|
-
```ruby
|
|
222
|
-
# lib/htm/models/base.rb
|
|
223
|
-
module HTM
|
|
224
|
-
module Models
|
|
225
|
-
class Base < ActiveRecord::Base
|
|
226
|
-
self.abstract_class = true
|
|
227
|
-
|
|
228
|
-
def self.establish_connection_if_needed
|
|
229
|
-
unless connected?
|
|
230
|
-
if defined?(Rails)
|
|
231
|
-
establish_connection(Rails.configuration.database_configuration[Rails.env])
|
|
232
|
-
else
|
|
233
|
-
HTM::ActiveRecordConfig.establish_connection!
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
**Update all models:**
|
|
243
|
-
```ruby
|
|
244
|
-
class Robot < HTM::Models::Base
|
|
245
|
-
# ...
|
|
246
|
-
end
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
---
|
|
250
|
-
|
|
251
|
-
### 5. Documentation & Examples
|
|
252
|
-
|
|
253
|
-
**Framework-Specific Documentation:**
|
|
254
|
-
- `docs/cli_usage.md` - CLI application guide
|
|
255
|
-
- `docs/sinatra_integration.md` - Sinatra integration guide
|
|
256
|
-
- `docs/rails_integration.md` - Rails integration guide
|
|
257
|
-
- `docs/job_backends.md` - Job backend configuration
|
|
258
|
-
|
|
259
|
-
**Working Example Apps:**
|
|
260
|
-
- `examples/cli_app/` - CLI tool with synchronous jobs
|
|
261
|
-
- `examples/sinatra_app/` - Sinatra + Sidekiq
|
|
262
|
-
- `examples/rails_app/` - Rails 7 + ActiveJob
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Implementation Roadmap
|
|
267
|
-
|
|
268
|
-
### Phase 1: Job Backend Abstraction (Week 1) ⭐ **CRITICAL**
|
|
269
|
-
|
|
270
|
-
**Tasks:**
|
|
271
|
-
- [ ] Create `HTM::JobAdapter` with pluggable backends
|
|
272
|
-
- [ ] Add `job_backend` configuration option
|
|
273
|
-
- [ ] Update job enqueueing in `lib/htm.rb`
|
|
274
|
-
- [ ] Support: `:active_job`, `:sidekiq`, `:inline`, `:thread`
|
|
275
|
-
- [ ] Add environment auto-detection
|
|
276
|
-
- [ ] Create job adapter tests
|
|
277
|
-
- [ ] Update existing job classes
|
|
278
|
-
|
|
279
|
-
**Files to Create:**
|
|
280
|
-
- `lib/htm/job_adapter.rb`
|
|
281
|
-
- `test/job_adapter_test.rb`
|
|
282
|
-
|
|
283
|
-
**Files to Modify:**
|
|
284
|
-
- `lib/htm/configuration.rb`
|
|
285
|
-
- `lib/htm.rb`
|
|
286
|
-
- `lib/htm/jobs/generate_embedding_job.rb`
|
|
287
|
-
- `lib/htm/jobs/generate_tags_job.rb`
|
|
288
|
-
|
|
289
|
-
**Impact:** Enables proper Sinatra and Rails integration
|
|
290
|
-
|
|
291
|
-
---
|
|
292
|
-
|
|
293
|
-
### Phase 2: Rails Integration (Week 2)
|
|
294
|
-
|
|
295
|
-
**Tasks:**
|
|
296
|
-
- [ ] Create `HTM::Railtie` for auto-configuration
|
|
297
|
-
- [ ] Add Rails connection sharing logic
|
|
298
|
-
- [ ] Convert jobs to ActiveJob::Base (when in Rails)
|
|
299
|
-
- [ ] Create Rails generator (`rails g htm:install`)
|
|
300
|
-
- [ ] Add test environment inline jobs
|
|
301
|
-
- [ ] Create example Rails app
|
|
302
|
-
- [ ] Write Rails integration docs
|
|
303
|
-
|
|
304
|
-
**Files to Create:**
|
|
305
|
-
- `lib/htm/railtie.rb`
|
|
306
|
-
- `lib/htm/models/base.rb`
|
|
307
|
-
- `lib/generators/htm/install_generator.rb`
|
|
308
|
-
- `lib/generators/htm/templates/initializer.rb`
|
|
309
|
-
- `examples/rails_app/` (full Rails app)
|
|
310
|
-
- `docs/rails_integration.md`
|
|
311
|
-
|
|
312
|
-
**Files to Modify:**
|
|
313
|
-
- `lib/htm.rb` (require railtie)
|
|
314
|
-
- `lib/htm/active_record_config.rb`
|
|
315
|
-
- `lib/htm/models/*.rb` (inherit from Base)
|
|
316
|
-
- `README.md` (add Rails section)
|
|
317
|
-
|
|
318
|
-
**Impact:** Production-ready Rails support
|
|
319
|
-
|
|
320
|
-
---
|
|
321
|
-
|
|
322
|
-
### Phase 3: Sinatra Integration (Week 2)
|
|
323
|
-
|
|
324
|
-
**Tasks:**
|
|
325
|
-
- [ ] Create Rack middleware (optional)
|
|
326
|
-
- [ ] Create Sinatra helpers module
|
|
327
|
-
- [ ] Create example Sinatra app with Sidekiq
|
|
328
|
-
- [ ] Write Sinatra integration docs
|
|
329
|
-
- [ ] Add Sinatra-specific tests
|
|
330
|
-
|
|
331
|
-
**Files to Create:**
|
|
332
|
-
- `lib/htm/middleware.rb`
|
|
333
|
-
- `lib/htm/sinatra.rb` (helpers)
|
|
334
|
-
- `examples/sinatra_app/` (full Sinatra app)
|
|
335
|
-
- `docs/sinatra_integration.md`
|
|
336
|
-
- `test/sinatra_integration_test.rb`
|
|
337
|
-
|
|
338
|
-
**Files to Modify:**
|
|
339
|
-
- `README.md` (add Sinatra section)
|
|
340
|
-
|
|
341
|
-
**Impact:** Production-ready Sinatra support
|
|
342
|
-
|
|
343
|
-
---
|
|
344
|
-
|
|
345
|
-
### Phase 4: CLI Enhancements (Week 3)
|
|
346
|
-
|
|
347
|
-
**Tasks:**
|
|
348
|
-
- [ ] Add synchronous mode option
|
|
349
|
-
- [ ] Create CLI executable (`exe/htm`)
|
|
350
|
-
- [ ] Add progress indicators
|
|
351
|
-
- [ ] Create CLI example app
|
|
352
|
-
- [ ] Write CLI usage documentation
|
|
353
|
-
|
|
354
|
-
**Files to Create:**
|
|
355
|
-
- `exe/htm`
|
|
356
|
-
- `examples/cli_app/` (CLI tool)
|
|
357
|
-
- `docs/cli_usage.md`
|
|
358
|
-
- `lib/htm/cli.rb` (command classes)
|
|
359
|
-
|
|
360
|
-
**Files to Modify:**
|
|
361
|
-
- `htm.gemspec` (add executables)
|
|
362
|
-
- `README.md` (add CLI section)
|
|
363
|
-
|
|
364
|
-
**Impact:** Better CLI developer experience
|
|
365
|
-
|
|
366
|
-
---
|
|
367
|
-
|
|
368
|
-
### Phase 5: Thread Safety & Testing (Week 3)
|
|
369
|
-
|
|
370
|
-
**Tasks:**
|
|
371
|
-
- [ ] Thread-safety audit
|
|
372
|
-
- [ ] Concurrent request tests
|
|
373
|
-
- [ ] Load testing
|
|
374
|
-
- [ ] Framework integration tests
|
|
375
|
-
- [ ] Job backend tests for all modes
|
|
376
|
-
|
|
377
|
-
**Files to Create:**
|
|
378
|
-
- `test/thread_safety_test.rb`
|
|
379
|
-
- `test/concurrent_requests_test.rb`
|
|
380
|
-
- `test/job_backends/active_job_test.rb`
|
|
381
|
-
- `test/job_backends/sidekiq_test.rb`
|
|
382
|
-
- `test/job_backends/inline_test.rb`
|
|
383
|
-
- `test/job_backends/thread_test.rb`
|
|
384
|
-
|
|
385
|
-
**Impact:** Confidence in production deployment
|
|
386
|
-
|
|
387
|
-
---
|
|
388
|
-
|
|
389
|
-
## Summary of Required Changes
|
|
390
|
-
|
|
391
|
-
| Component | Change | Priority | Effort |
|
|
392
|
-
|-----------|--------|----------|--------|
|
|
393
|
-
| Job Backend Abstraction | Create `HTM::JobAdapter` | **CRITICAL** | Medium |
|
|
394
|
-
| Rails Railtie | Auto-configuration | High | Medium |
|
|
395
|
-
| Rails Connection Sharing | Detect & use Rails DB | High | Low |
|
|
396
|
-
| ActiveJob Integration | Job classes | High | Low |
|
|
397
|
-
| Sidekiq Support | Job backend option | High | Low |
|
|
398
|
-
| Inline/Sync Mode | For CLI & tests | Medium | Low |
|
|
399
|
-
| Thread Safety Tests | Concurrent tests | Medium | Low |
|
|
400
|
-
| Sinatra Example | Full app | Medium | Medium |
|
|
401
|
-
| Rails Example | Full app | Medium | High |
|
|
402
|
-
| Rails Generator | Install generator | Low | Medium |
|
|
403
|
-
| CLI Executable | Binary wrapper | Low | Low |
|
|
404
|
-
| Rack Middleware | Per-request HTM | Low | Medium |
|
|
405
|
-
|
|
406
|
-
**Total Estimated Effort:** 2-3 weeks for full implementation
|
|
407
|
-
|
|
408
|
-
**Minimum Viable Changes** (1 week):
|
|
409
|
-
1. Job backend abstraction with ActiveJob + Sidekiq + inline support
|
|
410
|
-
2. Rails Railtie for auto-config
|
|
411
|
-
3. Basic thread-safety tests
|
|
412
|
-
4. Updated documentation
|
|
413
|
-
|
|
414
|
-
---
|
|
415
|
-
|
|
416
|
-
## File Structure After Implementation
|
|
417
|
-
|
|
418
|
-
```
|
|
419
|
-
htm/
|
|
420
|
-
├── lib/
|
|
421
|
-
│ ├── htm/
|
|
422
|
-
│ │ ├── job_adapter.rb # NEW: Pluggable job backends
|
|
423
|
-
│ │ ├── railtie.rb # NEW: Rails auto-configuration
|
|
424
|
-
│ │ ├── middleware.rb # NEW: Rack middleware
|
|
425
|
-
│ │ ├── sinatra.rb # NEW: Sinatra helpers
|
|
426
|
-
│ │ ├── cli.rb # NEW: CLI commands
|
|
427
|
-
│ │ ├── models/
|
|
428
|
-
│ │ │ ├── base.rb # NEW: Abstract base class
|
|
429
|
-
│ │ │ ├── robot.rb # MODIFIED: Inherit from Base
|
|
430
|
-
│ │ │ ├── node.rb # MODIFIED: Inherit from Base
|
|
431
|
-
│ │ │ ├── tag.rb # MODIFIED: Inherit from Base
|
|
432
|
-
│ │ │ └── node_tag.rb # MODIFIED: Inherit from Base
|
|
433
|
-
│ │ ├── jobs/
|
|
434
|
-
│ │ │ ├── generate_embedding_job.rb # MODIFIED: Use JobAdapter
|
|
435
|
-
│ │ │ └── generate_tags_job.rb # MODIFIED: Use JobAdapter
|
|
436
|
-
│ │ ├── configuration.rb # MODIFIED: Add job_backend
|
|
437
|
-
│ │ └── active_record_config.rb # MODIFIED: Rails detection
|
|
438
|
-
│ └── generators/
|
|
439
|
-
│ └── htm/
|
|
440
|
-
│ ├── install_generator.rb # NEW: Rails generator
|
|
441
|
-
│ └── templates/
|
|
442
|
-
│ └── initializer.rb # NEW: Initializer template
|
|
443
|
-
├── exe/
|
|
444
|
-
│ └── htm # NEW: CLI executable
|
|
445
|
-
├── examples/
|
|
446
|
-
│ ├── cli_app/ # NEW: CLI example
|
|
447
|
-
│ ├── sinatra_app/ # NEW: Sinatra example
|
|
448
|
-
│ └── rails_app/ # NEW: Rails example
|
|
449
|
-
├── docs/
|
|
450
|
-
│ ├── cli_usage.md # NEW: CLI guide
|
|
451
|
-
│ ├── sinatra_integration.md # NEW: Sinatra guide
|
|
452
|
-
│ ├── rails_integration.md # NEW: Rails guide
|
|
453
|
-
│ └── job_backends.md # NEW: Job backend guide
|
|
454
|
-
├── test/
|
|
455
|
-
│ ├── job_adapter_test.rb # NEW: Job adapter tests
|
|
456
|
-
│ ├── thread_safety_test.rb # NEW: Thread safety tests
|
|
457
|
-
│ ├── concurrent_requests_test.rb # NEW: Concurrency tests
|
|
458
|
-
│ ├── sinatra_integration_test.rb # NEW: Sinatra tests
|
|
459
|
-
│ └── job_backends/ # NEW: Backend-specific tests
|
|
460
|
-
│ ├── active_job_test.rb
|
|
461
|
-
│ ├── sidekiq_test.rb
|
|
462
|
-
│ ├── inline_test.rb
|
|
463
|
-
│ └── thread_test.rb
|
|
464
|
-
└── README.md # MODIFIED: Add framework sections
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
---
|
|
468
|
-
|
|
469
|
-
## Testing Strategy
|
|
470
|
-
|
|
471
|
-
### Unit Tests
|
|
472
|
-
- Job adapter with all backends
|
|
473
|
-
- Configuration auto-detection
|
|
474
|
-
- Model base class connection logic
|
|
475
|
-
|
|
476
|
-
### Integration Tests
|
|
477
|
-
- Rails app integration
|
|
478
|
-
- Sinatra app integration
|
|
479
|
-
- CLI app integration
|
|
480
|
-
|
|
481
|
-
### Thread Safety Tests
|
|
482
|
-
- Concurrent remember() calls
|
|
483
|
-
- Concurrent recall() calls
|
|
484
|
-
- Connection pool stress test
|
|
485
|
-
|
|
486
|
-
### Performance Tests
|
|
487
|
-
- Job enqueueing overhead
|
|
488
|
-
- Connection pool efficiency
|
|
489
|
-
- Memory usage under load
|
|
490
|
-
|
|
491
|
-
---
|
|
492
|
-
|
|
493
|
-
## Documentation Deliverables
|
|
494
|
-
|
|
495
|
-
### User Documentation
|
|
496
|
-
1. **README.md** - Updated with framework sections
|
|
497
|
-
2. **docs/cli_usage.md** - Standalone CLI applications
|
|
498
|
-
3. **docs/sinatra_integration.md** - Sinatra web applications
|
|
499
|
-
4. **docs/rails_integration.md** - Rails web applications
|
|
500
|
-
5. **docs/job_backends.md** - Job backend configuration
|
|
501
|
-
|
|
502
|
-
### Developer Documentation
|
|
503
|
-
1. **CONTRIBUTING.md** - Updated with testing guidelines
|
|
504
|
-
2. **docs/architecture.md** - Job adapter architecture
|
|
505
|
-
3. **docs/thread_safety.md** - Thread safety guarantees
|
|
506
|
-
|
|
507
|
-
### Examples
|
|
508
|
-
1. **examples/cli_app/** - Working CLI application
|
|
509
|
-
2. **examples/sinatra_app/** - Working Sinatra app
|
|
510
|
-
3. **examples/rails_app/** - Working Rails app
|
|
511
|
-
|
|
512
|
-
---
|
|
513
|
-
|
|
514
|
-
## Success Criteria
|
|
515
|
-
|
|
516
|
-
### CLI Applications
|
|
517
|
-
- [ ] Can run synchronously without background threads
|
|
518
|
-
- [ ] Clear progress indicators
|
|
519
|
-
- [ ] Works without Rails/Sinatra dependencies
|
|
520
|
-
- [ ] Example app runs successfully
|
|
521
|
-
|
|
522
|
-
### Sinatra Applications
|
|
523
|
-
- [ ] Works with Sidekiq in production
|
|
524
|
-
- [ ] Thread-safe for concurrent requests
|
|
525
|
-
- [ ] Example app with realistic usage
|
|
526
|
-
- [ ] Documentation covers deployment
|
|
527
|
-
|
|
528
|
-
### Rails Applications
|
|
529
|
-
- [ ] Auto-configures on Rails boot
|
|
530
|
-
- [ ] Uses ActiveJob seamlessly
|
|
531
|
-
- [ ] Shares Rails database connection
|
|
532
|
-
- [ ] Generator creates working setup
|
|
533
|
-
- [ ] Example app demonstrates best practices
|
|
534
|
-
- [ ] Test environment runs synchronously
|
|
535
|
-
|
|
536
|
-
### All Frameworks
|
|
537
|
-
- [ ] Zero breaking changes to existing API
|
|
538
|
-
- [ ] Comprehensive test coverage (>90%)
|
|
539
|
-
- [ ] Complete documentation
|
|
540
|
-
- [ ] Performance regression tests pass
|
|
541
|
-
|
|
542
|
-
---
|
|
543
|
-
|
|
544
|
-
## Migration Path for Existing Users
|
|
545
|
-
|
|
546
|
-
### No Breaking Changes
|
|
547
|
-
All changes are backwards-compatible:
|
|
548
|
-
- Current `Thread.new` behavior remains default for standalone apps
|
|
549
|
-
- Existing configurations continue to work
|
|
550
|
-
- Auto-detection happens transparently
|
|
551
|
-
|
|
552
|
-
### Optional Migration
|
|
553
|
-
Users can opt into new features:
|
|
554
|
-
```ruby
|
|
555
|
-
# Sinatra app
|
|
556
|
-
HTM.configure do |c|
|
|
557
|
-
c.job_backend = :sidekiq
|
|
558
|
-
end
|
|
559
|
-
|
|
560
|
-
# Rails app (auto-detected, but can override)
|
|
561
|
-
HTM.configure do |c|
|
|
562
|
-
c.job_backend = :active_job # Already the default in Rails
|
|
563
|
-
end
|
|
564
|
-
|
|
565
|
-
# CLI app (run synchronously)
|
|
566
|
-
HTM.configure do |c|
|
|
567
|
-
c.job_backend = :inline
|
|
568
|
-
end
|
|
569
|
-
```
|
|
570
|
-
|
|
571
|
-
---
|
|
572
|
-
|
|
573
|
-
## Risk Assessment
|
|
574
|
-
|
|
575
|
-
### Low Risk
|
|
576
|
-
- Job adapter abstraction (well-defined interface)
|
|
577
|
-
- Rails Railtie (optional, doesn't affect existing users)
|
|
578
|
-
- Documentation and examples
|
|
579
|
-
|
|
580
|
-
### Medium Risk
|
|
581
|
-
- Thread safety verification (requires thorough testing)
|
|
582
|
-
- Connection sharing with Rails (needs careful implementation)
|
|
583
|
-
|
|
584
|
-
### Mitigation Strategies
|
|
585
|
-
- Comprehensive test suite before release
|
|
586
|
-
- Beta release for early adopters
|
|
587
|
-
- Gradual rollout (job adapter first, then framework integrations)
|
|
588
|
-
- Maintain backwards compatibility at all costs
|
|
589
|
-
|
|
590
|
-
---
|
|
591
|
-
|
|
592
|
-
## Timeline
|
|
593
|
-
|
|
594
|
-
**Week 1:** Job Backend Abstraction
|
|
595
|
-
- Days 1-2: Create JobAdapter, update configuration
|
|
596
|
-
- Days 3-4: Convert jobs to use adapter
|
|
597
|
-
- Day 5: Tests and documentation
|
|
598
|
-
|
|
599
|
-
**Week 2:** Rails & Sinatra Integration
|
|
600
|
-
- Days 1-3: Rails Railtie, connection sharing, generator
|
|
601
|
-
- Days 4-5: Sinatra helpers, middleware
|
|
602
|
-
|
|
603
|
-
**Week 3:** Examples, CLI, Testing
|
|
604
|
-
- Days 1-2: Example applications
|
|
605
|
-
- Days 3-4: CLI enhancements
|
|
606
|
-
- Day 5: Thread safety and performance tests
|
|
607
|
-
|
|
608
|
-
---
|
|
609
|
-
|
|
610
|
-
## Next Steps
|
|
611
|
-
|
|
612
|
-
1. **Review and Approve** this plan
|
|
613
|
-
2. **Create Feature Branch** (`git checkout -b feature/multi-framework-support`)
|
|
614
|
-
3. **Phase 1 Implementation** - Job Backend Abstraction
|
|
615
|
-
4. **Iterative Development** - Implement, test, document each phase
|
|
616
|
-
5. **Beta Release** - Get feedback from early adopters
|
|
617
|
-
6. **Production Release** - After thorough testing
|
|
618
|
-
|
|
619
|
-
---
|
|
620
|
-
|
|
621
|
-
## Conclusion
|
|
622
|
-
|
|
623
|
-
This implementation will transform HTM from a library that *works* in multiple frameworks to one that *excels* in each framework's ecosystem. The pluggable job backend is the critical enabler, with framework-specific integrations providing the polish that makes HTM feel native to each environment.
|
|
624
|
-
|
|
625
|
-
**Total effort: 2-3 weeks**
|
|
626
|
-
**Risk level: Low-Medium**
|
|
627
|
-
**Value: High - enables production use in web applications**
|