htm 0.0.32 → 0.1.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/.architecture/decisions/adrs/005-rag-based-retrieval-with-hybrid-search.md +4 -0
- data/.architecture/decisions/adrs/017-bitemporal-event-time.md +78 -0
- data/.architecture/decisions/adrs/018-memory-timelines-and-node-links.md +64 -0
- data/.architecture/decisions/adrs/019-epistemic-status.md +66 -0
- data/.claude.json +11 -0
- data/.envrc +9 -7
- data/.irbrc +14 -14
- data/.reek.yml +104 -0
- data/.rubocop.yml +0 -11
- data/.ruby-version +1 -0
- data/CHANGELOG.md +160 -98
- data/README.md +22 -17
- data/SETUP.md +49 -46
- data/_typos.toml +17 -0
- data/bin/htm +18 -0
- data/db/migrate/00010_convert_embedding_to_sparsevec.rb +47 -0
- data/db/migrate/00011_strip_frontmatter_from_chunks.rb +66 -0
- data/db/migrate/00012_add_event_time_to_nodes.rb +110 -0
- data/db/migrate/00013_create_node_links.rb +158 -0
- data/db/migrate/00014_add_epistemic_status.rb +110 -0
- data/db/schema.sql +238 -7
- data/db/seed_data/README.md +11 -11
- data/db/seeds.rb +11 -11
- data/docs/api/database.md +8 -8
- data/docs/api/embedding-service.md +138 -262
- data/docs/api/htm.md +128 -12
- data/docs/api/index.md +8 -8
- data/docs/api/long-term-memory.md +8 -19
- data/docs/api/working-memory.md +34 -46
- data/docs/api/yard/HTM/Admin/Console.md +53 -0
- data/docs/api/yard/HTM/Admin/DatabaseCommands/Console.md +38 -0
- data/docs/api/yard/HTM/Admin/DatabaseCommands.md +127 -0
- data/docs/api/yard/HTM/Admin/EnrichCommands.md +85 -0
- data/docs/api/yard/HTM/Admin/Error.md +9 -0
- data/docs/api/yard/HTM/Admin/FileCommands/Console.md +50 -0
- data/docs/api/yard/HTM/Admin/FileCommands.md +83 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/Base.md +17 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/Edit.md +74 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/Search.md +77 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/TagSearch.md +46 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/WorkingMemory.md +36 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands.md +67 -0
- data/docs/api/yard/HTM/Admin/TagCommands/Console.md +48 -0
- data/docs/api/yard/HTM/Admin/TagCommands.md +105 -0
- data/docs/api/yard/HTM/Admin/TagGraph.md +149 -0
- data/docs/api/yard/HTM/Admin/YardDocs.md +60 -0
- data/docs/api/yard/HTM/Admin.md +102 -0
- data/docs/api/yard/HTM/AuthorizationError.md +6 -6
- data/docs/api/yard/HTM/CLI/ConfigFile.md +40 -0
- data/docs/api/yard/HTM/CLI/Db.md +63 -0
- data/docs/api/yard/HTM/CLI/Enrich.md +39 -0
- data/docs/api/yard/HTM/CLI/ErrorSuggestion.md +56 -0
- data/docs/api/yard/HTM/CLI/Files.md +36 -0
- data/docs/api/yard/HTM/CLI/Group/ClassMethods.md +11 -0
- data/docs/api/yard/HTM/CLI/Group.md +13 -0
- data/docs/api/yard/HTM/CLI/MemoryCommand/ClassMethods.md +20 -0
- data/docs/api/yard/HTM/CLI/MemoryCommand.md +9 -0
- data/docs/api/yard/HTM/CLI/Robots.md +31 -0
- data/docs/api/yard/HTM/CLI/Support.md +9 -0
- data/docs/api/yard/HTM/CLI/Tags.md +57 -0
- data/docs/api/yard/HTM/CLI/WorkingMemory.md +24 -0
- data/docs/api/yard/HTM/CLI.md +84 -0
- data/docs/api/yard/HTM/CircuitBreaker/Guarded.md +29 -0
- data/docs/api/yard/HTM/CircuitBreaker/Settings.md +21 -0
- data/docs/api/yard/HTM/CircuitBreaker/Status.md +42 -0
- data/docs/api/yard/HTM/CircuitBreaker.md +54 -49
- data/docs/api/yard/HTM/CircuitBreakerOpenError.md +9 -9
- data/docs/api/yard/HTM/Config/Builder.md +87 -0
- data/docs/api/yard/HTM/Config/Coercion.md +59 -0
- data/docs/api/yard/HTM/Config/Database.md +102 -0
- data/docs/api/yard/HTM/Config/Readers.md +30 -0
- data/docs/api/yard/HTM/Config/RubyLlmSettings.md +32 -0
- data/docs/api/yard/HTM/Config/Validator.md +59 -0
- data/docs/api/yard/HTM/Config.md +224 -105
- data/docs/api/yard/HTM/ConfigurationError.md +20 -0
- data/docs/api/yard/HTM/Confirmation.md +22 -0
- data/docs/api/yard/HTM/Database/Connection.md +26 -0
- data/docs/api/yard/HTM/Database/Migrations.md +32 -0
- data/docs/api/yard/HTM/Database/Report.md +26 -0
- data/docs/api/yard/HTM/Database/SchemaFile.md +52 -0
- data/docs/api/yard/HTM/Database/Teardown.md +15 -0
- data/docs/api/yard/HTM/Database.md +58 -70
- data/docs/api/yard/HTM/DatabaseDocs.md +67 -0
- data/docs/api/yard/HTM/DatabaseError.md +6 -6
- data/docs/api/yard/HTM/Deletion.md +32 -0
- data/docs/api/yard/HTM/EmbeddingError.md +6 -6
- data/docs/api/yard/HTM/EmbeddingService.md +37 -38
- data/docs/api/yard/HTM/Epistemics.md +135 -0
- data/docs/api/yard/HTM/Error.md +6 -6
- data/docs/api/yard/HTM/EventTime.md +110 -0
- data/docs/api/yard/HTM/FileMemory.md +76 -0
- data/docs/api/yard/HTM/InputValidator.md +82 -0
- data/docs/api/yard/HTM/JobAdapter/Job.md +26 -0
- data/docs/api/yard/HTM/JobAdapter.md +35 -16
- data/docs/api/yard/HTM/Jobs/FailureLogging.md +14 -0
- data/docs/api/yard/HTM/Jobs/GenerateEmbeddingJob.md +16 -0
- data/docs/api/yard/HTM/Jobs/GeneratePropositionsJob.md +17 -0
- data/docs/api/yard/HTM/Jobs/GenerateRelationshipsJob.md +26 -0
- data/docs/api/yard/HTM/Jobs/GenerateTagsJob.md +17 -0
- data/docs/api/yard/HTM/Jobs/LlmCallTimer.md +58 -0
- data/docs/api/yard/HTM/Jobs/NodeLookup.md +14 -0
- data/docs/api/yard/HTM/Jobs.md +13 -0
- data/docs/api/yard/HTM/Loaders/ChunkSync/Chunk.md +22 -0
- data/docs/api/yard/HTM/Loaders/ChunkSync.md +50 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker/Coalescer.md +24 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker/Packer.md +20 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker/Splitter.md +18 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker.md +83 -0
- data/docs/api/yard/HTM/Loaders/MarkdownLoader/Document.md +43 -0
- data/docs/api/yard/HTM/Loaders/MarkdownLoader.md +62 -0
- data/docs/api/yard/HTM/Loaders.md +5 -0
- data/docs/api/yard/HTM/LongTermMemory/FulltextSearch.md +36 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfMerger.md +25 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfRows.md +30 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfSql/Query.md +79 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfSql/Source.md +45 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfSql.md +11 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/TagDepth.md +52 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch.md +52 -0
- data/docs/api/yard/HTM/LongTermMemory/NodeOperations.md +95 -0
- data/docs/api/yard/HTM/LongTermMemory/RelevanceScorer/HierarchicalJaccard.md +58 -0
- data/docs/api/yard/HTM/LongTermMemory/RelevanceScorer/TagSearch.md +27 -0
- data/docs/api/yard/HTM/LongTermMemory/RelevanceScorer.md +81 -0
- data/docs/api/yard/HTM/LongTermMemory/RobotOperations.md +22 -0
- data/docs/api/yard/HTM/LongTermMemory/TagOperations/ExpiringValue.md +24 -0
- data/docs/api/yard/HTM/LongTermMemory/TagOperations/TagMatchSql.md +40 -0
- data/docs/api/yard/HTM/LongTermMemory/TagOperations.md +129 -0
- data/docs/api/yard/HTM/LongTermMemory/VectorSearch.md +30 -0
- data/docs/api/yard/HTM/LongTermMemory.md +279 -31
- data/docs/api/yard/HTM/MCP/AssembleContextTool.md +16 -0
- data/docs/api/yard/HTM/MCP/ClearGroupWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ClearWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ConfigResource.md +12 -0
- data/docs/api/yard/HTM/MCP/ConfirmTool.md +12 -0
- data/docs/api/yard/HTM/MCP/CreateGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/EnrichPendingTool.md +16 -0
- data/docs/api/yard/HTM/MCP/ExtractPropositionsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/FailoverTool.md +12 -0
- data/docs/api/yard/HTM/MCP/FileInfoTool.md +13 -0
- data/docs/api/yard/HTM/MCP/FileSourcesResource.md +12 -0
- data/docs/api/yard/HTM/MCP/FileSupport.md +7 -0
- data/docs/api/yard/HTM/MCP/FindByTopicTool.md +12 -0
- data/docs/api/yard/HTM/MCP/FirstMentionTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ForgetContentTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ForgetTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetGroupStatusTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetGroupWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetNodeTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetRobotTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GroupRecallTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GroupRememberTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GroupSession.md +23 -0
- data/docs/api/yard/HTM/MCP/JoinGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/LeaveGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListDeletedTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListFilesTool.md +13 -0
- data/docs/api/yard/HTM/MCP/ListGroupsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListRobotsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListTagsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/LoadDirectoryTool.md +13 -0
- data/docs/api/yard/HTM/MCP/LoadFileTool.md +13 -0
- data/docs/api/yard/HTM/MCP/MemoryStatsResource.md +13 -0
- data/docs/api/yard/HTM/MCP/PopularTagsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/PromoteRobotTool.md +12 -0
- data/docs/api/yard/HTM/MCP/PurgeDeletedTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RecallTool.md +16 -0
- data/docs/api/yard/HTM/MCP/RecentMemoriesResource.md +13 -0
- data/docs/api/yard/HTM/MCP/RelatedNodesTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RememberTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RestoreTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RobotGroupsResource.md +13 -0
- data/docs/api/yard/HTM/MCP/RobotTeamsStatusTool.md +13 -0
- data/docs/api/yard/HTM/MCP/RunRobotTeamsTool.md +13 -0
- data/docs/api/yard/HTM/MCP/SearchByTagsTool.md +16 -0
- data/docs/api/yard/HTM/MCP/SearchTagsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/Server.md +37 -0
- data/docs/api/yard/HTM/MCP/Session.md +32 -0
- data/docs/api/yard/HTM/MCP/SetRobotTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ShutdownGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/StartupPromptResource.md +16 -0
- data/docs/api/yard/HTM/MCP/StatsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/SyncFilesTool.md +13 -0
- data/docs/api/yard/HTM/MCP/SyncGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/TagHierarchyResource.md +16 -0
- data/docs/api/yard/HTM/MCP/TagNodeTool.md +12 -0
- data/docs/api/yard/HTM/MCP/TagTreeTool.md +22 -0
- data/docs/api/yard/HTM/MCP/TeamNames.md +7 -0
- data/docs/api/yard/HTM/MCP/TimelineTool.md +12 -0
- data/docs/api/yard/HTM/MCP/Tool.md +24 -0
- data/docs/api/yard/HTM/MCP/ToolSupport.md +17 -0
- data/docs/api/yard/HTM/MCP/TopicRelationshipsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/TransferWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/UnloadFileTool.md +13 -0
- data/docs/api/yard/HTM/MCP/UntagNodeTool.md +12 -0
- data/docs/api/yard/HTM/MCP.md +30 -0
- data/docs/api/yard/HTM/Migration.md +44 -0
- data/docs/api/yard/HTM/Models/FileSource.md +66 -0
- data/docs/api/yard/HTM/Models/Node/Scopes.md +74 -0
- data/docs/api/yard/HTM/Models/Node/SoftDeletion.md +22 -0
- data/docs/api/yard/HTM/Models/Node/VectorSimilarity.md +28 -0
- data/docs/api/yard/HTM/Models/Node.md +113 -0
- data/docs/api/yard/HTM/Models/NodeLink.md +65 -0
- data/docs/api/yard/HTM/Models/NodeRelationship.md +31 -0
- data/docs/api/yard/HTM/Models/NodeTag.md +38 -0
- data/docs/api/yard/HTM/Models/Robot.md +50 -0
- data/docs/api/yard/HTM/Models/RobotNode.md +35 -0
- data/docs/api/yard/HTM/Models/Tag/Scopes.md +32 -0
- data/docs/api/yard/HTM/Models/Tag.md +112 -0
- data/docs/api/yard/HTM/Models.md +5 -0
- data/docs/api/yard/HTM/NodeEnrichment.md +36 -0
- data/docs/api/yard/HTM/NodeView.md +113 -0
- data/docs/api/yard/HTM/NotFoundError.md +6 -5
- data/docs/api/yard/HTM/Observability.md +58 -40
- data/docs/api/yard/HTM/PropositionError.md +6 -6
- data/docs/api/yard/HTM/PropositionService.md +63 -29
- data/docs/api/yard/HTM/QueryCache/KeyNormalizer.md +25 -0
- data/docs/api/yard/HTM/QueryCache/NullStore.md +19 -0
- data/docs/api/yard/HTM/QueryCache/Store.md +43 -0
- data/docs/api/yard/HTM/QueryCache.md +41 -46
- data/docs/api/yard/HTM/QueryTimeoutError.md +9 -8
- data/docs/api/yard/HTM/Railtie.md +11 -7
- data/docs/api/yard/HTM/RecallQuery.md +111 -0
- data/docs/api/yard/HTM/ResourceExhaustedError.md +6 -6
- data/docs/api/yard/HTM/RobotGroup/CacheSync.md +35 -0
- data/docs/api/yard/HTM/RobotGroup/Membership.md +96 -0
- data/docs/api/yard/HTM/RobotGroup/TransferOptions.md +14 -0
- data/docs/api/yard/HTM/RobotGroup/WorkingMemoryLedger.md +65 -0
- data/docs/api/yard/HTM/RobotGroup.md +116 -360
- data/docs/api/yard/HTM/Robots/Actions/TagMove.md +31 -0
- data/docs/api/yard/HTM/Robots/Actions.md +153 -0
- data/docs/api/yard/HTM/Robots/Neighbors.md +20 -0
- data/docs/api/yard/HTM/Robots/Supervisor/Idler.md +26 -0
- data/docs/api/yard/HTM/Robots/Supervisor/Roster.md +26 -0
- data/docs/api/yard/HTM/Robots/Supervisor.md +42 -0
- data/docs/api/yard/HTM/Robots/Team.md +60 -0
- data/docs/api/yard/HTM/Robots/Teams/Archivist.md +43 -0
- data/docs/api/yard/HTM/Robots/Teams/Consolidator.md +29 -0
- data/docs/api/yard/HTM/Robots/Teams/ContradictionDetector.md +33 -0
- data/docs/api/yard/HTM/Robots/Teams/TagCurator.md +37 -0
- data/docs/api/yard/HTM/Robots/Teams.md +5 -0
- data/docs/api/yard/HTM/Robots/Tools/ArchiveNodes.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/Base.md +16 -0
- data/docs/api/yard/HTM/Robots/Tools/MergeNodes.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/MergeTags.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/Pass.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/RecordConflict.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/SupersedeNode.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools.md +14 -0
- data/docs/api/yard/HTM/Robots.md +72 -0
- data/docs/api/yard/HTM/SearchFilters.md +82 -0
- data/docs/api/yard/HTM/SequelConfig.md +97 -0
- data/docs/api/yard/HTM/Settings.md +39 -0
- data/docs/api/yard/HTM/Sinatra/Helpers.md +37 -0
- data/docs/api/yard/HTM/Sinatra/Middleware.md +29 -0
- data/docs/api/yard/HTM/Sinatra.md +44 -0
- data/docs/api/yard/HTM/SqlBuilder/Sparsevec.md +69 -0
- data/docs/api/yard/HTM/SqlBuilder.md +62 -75
- data/docs/api/yard/HTM/StartupPrompt.md +45 -0
- data/docs/api/yard/HTM/TagError.md +6 -6
- data/docs/api/yard/HTM/TagService.md +100 -37
- data/docs/api/yard/HTM/TagTree/Branch.md +43 -0
- data/docs/api/yard/HTM/TagTree/SvgRenderer/Layout.md +51 -0
- data/docs/api/yard/HTM/TagTree/SvgRenderer.md +25 -0
- data/docs/api/yard/HTM/TagTree.md +65 -0
- data/docs/api/yard/HTM/Telemetry/NullInstrument.md +12 -9
- data/docs/api/yard/HTM/Telemetry/NullMeter.md +17 -9
- data/docs/api/yard/HTM/Telemetry.md +53 -50
- data/docs/api/yard/HTM/Timeframe/Result.md +13 -16
- data/docs/api/yard/HTM/Timeframe.md +17 -20
- data/docs/api/yard/HTM/TimeframeExtractor/Patterns.md +18 -0
- data/docs/api/yard/HTM/TimeframeExtractor/Result.md +13 -16
- data/docs/api/yard/HTM/TimeframeExtractor.md +27 -16
- data/docs/api/yard/HTM/Timeline.md +113 -0
- data/docs/api/yard/HTM/ValidationError.md +6 -5
- data/docs/api/yard/HTM/Workflows/RememberWorkflow/NodeState.md +73 -0
- data/docs/api/yard/HTM/Workflows/RememberWorkflow.md +80 -0
- data/docs/api/yard/HTM/Workflows.md +5 -0
- data/docs/api/yard/HTM/WorkingMemory/Entry.md +67 -0
- data/docs/api/yard/HTM/WorkingMemory/Store.md +54 -0
- data/docs/api/yard/HTM/WorkingMemory.md +113 -87
- data/docs/api/yard/HTM/WorkingMemoryChannel/Subscribers.md +28 -0
- data/docs/api/yard/HTM/WorkingMemoryChannel.md +108 -102
- data/docs/api/yard/HTM.md +483 -5
- data/docs/api/yard/README.md +211 -0
- data/docs/api/yard/Sinatra/Base.md +30 -0
- data/docs/api/yard/Sinatra.md +7 -0
- data/docs/api/yard/index.csv +1834 -181
- data/docs/api/yard-reference.md +228 -9
- data/docs/architecture/adrs/005-rag-retrieval.md +3 -0
- data/docs/architecture/adrs/index.md +1 -1
- data/docs/architecture/index.md +2 -2
- data/docs/architecture/overview.md +3 -3
- data/docs/assets/images/project-structure.svg +2 -2
- data/docs/database/INDEX.md +113 -0
- data/docs/database/README.md +60 -176
- data/docs/database/file_sources.md +51 -0
- data/docs/database/file_sources.svg +120 -0
- data/docs/database/naming-convention.md +12 -12
- data/docs/database/node_links.md +65 -0
- data/docs/database/node_links.svg +171 -0
- data/docs/database/node_relationships.md +62 -0
- data/docs/database/node_relationships.svg +124 -0
- data/docs/database/node_tags.md +50 -0
- data/docs/database/node_tags.svg +125 -0
- data/docs/database/nodes.md +120 -0
- data/docs/database/nodes.svg +394 -0
- data/docs/database/robot_nodes.md +57 -0
- data/docs/database/robot_nodes.svg +155 -0
- data/docs/database/robots.md +40 -0
- data/docs/database/robots.svg +131 -0
- data/docs/database/schema.svg +384 -275
- data/docs/database/schema_migrations.md +19 -0
- data/docs/database/schema_migrations.svg +31 -0
- data/docs/database/tags.md +47 -0
- data/docs/database/tags.svg +90 -0
- data/docs/development/asgard-tasks.md +114 -0
- data/docs/development/contributing.md +6 -6
- data/docs/development/index.md +15 -17
- data/docs/development/schema.md +43 -14
- data/docs/development/setup.md +60 -70
- data/docs/development/testing.md +57 -65
- data/docs/examples/basic-usage.md +9 -9
- data/docs/examples/config-files.md +8 -8
- data/docs/examples/file-loading.md +12 -12
- data/docs/examples/index.md +15 -8
- data/docs/examples/llm-configuration.md +13 -9
- data/docs/examples/mcp-client.md +61 -59
- data/docs/examples/rails-integration.md +5 -4
- data/docs/examples/sinatra-integration.md +5 -4
- data/docs/examples/standalone-app.md +17 -16
- data/docs/getting-started/index.md +3 -3
- data/docs/getting-started/installation.md +76 -83
- data/docs/getting-started/quick-start.md +24 -22
- data/docs/guides/adding-memories.md +14 -3
- data/docs/guides/cli.md +458 -0
- data/docs/guides/configuration.md +72 -37
- data/docs/guides/epistemic-status.md +138 -0
- data/docs/guides/event-time.md +106 -0
- data/docs/guides/file-loading.md +26 -22
- data/docs/guides/getting-started.md +21 -17
- data/docs/guides/long-term-memory.md +1 -1
- data/docs/guides/mcp-server.md +416 -173
- data/docs/guides/propositions.md +18 -29
- data/docs/guides/recalling-memories.md +22 -7
- data/docs/guides/robot-teams.md +96 -0
- data/docs/guides/search-strategies.md +10 -7
- data/docs/guides/tags.md +19 -19
- data/docs/guides/timeline.md +106 -0
- data/docs/index.md +7 -7
- data/docs/llms.txt +35 -0
- data/docs/multi_framework_support.md +13 -13
- data/docs/robots/robot-groups.md +9 -9
- data/docs/robots/two-tier-memory.md +13 -26
- data/docs/setup_local_database.md +33 -31
- data/examples/00_create_examples_db.rb +20 -7
- data/examples/01_basic_usage.rb +20 -18
- data/examples/02_config_file_example/README.md +13 -12
- data/examples/02_config_file_example/config/htm.local.yml +8 -8
- data/examples/02_config_file_example/show_config.rb +3 -4
- data/examples/03_custom_llm_configuration.rb +12 -12
- data/examples/04_file_loader_usage.rb +15 -21
- data/examples/05_timeframe_demo.rb +282 -234
- data/examples/06_example_app/.loki +36 -0
- data/examples/06_example_app/app.rb +21 -33
- data/examples/07_cli_app/README.md +18 -18
- data/examples/07_cli_app/htm_cli.rb +25 -19
- data/examples/08_sinatra_app/Gemfile +1 -0
- data/examples/08_sinatra_app/Gemfile.lock +101 -67
- data/examples/08_sinatra_app/app.rb +64 -62
- data/examples/09_mcp_client.rb +92 -119
- data/examples/10_telemetry/README.md +3 -3
- data/examples/10_telemetry/SETUP_README.md +2 -2
- data/examples/10_telemetry/demo.rb +5 -5
- data/examples/11_robot_groups/README.md +5 -4
- data/examples/11_robot_groups/lib/robot_worker.rb +0 -5
- data/examples/11_robot_groups/multi_process.rb +5 -4
- data/examples/11_robot_groups/same_process.rb +18 -17
- data/examples/12_rails_app/Gemfile +1 -1
- data/examples/12_rails_app/Gemfile.lock +146 -97
- data/examples/12_rails_app/README.md +21 -17
- data/examples/12_rails_app/app/controllers/chats_controller.rb +33 -63
- data/examples/12_rails_app/app/controllers/memories_controller.rb +7 -1
- data/examples/12_rails_app/app/controllers/messages_controller.rb +21 -58
- data/examples/12_rails_app/app/controllers/search_controller.rb +7 -2
- data/examples/12_rails_app/app/models/chat.rb +0 -33
- data/examples/12_rails_app/app/models/message.rb +0 -2
- data/examples/12_rails_app/app/views/chats/show.html.erb +2 -2
- data/examples/12_rails_app/app/views/files/new.html.erb +1 -1
- data/examples/12_rails_app/app/views/memories/_memory_card.html.erb +1 -1
- data/examples/12_rails_app/app/views/memories/new.html.erb +12 -0
- data/examples/12_rails_app/app/views/memories/show.html.erb +13 -0
- data/examples/12_rails_app/app/views/search/index.html.erb +18 -2
- data/examples/12_rails_app/config/initializers/ruby_llm.rb +11 -15
- data/examples/12_rails_app/db/migrate/20261205061932_create_ruby_llm_records.rb +160 -0
- data/examples/12_rails_app/db/migrate/20261205061933_create_chats.rb +13 -0
- data/examples/12_rails_app/db/migrate/20261205061934_create_messages.rb +23 -0
- data/examples/12_rails_app/db/schema.rb +163 -20
- data/examples/README.md +53 -44
- data/examples/examples_helper.rb +29 -5
- data/htm.gemspec +68 -0
- data/lib/htm/admin/database_commands.rb +454 -0
- data/lib/htm/admin/enrich_commands.rb +209 -0
- data/lib/htm/admin/file_commands.rb +323 -0
- data/lib/htm/admin/memory_commands/edit.rb +157 -0
- data/lib/htm/admin/memory_commands/search.rb +178 -0
- data/lib/htm/admin/memory_commands/tag_search.rb +98 -0
- data/lib/htm/admin/memory_commands/text.rb +164 -0
- data/lib/htm/admin/memory_commands/working_memory.rb +71 -0
- data/lib/htm/admin/memory_commands.rb +179 -0
- data/lib/htm/admin/tag_commands.rb +352 -0
- data/lib/htm/admin/tag_graph.rb +290 -0
- data/lib/htm/admin/templates/tag_graph.html +295 -0
- data/lib/htm/admin/yard_docs.rb +206 -0
- data/lib/htm/admin.rb +253 -0
- data/lib/htm/circuit_breaker.rb +142 -68
- data/lib/htm/class_methods.rb +136 -0
- data/lib/htm/cli/config_file.rb +86 -0
- data/lib/htm/cli/db.rb +77 -0
- data/lib/htm/cli/enrich.rb +44 -0
- data/lib/htm/cli/environment.rb +74 -0
- data/lib/htm/cli/error_suggestion.rb +97 -0
- data/lib/htm/cli/files.rb +41 -0
- data/lib/htm/cli/group.rb +32 -0
- data/lib/htm/cli/memory.rb +320 -0
- data/lib/htm/cli/memory_command.rb +71 -0
- data/lib/htm/cli/robots.rb +71 -0
- data/lib/htm/cli/support.rb +46 -0
- data/lib/htm/cli/tags.rb +103 -0
- data/lib/htm/cli/working_memory.rb +41 -0
- data/lib/htm/cli.rb +75 -0
- data/lib/htm/config/builder.rb +99 -68
- data/lib/htm/config/coercion.rb +91 -0
- data/lib/htm/config/database.rb +81 -52
- data/lib/htm/config/defaults.yml +52 -16
- data/lib/htm/config/readers.rb +85 -0
- data/lib/htm/config/ruby_llm_settings.rb +58 -0
- data/lib/htm/config/validator.rb +45 -26
- data/lib/htm/config.rb +112 -297
- data/lib/htm/database.rb +305 -396
- data/lib/htm/database_docs.rb +149 -0
- data/lib/htm/embedding_service.rb +26 -66
- data/lib/htm/epistemics.rb +254 -0
- data/lib/htm/errors.rb +4 -4
- data/lib/htm/event_time.rb +201 -0
- data/lib/htm/file_memory.rb +106 -0
- data/lib/htm/input_validator.rb +158 -0
- data/lib/htm/integrations/sinatra.rb +43 -31
- data/lib/htm/job_adapter.rb +78 -83
- data/lib/htm/jobs/failure_logging.rb +49 -0
- data/lib/htm/jobs/generate_embedding_job.rb +21 -28
- data/lib/htm/jobs/generate_propositions_job.rb +56 -28
- data/lib/htm/jobs/generate_relationships_job.rb +28 -24
- data/lib/htm/jobs/generate_tags_job.rb +32 -37
- data/lib/htm/jobs/llm_call_timer.rb +53 -0
- data/lib/htm/jobs/node_lookup.rb +27 -0
- data/lib/htm/knowledge_memory.rb +153 -0
- data/lib/htm/loaders/chunk_sync.rb +168 -0
- data/lib/htm/loaders/markdown_chunker.rb +207 -36
- data/lib/htm/loaders/markdown_loader.rb +76 -120
- data/lib/htm/long_term_memory/fulltext_search.rb +15 -36
- data/lib/htm/long_term_memory/hybrid_search.rb +471 -544
- data/lib/htm/long_term_memory/node_operations.rb +110 -81
- data/lib/htm/long_term_memory/relevance_scorer.rb +232 -237
- data/lib/htm/long_term_memory/tag_operations.rb +201 -130
- data/lib/htm/long_term_memory/vector_search.rb +33 -61
- data/lib/htm/long_term_memory.rb +5 -17
- data/lib/htm/mcp/file_tools.rb +190 -0
- data/lib/htm/mcp/group_tools.rb +223 -233
- data/lib/htm/mcp/node_tools.rb +350 -0
- data/lib/htm/mcp/resources.rb +102 -28
- data/lib/htm/mcp/robot_team_tools.rb +119 -0
- data/lib/htm/mcp/server.rb +26 -14
- data/lib/htm/mcp/tag_tools.rb +130 -0
- data/lib/htm/mcp/tool.rb +40 -0
- data/lib/htm/mcp/tool_support.rb +88 -0
- data/lib/htm/mcp/tools.rb +232 -283
- data/lib/htm/models/file_source.rb +35 -20
- data/lib/htm/models/node.rb +287 -193
- data/lib/htm/models/node_link.rb +97 -0
- data/lib/htm/models/node_relationship.rb +3 -2
- data/lib/htm/models/node_tag.rb +22 -2
- data/lib/htm/models/robot.rb +4 -8
- data/lib/htm/models/robot_node.rb +5 -2
- data/lib/htm/models/tag.rb +53 -207
- data/lib/htm/node_enrichment.rb +75 -0
- data/lib/htm/node_view.rb +295 -0
- data/lib/htm/observability.rb +114 -98
- data/lib/htm/proposition_service.rb +38 -74
- data/lib/htm/query_cache.rb +145 -91
- data/lib/htm/railtie.rb +3 -7
- data/lib/htm/request_options.rb +149 -0
- data/lib/htm/robot_group/cache_sync.rb +69 -0
- data/lib/htm/robot_group/membership.rb +147 -0
- data/lib/htm/robot_group/working_memory_ledger.rb +111 -0
- data/lib/htm/robot_group.rb +128 -521
- data/lib/htm/robots/actions.rb +371 -0
- data/lib/htm/robots/neighbors.rb +63 -0
- data/lib/htm/robots/node_brief.rb +49 -0
- data/lib/htm/robots/supervisor.rb +140 -0
- data/lib/htm/robots/team.rb +124 -0
- data/lib/htm/robots/teams/archivist.rb +88 -0
- data/lib/htm/robots/teams/consolidator.rb +52 -0
- data/lib/htm/robots/teams/contradiction_detector.rb +67 -0
- data/lib/htm/robots/teams/tag_curator.rb +75 -0
- data/lib/htm/robots/tools.rb +127 -0
- data/lib/htm/robots.rb +125 -0
- data/lib/htm/search_filters.rb +116 -0
- data/lib/htm/sequel_config.rb +95 -59
- data/lib/htm/sql_builder.rb +162 -53
- data/lib/htm/startup_prompt.rb +73 -0
- data/lib/htm/tag_service.rb +104 -109
- data/lib/htm/tag_tree.rb +206 -0
- data/lib/htm/telemetry.rb +15 -16
- data/lib/htm/timeframe.rb +27 -9
- data/lib/htm/timeframe_extractor.rb +77 -55
- data/lib/htm/timeline.rb +230 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm/workflows/remember_workflow.rb +145 -136
- data/lib/htm/working_memory/entry.rb +53 -0
- data/lib/htm/working_memory/store.rb +97 -0
- data/lib/htm/working_memory.rb +137 -139
- data/lib/htm/working_memory_channel.rb +90 -40
- data/lib/htm.rb +177 -501
- data/mkdocs.yml +100 -23
- data/scripts/install_local_database.sh +7 -6
- metadata +1032 -594
- data/.tbls.yml +0 -31
- data/Rakefile +0 -240
- data/bin/htm_mcp +0 -27
- data/docs/api/yard/HTM/ActiveRecordConfig.md +0 -29
- data/docs/api/yard/HTM/ConfigSection.md +0 -28
- data/docs/database/public.file_sources.md +0 -42
- data/docs/database/public.file_sources.svg +0 -219
- data/docs/database/public.node_stats.md +0 -48
- data/docs/database/public.node_stats.svg +0 -41
- data/docs/database/public.node_tags.md +0 -41
- data/docs/database/public.node_tags.svg +0 -251
- data/docs/database/public.nodes.md +0 -61
- data/docs/database/public.nodes.svg +0 -283
- data/docs/database/public.nodes_tags.md +0 -39
- data/docs/database/public.nodes_tags.svg +0 -112
- data/docs/database/public.ontology_structure.md +0 -48
- data/docs/database/public.ontology_structure.svg +0 -38
- data/docs/database/public.operations_log.md +0 -42
- data/docs/database/public.operations_log.svg +0 -130
- data/docs/database/public.relationships.md +0 -39
- data/docs/database/public.relationships.svg +0 -41
- data/docs/database/public.robot_activity.md +0 -46
- data/docs/database/public.robot_activity.svg +0 -35
- data/docs/database/public.robot_nodes.md +0 -48
- data/docs/database/public.robot_nodes.svg +0 -251
- data/docs/database/public.robots.md +0 -34
- data/docs/database/public.robots.svg +0 -165
- data/docs/database/public.schema_migrations.md +0 -29
- data/docs/database/public.schema_migrations.svg +0 -26
- data/docs/database/public.tags.md +0 -38
- data/docs/database/public.tags.svg +0 -147
- data/docs/database/public.topic_relationships.md +0 -45
- data/docs/database/public.topic_relationships.svg +0 -32
- data/docs/database/schema.json +0 -1814
- data/docs/database_rake_tasks.md +0 -345
- data/docs/development/rake-tasks.md +0 -1113
- data/docs/using_rake_tasks_in_your_app.md +0 -383
- data/examples/06_example_app/Rakefile +0 -71
- data/examples/12_rails_app/app/models/model.rb +0 -5
- data/examples/12_rails_app/app/models/tool_call.rb +0 -5
- data/examples/12_rails_app/db/migrate/20250124000001_create_ruby_llm_tables.rb +0 -34
- data/examples/12_rails_app/db/migrate/20250124000002_create_models_table.rb +0 -28
- data/lib/htm/mcp/cli.rb +0 -583
- data/lib/htm/tasks.rb +0 -79
- data/lib/tasks/db.rake +0 -15
- data/lib/tasks/doc.rake +0 -301
- data/lib/tasks/files.rake +0 -285
- data/lib/tasks/htm.rake +0 -703
- data/lib/tasks/jobs.rake +0 -429
- data/lib/tasks/tags.rake +0 -184
- data/scripts/backfill_parent_tags.rb +0 -376
- data/scripts/normalize_plural_tags.rb +0 -335
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
# Class
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Class HTM::WorkingMemory <a id="class-HTM-WorkingMemory"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Object |
|
|
6
|
+
| **Defined in** | lib/htm/working_memory.rb, lib/htm/working_memory/entry.rb, lib/htm/working_memory/store.rb |
|
|
4
7
|
|
|
5
8
|
Working Memory - Token-limited active context for immediate LLM use
|
|
6
9
|
|
|
@@ -8,124 +11,147 @@ WorkingMemory manages the active conversation context within token limits.
|
|
|
8
11
|
When full, it evicts less important or older nodes back to long-term storage.
|
|
9
12
|
|
|
10
13
|
Thread Safety: All public methods are protected by a mutex to ensure safe
|
|
11
|
-
concurrent access from multiple threads.
|
|
14
|
+
concurrent access from multiple threads. The node bookkeeping itself lives in
|
|
15
|
+
{Store}, which is not thread-safe on its own.
|
|
12
16
|
|
|
17
|
+
## Constants
|
|
18
|
+
### `SECONDS_PER_HOUR` <a id="constant-SECONDS_PER_HOUR"></a> <a id="SECONDS_PER_HOUR-constant"></a>
|
|
19
|
+
Seconds in an hour; recency decays on an hourly scale
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
## Attributes
|
|
22
|
+
### `max_tokens` [R] <a id="attribute-i-max_tokens"></a> <a id="max_tokens-instance_method"></a>
|
|
16
23
|
Returns the value of attribute max_tokens.
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
## Public Class Methods
|
|
26
|
+
### `count_to_reach(counts, target)` <a id="method-c-count_to_reach"></a> <a id="count_to_reach-class_method"></a>
|
|
27
|
+
How many leading token counts it takes to reach a target. Counts are taken
|
|
28
|
+
until their sum is at least the target.
|
|
29
|
+
- **`@param`** `counts` [Array<Integer>] Token counts, in eviction order
|
|
30
|
+
- **`@param`** `target` [Integer] Tokens needed
|
|
31
|
+
- **`@return`** [Integer] Number of leading counts to take
|
|
32
|
+
|
|
33
|
+
### `fit_to_budget(entries, budget)` <a id="method-c-fit_to_budget"></a> <a id="fit_to_budget-class_method"></a>
|
|
34
|
+
Values of entries, in order, that fit within a token budget. Stops at the
|
|
35
|
+
first entry that would exceed it.
|
|
36
|
+
- **`@param`** `entries` [Array<Entry>] Ordered entries
|
|
37
|
+
- **`@param`** `budget` [Integer] Maximum total tokens
|
|
38
|
+
- **`@return`** [Array<String>] Entry values
|
|
39
|
+
|
|
40
|
+
### `knowledge_labels(keys)` <a id="method-c-knowledge_labels"></a> <a id="knowledge_labels-class_method"></a>
|
|
41
|
+
Epistemic labels for the nodes among `keys` (node ids); empty when there are
|
|
42
|
+
none or the database cannot be read
|
|
43
|
+
- **`@param`** `keys` [Array] working memory keys
|
|
44
|
+
- **`@return`** [Hash{Integer => String}]
|
|
45
|
+
|
|
46
|
+
### `restorable_entries(robot_id)` <a id="method-c-restorable_entries"></a> <a id="restorable_entries-class_method"></a>
|
|
47
|
+
The nodes a robot's working memory held, as add_from_sync arguments, least
|
|
48
|
+
recently remembered first
|
|
49
|
+
- **`@param`** `robot_id` [Integer]
|
|
50
|
+
- **`@return`** [Array<Hash>] { id:, content:, token_count:, created_at: }
|
|
51
|
+
|
|
52
|
+
### `retirement_notes(keys)` <a id="method-c-retirement_notes"></a> <a id="retirement_notes-class_method"></a>
|
|
53
|
+
Timeline notes for the retired nodes among `keys` (node ids); empty when there
|
|
54
|
+
are none or the database cannot be read
|
|
55
|
+
- **`@param`** `keys` [Array] working memory keys
|
|
56
|
+
- **`@return`** [Hash{Integer => String}]
|
|
57
|
+
|
|
58
|
+
## Public Instance Methods
|
|
59
|
+
### `add(key, value, token_count:, access_count: 0)` <a id="method-i-add"></a> <a id="add-instance_method"></a>
|
|
21
60
|
Add a node to working memory
|
|
22
|
-
|
|
23
|
-
**`@param`** [String] Node
|
|
24
|
-
|
|
25
|
-
**`@param`** [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
**`@param`** [
|
|
32
|
-
|
|
33
|
-
**`@
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## add_from_sync(id:, content:, token_count:, created_at:) {: #method-i-add_from_sync }
|
|
61
|
+
- **`@param`** `key` [String] Node identifier
|
|
62
|
+
- **`@param`** `value` [String] Node content
|
|
63
|
+
- **`@param`** `token_count` [Integer] Number of tokens in this node
|
|
64
|
+
- **`@param`** `access_count` [Integer] Access count from long-term memory (default: 0)
|
|
65
|
+
- **`@return`** [void]
|
|
66
|
+
|
|
67
|
+
### `add_entry(key, entry)` <a id="method-i-add_entry"></a> <a id="add_entry-instance_method"></a>
|
|
68
|
+
Add a prepared entry, such as one recalled from long-term memory (see
|
|
69
|
+
{Entry.recalled})
|
|
70
|
+
- **`@param`** `key` [Object] Node identifier
|
|
71
|
+
- **`@param`** `entry` [Entry] The node
|
|
72
|
+
- **`@return`** [void]
|
|
73
|
+
|
|
74
|
+
### `add_from_sync(id:, content:, token_count:, created_at:)` <a id="method-i-add_from_sync"></a> <a id="add_from_sync-instance_method"></a>
|
|
38
75
|
Add a node from sync notification (bypasses normal add flow)
|
|
39
76
|
|
|
40
77
|
Called by RobotGroup when another robot adds to working memory. Does not
|
|
41
78
|
trigger notifications to avoid infinite loops.
|
|
79
|
+
- **`@param`** `id` [Integer] Node database ID
|
|
80
|
+
- **`@param`** `content` [String] Node content
|
|
81
|
+
- **`@param`** `token_count` [Integer] Token count
|
|
82
|
+
- **`@param`** `created_at` [Time] When node was created
|
|
83
|
+
- **`@return`** [void]
|
|
42
84
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
**`@param`** [String] Node content
|
|
46
|
-
|
|
47
|
-
**`@param`** [Integer] Token count
|
|
48
|
-
|
|
49
|
-
**`@param`** [Time] When node was created
|
|
50
|
-
|
|
51
|
-
**`@return`** [void]
|
|
52
|
-
|
|
53
|
-
## assemble_context(strategy:, max_tokens:nil) {: #method-i-assemble_context }
|
|
85
|
+
### `assemble_context(strategy:, max_tokens: @max_tokens)` <a id="method-i-assemble_context"></a> <a id="assemble_context-instance_method"></a>
|
|
54
86
|
Assemble context string for LLM
|
|
55
|
-
|
|
56
|
-
**`@param`** [Symbol] Assembly strategy (:recent, :frequent, :balanced)
|
|
87
|
+
- **`@param`** `strategy` [Symbol] Assembly strategy (:recent, :frequent, :balanced)
|
|
57
88
|
- :recent - Most recently accessed (LRU)
|
|
58
89
|
- :frequent - Most frequently accessed (LFU)
|
|
59
90
|
- :balanced - Combines frequency × recency
|
|
60
|
-
|
|
61
|
-
**`@
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
- **`@param`** `max_tokens` [Integer] Optional token limit (default: this memory's limit)
|
|
92
|
+
- **`@return`** [String] Assembled context. Each node is prefixed with how it
|
|
93
|
+
is known and when, e.g. "[stated 2026-11-21]" or
|
|
94
|
+
"[inferred from #88, 2026-11-22, confidence 0.60]" (see
|
|
95
|
+
HTM::Epistemics.labels). A node retired since it entered working
|
|
96
|
+
memory (superseded, merged, archived) also gets a note saying so,
|
|
97
|
+
e.g. "(superseded by #41 on 2026-03-03: moved)".
|
|
98
|
+
|
|
99
|
+
### `clear()` <a id="method-i-clear"></a> <a id="clear-instance_method"></a>
|
|
66
100
|
Clear all nodes from working memory
|
|
101
|
+
- **`@return`** [void]
|
|
67
102
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
## clear_from_sync() {: #method-i-clear_from_sync }
|
|
103
|
+
### `clear_from_sync()` <a id="method-i-clear_from_sync"></a> <a id="clear_from_sync-instance_method"></a>
|
|
71
104
|
Clear all nodes from sync notification
|
|
72
105
|
|
|
73
106
|
Called by RobotGroup when another robot clears working memory.
|
|
107
|
+
- **`@return`** [void]
|
|
74
108
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
## evict_to_make_space(needed_tokens) {: #method-i-evict_to_make_space }
|
|
109
|
+
### `evict_to_make_space(needed_tokens)` <a id="method-i-evict_to_make_space"></a> <a id="evict_to_make_space-instance_method"></a>
|
|
78
110
|
Evict nodes to make space
|
|
79
111
|
|
|
80
|
-
Uses LFU + LRU strategy: Least Frequently Used + Least Recently Used
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
**`@
|
|
84
|
-
|
|
85
|
-
**`@return`** [Array<Hash>] Evicted nodes
|
|
112
|
+
Uses LFU + LRU strategy: Least Frequently Used + Least Recently Used,
|
|
113
|
+
combining access count and time since last access into one score.
|
|
114
|
+
- **`@param`** `needed_tokens` [Integer] Number of tokens needed
|
|
115
|
+
- **`@return`** [Array<Hash>] Evicted nodes
|
|
86
116
|
|
|
87
|
-
|
|
117
|
+
### `has_space?(token_count)` <a id="method-i-has_space-3F"></a> <a id="has_space?-instance_method"></a>
|
|
88
118
|
Check if there's space for a node
|
|
119
|
+
- **`@param`** `token_count` [Integer] Number of tokens needed
|
|
120
|
+
- **`@return`** [Boolean] true if space available
|
|
89
121
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
**`@return`** [Boolean] true if space available
|
|
93
|
-
|
|
94
|
-
## initialize(max_tokens:) {: #method-i-initialize }
|
|
122
|
+
### `initialize(max_tokens:)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
|
|
95
123
|
Initialize working memory
|
|
124
|
+
- **`@param`** `max_tokens` [Integer] Maximum tokens allowed in working memory
|
|
125
|
+
- **`@return`** [WorkingMemory] a new instance of WorkingMemory
|
|
96
126
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
**`@return`** [WorkingMemory] a new instance of WorkingMemory
|
|
100
|
-
|
|
101
|
-
## node_count() {: #method-i-node_count }
|
|
127
|
+
### `node_count()` <a id="method-i-node_count"></a> <a id="node_count-instance_method"></a>
|
|
102
128
|
Get node count
|
|
129
|
+
- **`@return`** [Integer] Number of nodes in working memory
|
|
103
130
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
## remove(key) {: #method-i-remove }
|
|
131
|
+
### `remove(key)` <a id="method-i-remove"></a> <a id="remove-instance_method"></a>
|
|
107
132
|
Remove a node from working memory
|
|
133
|
+
- **`@param`** `key` [String] Node identifier
|
|
134
|
+
- **`@return`** [void]
|
|
108
135
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
**`@return`** [void]
|
|
112
|
-
|
|
113
|
-
## remove_from_sync(node_id) {: #method-i-remove_from_sync }
|
|
136
|
+
### `remove_from_sync(node_id)` <a id="method-i-remove_from_sync"></a> <a id="remove_from_sync-instance_method"></a>
|
|
114
137
|
Remove a node from sync notification
|
|
115
138
|
|
|
116
139
|
Called by RobotGroup when another robot evicts from working memory.
|
|
117
|
-
|
|
118
|
-
**`@
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
140
|
+
- **`@param`** `node_id` [Integer] Node database ID
|
|
141
|
+
- **`@return`** [void]
|
|
142
|
+
|
|
143
|
+
### `restore(robot_id)` <a id="method-i-restore"></a> <a id="restore-instance_method"></a>
|
|
144
|
+
Refill from the database: the nodes it marks as in `robot_id`'s working
|
|
145
|
+
memory, oldest first, while they fit the token budget. A new process (the MCP
|
|
146
|
+
server, the command line) calls this to pick up the context a robot built up
|
|
147
|
+
earlier.
|
|
148
|
+
- **`@param`** `robot_id` [Integer]
|
|
149
|
+
- **`@return`** [Integer] nodes now in working memory
|
|
150
|
+
|
|
151
|
+
### `token_count()` <a id="method-i-token_count"></a> <a id="token_count-instance_method"></a>
|
|
123
152
|
Get current token count
|
|
153
|
+
- **`@return`** [Integer] Total tokens in working memory
|
|
124
154
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
## utilization_percentage() {: #method-i-utilization_percentage }
|
|
155
|
+
### `utilization_percentage()` <a id="method-i-utilization_percentage"></a> <a id="utilization_percentage-instance_method"></a>
|
|
128
156
|
Get utilization percentage
|
|
129
|
-
|
|
130
|
-
**`@return`** [Float] Percentage of working memory used
|
|
131
|
-
|
|
157
|
+
- **`@return`** [Float] Percentage of working memory used
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Class HTM::WorkingMemoryChannel::Subscribers <a id="class-HTM-WorkingMemoryChannel-Subscribers"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Object |
|
|
6
|
+
| **Defined in** | lib/htm/working_memory_channel.rb |
|
|
7
|
+
|
|
8
|
+
Thread-safe registry of change callbacks. Decodes each notification payload,
|
|
9
|
+
counts it, and passes it to every registered callback.
|
|
10
|
+
|
|
11
|
+
## Attributes
|
|
12
|
+
### `received` [R] <a id="attribute-i-received"></a> <a id="received-instance_method"></a>
|
|
13
|
+
Number of notifications dispatched so far
|
|
14
|
+
- **`@return`** [Integer]
|
|
15
|
+
|
|
16
|
+
## Public Instance Methods
|
|
17
|
+
### `add(callback)` <a id="method-i-add"></a> <a id="add-instance_method"></a>
|
|
18
|
+
Registers a callback for (event, node_id, robot_id)
|
|
19
|
+
- **`@return`** [void]
|
|
20
|
+
|
|
21
|
+
### `dispatch(payload)` <a id="method-i-dispatch"></a> <a id="dispatch-instance_method"></a>
|
|
22
|
+
Decodes a JSON notification payload and calls every callback with it. Logs and
|
|
23
|
+
ignores a payload that is not valid JSON.
|
|
24
|
+
- **`@param`** `payload` [String] JSON payload from pg_notify
|
|
25
|
+
- **`@return`** [void]
|
|
26
|
+
|
|
27
|
+
### `initialize()` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
|
|
28
|
+
- **`@return`** [Subscribers] a new instance of Subscribers
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
# Class
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Class HTM::WorkingMemoryChannel <a id="class-HTM-WorkingMemoryChannel"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Object |
|
|
6
|
+
| **Defined in** | lib/htm/working_memory_channel.rb |
|
|
4
7
|
|
|
5
8
|
Provides real-time synchronization of working memory changes across multiple
|
|
6
9
|
robots using PostgreSQL LISTEN/NOTIFY pub/sub mechanism.
|
|
@@ -10,10 +13,9 @@ by broadcasting change notifications through PostgreSQL channels. When one
|
|
|
10
13
|
robot adds, evicts, or clears working memory, all other robots in the group
|
|
11
14
|
receive immediate notification.
|
|
12
15
|
|
|
13
|
-
**`@see`**
|
|
14
|
-
|
|
16
|
+
- **`@see`** `HTM::RobotGroup` Higher-level coordination using this channel
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
**@example Basic usage**
|
|
17
19
|
```ruby
|
|
18
20
|
channel = HTM::WorkingMemoryChannel.new('support-team', db_config)
|
|
19
21
|
|
|
@@ -35,142 +37,146 @@ channel.notify(:added, node_id: 123, robot_id: 456)
|
|
|
35
37
|
# Cleanup when done
|
|
36
38
|
channel.stop_listening
|
|
37
39
|
```
|
|
38
|
-
# Attributes
|
|
39
|
-
## notifications_received[RW] {: #attribute-i-notifications_received }
|
|
40
|
-
Number of notifications received since channel was created
|
|
41
|
-
|
|
42
|
-
**`@return`** [Integer]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
# Instance Methods
|
|
46
|
-
## channel_name() {: #method-i-channel_name }
|
|
47
|
-
Returns the PostgreSQL channel name used for notifications.
|
|
48
|
-
|
|
49
|
-
The channel name is derived from the group name with a prefix and sanitization
|
|
50
|
-
of special characters.
|
|
51
|
-
|
|
52
|
-
**`@return`** [String] The PostgreSQL LISTEN/NOTIFY channel name
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
**`@example`**
|
|
56
|
-
```ruby
|
|
57
|
-
channel = HTM::WorkingMemoryChannel.new('my-group', db_config)
|
|
58
|
-
channel.channel_name # => "htm_wm_my_group"
|
|
59
|
-
```
|
|
60
|
-
## initialize(group_name, db_config) {: #method-i-initialize }
|
|
61
|
-
Creates a new working memory channel for a robot group.
|
|
62
|
-
|
|
63
|
-
The channel name is derived from the group name with non-alphanumeric
|
|
64
|
-
characters replaced by underscores to ensure PostgreSQL compatibility.
|
|
65
|
-
|
|
66
|
-
**`@option`** []
|
|
67
|
-
|
|
68
|
-
**`@option`** []
|
|
69
|
-
|
|
70
|
-
**`@option`** []
|
|
71
|
-
|
|
72
|
-
**`@option`** []
|
|
73
|
-
|
|
74
|
-
**`@option`** []
|
|
75
|
-
|
|
76
|
-
**`@param`** [String] Name of the robot group (used to create unique channel)
|
|
77
|
-
|
|
78
|
-
**`@param`** [Hash] PostgreSQL connection configuration hash
|
|
79
|
-
|
|
80
|
-
**`@return`** [WorkingMemoryChannel] a new instance of WorkingMemoryChannel
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
**`@example`**
|
|
84
|
-
```ruby
|
|
85
|
-
db_config = { host: 'localhost', port: 5432, dbname: 'htm_dev', user: 'postgres' }
|
|
86
|
-
channel = HTM::WorkingMemoryChannel.new('customer-support', db_config)
|
|
87
|
-
```
|
|
88
|
-
## listening?() {: #method-i-listening? }
|
|
89
|
-
Checks if the listener thread is currently active.
|
|
90
|
-
|
|
91
|
-
**`@return`** [Boolean] true if listening for notifications, false otherwise
|
|
92
|
-
|
|
93
40
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
channel
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
41
|
+
## Constants
|
|
42
|
+
### `CHANNEL_PREFIX` <a id="constant-CHANNEL_PREFIX"></a> <a id="CHANNEL_PREFIX-constant"></a>
|
|
43
|
+
Prefix used for all PostgreSQL channel names
|
|
44
|
+
- **`@return`** [String]
|
|
45
|
+
|
|
46
|
+
### `MAX_CHANNEL_BYTES` <a id="constant-MAX_CHANNEL_BYTES"></a> <a id="MAX_CHANNEL_BYTES-constant"></a>
|
|
47
|
+
PostgreSQL identifier limit (NAMEDATALEN - 1); pg_notify rejects longer
|
|
48
|
+
channels
|
|
49
|
+
- **`@return`** [Integer]
|
|
50
|
+
|
|
51
|
+
### `MAX_GROUP_NAME_LENGTH` <a id="constant-MAX_GROUP_NAME_LENGTH"></a> <a id="MAX_GROUP_NAME_LENGTH-constant"></a>
|
|
52
|
+
Longest group name that fits in a channel name
|
|
53
|
+
- **`@return`** [Integer]
|
|
54
|
+
|
|
55
|
+
### `STOP_KEY` <a id="constant-STOP_KEY"></a> <a id="STOP_KEY-constant"></a>
|
|
56
|
+
Thread-local key the listener thread checks to know it should stop
|
|
57
|
+
|
|
58
|
+
## Public Class Methods
|
|
59
|
+
### Subscribing
|
|
60
|
+
#### `stop_thread(thread)` <a id="method-c-stop_thread"></a> <a id="stop_thread-class_method"></a>
|
|
61
|
+
Asks a listener thread to stop, waits up to 0.5 seconds for it to exit
|
|
62
|
+
cleanly, then kills it if it is still running.
|
|
63
|
+
- **`@param`** `thread` [Thread] Listener thread started by {#start_listening}
|
|
64
|
+
- **`@return`** [void]
|
|
65
|
+
|
|
66
|
+
## Public Instance Methods
|
|
67
|
+
### Publishing
|
|
68
|
+
#### `notify(event, node_id:, robot_id:)` <a id="method-i-notify"></a> <a id="notify-instance_method"></a>
|
|
102
69
|
Broadcasts a working memory change notification to all listeners.
|
|
103
70
|
|
|
104
71
|
Uses PostgreSQL's pg_notify function to send a JSON payload containing the
|
|
105
72
|
event type, affected node ID, originating robot ID, and timestamp.
|
|
73
|
+
- **`@param`** `event` [Symbol] Type of change (:added, :evicted, or :cleared)
|
|
74
|
+
- **`@param`** `node_id` [Integer, nil] ID of the affected node (nil for :cleared events)
|
|
75
|
+
- **`@param`** `robot_id` [Integer] ID of the robot that triggered the change
|
|
76
|
+
- **`@return`** [void]
|
|
106
77
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
**`@param`** [Integer, nil] ID of the affected node (nil for :cleared events)
|
|
110
|
-
|
|
111
|
-
**`@param`** [Integer] ID of the robot that triggered the change
|
|
112
|
-
|
|
113
|
-
**`@return`** [void]
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
**`@example`**
|
|
78
|
+
**@example Notify that a node was added**
|
|
117
79
|
```ruby
|
|
118
80
|
channel.notify(:added, node_id: 123, robot_id: 1)
|
|
119
81
|
```
|
|
120
|
-
|
|
82
|
+
|
|
83
|
+
**@example Notify that working memory was cleared**
|
|
121
84
|
```ruby
|
|
122
85
|
channel.notify(:cleared, node_id: nil, robot_id: 1)
|
|
123
86
|
```
|
|
124
|
-
|
|
87
|
+
### Subscribing
|
|
88
|
+
#### `on_change(&callback)` <a id="method-i-on_change"></a> <a id="on_change-instance_method"></a>
|
|
125
89
|
Registers a callback to be invoked when working memory changes occur.
|
|
126
90
|
|
|
127
91
|
Multiple callbacks can be registered; all will be called for each event.
|
|
128
92
|
Callbacks are invoked synchronously within the listener thread.
|
|
93
|
+
- **`@return`** [void]
|
|
94
|
+
- **`@yield`** [event, node_id, robot_id] Block called for each notification
|
|
95
|
+
- **`@yieldparam`** `event` [Symbol] Type of change (:added, :evicted, or :cleared)
|
|
96
|
+
- **`@yieldparam`** `node_id` [Integer, nil] ID of the affected node
|
|
97
|
+
- **`@yieldparam`** `robot_id` [Integer] ID of the robot that triggered the change
|
|
129
98
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
**`@yield`** [event, node_id, robot_id] Block called for each notification
|
|
133
|
-
|
|
134
|
-
**`@yieldparam`** [Symbol] Type of change (:added, :evicted, or :cleared)
|
|
135
|
-
|
|
136
|
-
**`@yieldparam`** [Integer, nil] ID of the affected node
|
|
137
|
-
|
|
138
|
-
**`@yieldparam`** [Integer] ID of the robot that triggered the change
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
**`@example`**
|
|
99
|
+
**@example Register a change handler**
|
|
142
100
|
```ruby
|
|
143
101
|
channel.on_change do |event, node_id, robot_id|
|
|
144
102
|
puts "Received #{event} event for node #{node_id}"
|
|
145
103
|
end
|
|
146
104
|
```
|
|
147
|
-
|
|
105
|
+
|
|
106
|
+
#### `start_listening()` <a id="method-i-start_listening"></a> <a id="start_listening-instance_method"></a>
|
|
148
107
|
Starts listening for notifications in a background thread.
|
|
149
108
|
|
|
150
109
|
Creates a dedicated PostgreSQL connection that uses LISTEN to receive
|
|
151
110
|
notifications. The thread polls every 0.5 seconds, allowing for clean shutdown
|
|
152
111
|
via {#stop_listening}.
|
|
112
|
+
- **`@return`** [Thread] The background listener thread
|
|
153
113
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
**`@example`**
|
|
114
|
+
**@example Start and verify listening**
|
|
158
115
|
```ruby
|
|
159
116
|
thread = channel.start_listening
|
|
160
117
|
puts "Listening: #{channel.listening?}" # => true
|
|
161
118
|
```
|
|
162
|
-
|
|
119
|
+
|
|
120
|
+
#### `stop_listening()` <a id="method-i-stop_listening"></a> <a id="stop_listening-instance_method"></a>
|
|
163
121
|
Stops the background listener thread.
|
|
164
122
|
|
|
165
123
|
Signals the listener to stop, waits up to 0.5 seconds for clean exit, then
|
|
166
124
|
forcefully terminates if still running. The PostgreSQL connection is closed
|
|
167
125
|
automatically.
|
|
126
|
+
- **`@return`** [void]
|
|
127
|
+
|
|
128
|
+
**@example Clean shutdown**
|
|
129
|
+
```ruby
|
|
130
|
+
channel.stop_listening
|
|
131
|
+
puts "Listening: #{channel.listening?}" # => false
|
|
132
|
+
```
|
|
133
|
+
### Status
|
|
134
|
+
#### `channel_name()` <a id="method-i-channel_name"></a> <a id="channel_name-instance_method"></a>
|
|
135
|
+
Returns the PostgreSQL channel name used for notifications.
|
|
136
|
+
|
|
137
|
+
The channel name is derived from the group name with a prefix and sanitization
|
|
138
|
+
of special characters.
|
|
139
|
+
- **`@return`** [String] The PostgreSQL LISTEN/NOTIFY channel name
|
|
168
140
|
|
|
169
|
-
**`@
|
|
141
|
+
**`@example`**
|
|
142
|
+
```ruby
|
|
143
|
+
channel = HTM::WorkingMemoryChannel.new('my-group', db_config)
|
|
144
|
+
channel.channel_name # => "htm_wm_my_group"
|
|
145
|
+
```
|
|
170
146
|
|
|
147
|
+
#### `listening?()` <a id="method-i-listening-3F"></a> <a id="listening?-instance_method"></a>
|
|
148
|
+
Checks if the listener thread is currently active.
|
|
149
|
+
- **`@return`** [Boolean] true if listening for notifications, false otherwise
|
|
171
150
|
|
|
172
151
|
**`@example`**
|
|
173
152
|
```ruby
|
|
153
|
+
channel.start_listening
|
|
154
|
+
channel.listening? # => true
|
|
174
155
|
channel.stop_listening
|
|
175
|
-
|
|
176
|
-
```
|
|
156
|
+
channel.listening? # => false
|
|
157
|
+
```
|
|
158
|
+
### General
|
|
159
|
+
#### `initialize(group_name, db_config)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
|
|
160
|
+
Creates a new working memory channel for a robot group.
|
|
161
|
+
|
|
162
|
+
The channel name is derived from the group name with non-alphanumeric
|
|
163
|
+
characters replaced by underscores to ensure PostgreSQL compatibility.
|
|
164
|
+
- **`@option`** `db_config[:host]` [String] Database host
|
|
165
|
+
- **`@option`** `db_config[:port]` [Integer] Database port
|
|
166
|
+
- **`@option`** `db_config[:dbname]` [String] Database name
|
|
167
|
+
- **`@option`** `db_config[:user]` [String] Database user
|
|
168
|
+
- **`@option`** `db_config[:password]` [String] Database password (optional)
|
|
169
|
+
- **`@param`** `group_name` [String] Name of the robot group (used to create unique channel)
|
|
170
|
+
- **`@param`** `db_config` [Hash] PostgreSQL connection configuration hash
|
|
171
|
+
- **`@raise`** [ArgumentError] if the group name is longer than {MAX_GROUP_NAME_LENGTH} characters
|
|
172
|
+
- **`@return`** [WorkingMemoryChannel] a new instance of WorkingMemoryChannel
|
|
173
|
+
|
|
174
|
+
**`@example`**
|
|
175
|
+
```ruby
|
|
176
|
+
db_config = { host: 'localhost', port: 5432, dbname: 'htm_dev', user: 'postgres' }
|
|
177
|
+
channel = HTM::WorkingMemoryChannel.new('customer-support', db_config)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### `notifications_received()` <a id="method-i-notifications_received"></a> <a id="notifications_received-instance_method"></a>
|
|
181
|
+
Number of notifications received since channel was created
|
|
182
|
+
- **`@return`** [Integer]
|