htm 0.0.31 → 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 +16 -17
- data/.reek.yml +104 -0
- data/.rubocop.yml +173 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +162 -54
- data/README.md +24 -17
- data/SETUP.md +49 -46
- data/_typos.toml +17 -0
- data/bin/htm +18 -0
- data/db/migrate/00008_create_node_relationships.rb +54 -0
- data/db/migrate/00009_fix_node_relationships_column_types.rb +17 -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 +361 -7
- data/db/seed_data/README.md +11 -11
- data/db/seeds.rb +11 -11
- data/docs/api/database.md +43 -65
- data/docs/api/embedding-service.md +139 -263
- data/docs/api/htm.md +128 -12
- data/docs/api/index.md +34 -23
- data/docs/api/long-term-memory.md +8 -19
- data/docs/api/working-memory.md +42 -54
- 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 +7 -9
- data/docs/architecture/overview.md +8 -11
- data/docs/assets/images/htm-architecture-overview.svg +1 -1
- data/docs/assets/images/htm-context-assembly-flow.svg +2 -2
- data/docs/assets/images/htm-layered-architecture.svg +3 -3
- data/docs/assets/images/project-structure.svg +2 -2
- data/docs/assets/images/two-tier-memory-architecture.svg +1 -1
- data/docs/database/INDEX.md +113 -0
- data/docs/database/README.md +60 -175
- 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 +11 -11
- data/docs/development/index.md +19 -24
- data/docs/development/schema.md +113 -14
- data/docs/development/setup.md +99 -151
- data/docs/development/testing.md +58 -66
- data/docs/examples/basic-usage.md +9 -9
- data/docs/examples/config-files.md +8 -8
- data/docs/examples/file-loading.md +16 -16
- 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 +28 -26
- data/docs/guides/adding-memories.md +28 -4
- data/docs/guides/cli.md +458 -0
- data/docs/guides/configuration.md +77 -42
- data/docs/guides/context-assembly.md +4 -4
- data/docs/guides/epistemic-status.md +138 -0
- data/docs/guides/event-time.md +106 -0
- data/docs/guides/file-loading.md +36 -32
- data/docs/guides/getting-started.md +23 -19
- data/docs/guides/long-term-memory.md +8 -28
- data/docs/guides/mcp-server.md +416 -173
- data/docs/guides/propositions.md +30 -40
- data/docs/guides/recalling-memories.md +27 -12
- data/docs/guides/robot-teams.md +96 -0
- data/docs/guides/search-strategies.md +10 -7
- data/docs/guides/tags.md +37 -32
- 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 +14 -14
- data/docs/robots/hive-mind.md +1 -1
- data/docs/robots/multi-robot.md +2 -2
- data/docs/robots/robot-groups.md +10 -10
- data/docs/robots/two-tier-memory.md +85 -120
- data/docs/setup_local_database.md +41 -85
- data/examples/00_create_examples_db.rb +20 -7
- data/examples/01_basic_usage.rb +21 -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 +13 -12
- data/examples/04_file_loader_usage.rb +16 -21
- data/examples/05_timeframe_demo.rb +283 -234
- data/examples/06_example_app/.loki +36 -0
- data/examples/06_example_app/app.rb +22 -33
- data/examples/07_cli_app/README.md +18 -18
- data/examples/07_cli_app/htm_cli.rb +26 -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 +93 -119
- data/examples/10_telemetry/README.md +3 -3
- data/examples/10_telemetry/SETUP_README.md +2 -2
- data/examples/10_telemetry/demo.rb +6 -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 +6 -4
- data/examples/11_robot_groups/same_process.rb +19 -17
- data/examples/12_rails_app/.envrc +12 -0
- data/examples/12_rails_app/Gemfile +8 -3
- data/examples/12_rails_app/Gemfile.lock +226 -172
- data/examples/12_rails_app/README.md +77 -22
- data/examples/12_rails_app/app/controllers/application_controller.rb +6 -0
- data/examples/12_rails_app/app/controllers/chats_controller.rb +275 -0
- data/examples/12_rails_app/app/controllers/dashboard_controller.rb +3 -0
- data/examples/12_rails_app/app/controllers/files_controller.rb +17 -2
- data/examples/12_rails_app/app/controllers/home_controller.rb +8 -0
- data/examples/12_rails_app/app/controllers/memories_controller.rb +16 -5
- data/examples/12_rails_app/app/controllers/messages_controller.rb +177 -0
- data/examples/12_rails_app/app/controllers/robots_controller.rb +11 -1
- data/examples/12_rails_app/app/controllers/search_controller.rb +7 -2
- data/examples/12_rails_app/app/controllers/tags_controller.rb +14 -1
- data/examples/12_rails_app/app/javascript/application.js +1 -1
- data/examples/12_rails_app/app/models/application_record.rb +5 -0
- data/examples/12_rails_app/app/models/chat.rb +3 -0
- data/examples/12_rails_app/app/models/message.rb +3 -0
- data/examples/12_rails_app/app/views/chats/index.html.erb +61 -0
- data/examples/12_rails_app/app/views/chats/show.html.erb +213 -0
- data/examples/12_rails_app/app/views/dashboard/index.html.erb +3 -0
- data/examples/12_rails_app/app/views/files/index.html.erb +10 -5
- data/examples/12_rails_app/app/views/files/new.html.erb +5 -3
- data/examples/12_rails_app/app/views/files/show.html.erb +19 -3
- data/examples/12_rails_app/app/views/home/index.html.erb +45 -0
- data/examples/12_rails_app/app/views/layouts/application.html.erb +20 -18
- data/examples/12_rails_app/app/views/memories/_memory_card.html.erb +2 -2
- data/examples/12_rails_app/app/views/memories/deleted.html.erb +3 -1
- data/examples/12_rails_app/app/views/memories/edit.html.erb +2 -0
- data/examples/12_rails_app/app/views/memories/index.html.erb +2 -0
- data/examples/12_rails_app/app/views/memories/new.html.erb +14 -0
- data/examples/12_rails_app/app/views/memories/show.html.erb +17 -2
- data/examples/12_rails_app/app/views/messages/_message.html.erb +20 -0
- data/examples/12_rails_app/app/views/robots/index.html.erb +2 -0
- data/examples/12_rails_app/app/views/robots/new.html.erb +2 -0
- data/examples/12_rails_app/app/views/robots/show.html.erb +2 -0
- data/examples/12_rails_app/app/views/search/index.html.erb +77 -10
- data/examples/12_rails_app/app/views/shared/_navbar.html.erb +75 -29
- data/examples/12_rails_app/app/views/tags/index.html.erb +2 -0
- data/examples/12_rails_app/app/views/tags/show.html.erb +3 -1
- data/examples/12_rails_app/config/application.rb +1 -1
- data/examples/12_rails_app/config/database.yml +9 -5
- data/examples/12_rails_app/config/importmap.rb +1 -1
- data/examples/12_rails_app/config/initializers/htm.rb +9 -2
- data/examples/12_rails_app/config/initializers/ruby_llm.rb +29 -0
- data/examples/12_rails_app/config/routes.rb +39 -23
- 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 +210 -0
- data/examples/README.md +53 -44
- data/examples/examples_helper.rb +52 -3
- 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 -69
- 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 +106 -75
- data/lib/htm/config/coercion.rb +91 -0
- data/lib/htm/config/database.rb +94 -71
- 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 +47 -34
- data/lib/htm/config.rb +122 -296
- data/lib/htm/database.rb +330 -427
- data/lib/htm/database_docs.rb +149 -0
- data/lib/htm/embedding_service.rb +29 -74
- 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 +45 -33
- data/lib/htm/job_adapter.rb +79 -91
- data/lib/htm/jobs/failure_logging.rb +49 -0
- data/lib/htm/jobs/generate_embedding_job.rb +28 -51
- data/lib/htm/jobs/generate_propositions_job.rb +59 -57
- data/lib/htm/jobs/generate_relationships_job.rb +141 -0
- data/lib/htm/jobs/generate_tags_job.rb +44 -71
- 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 +99 -190
- data/lib/htm/long_term_memory/fulltext_search.rb +16 -37
- data/lib/htm/long_term_memory/hybrid_search.rb +484 -385
- data/lib/htm/long_term_memory/node_operations.rb +111 -82
- data/lib/htm/long_term_memory/relevance_scorer.rb +254 -227
- data/lib/htm/long_term_memory/tag_operations.rb +225 -187
- data/lib/htm/long_term_memory/vector_search.rb +34 -62
- data/lib/htm/long_term_memory.rb +5 -16
- 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 -15
- 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 +230 -287
- data/lib/htm/migration.rb +10 -10
- data/lib/htm/models/file_source.rb +35 -20
- data/lib/htm/models/node.rb +288 -195
- data/lib/htm/models/node_link.rb +97 -0
- data/lib/htm/models/node_relationship.rb +73 -0
- data/lib/htm/models/node_tag.rb +24 -4
- data/lib/htm/models/robot.rb +4 -8
- data/lib/htm/models/robot_node.rb +7 -4
- data/lib/htm/models/tag.rb +54 -195
- data/lib/htm/node_enrichment.rb +75 -0
- data/lib/htm/node_view.rb +295 -0
- data/lib/htm/observability.rb +125 -115
- data/lib/htm/proposition_service.rb +41 -81
- data/lib/htm/query_cache.rb +148 -96
- data/lib/htm/railtie.rb +4 -9
- 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 +130 -523
- 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 +96 -59
- data/lib/htm/sql_builder.rb +162 -53
- data/lib/htm/startup_prompt.rb +73 -0
- data/lib/htm/tag_service.rb +105 -114
- data/lib/htm/tag_tree.rb +206 -0
- data/lib/htm/telemetry.rb +15 -16
- data/lib/htm/timeframe.rb +30 -13
- data/lib/htm/timeframe_extractor.rb +104 -123
- data/lib/htm/timeline.rb +230 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm/workflows/remember_workflow.rb +147 -141
- data/lib/htm/working_memory/entry.rb +53 -0
- data/lib/htm/working_memory/store.rb +97 -0
- data/lib/htm/working_memory.rb +135 -142
- data/lib/htm/working_memory_channel.rb +90 -40
- data/lib/htm.rb +185 -522
- data/mkdocs.yml +100 -23
- data/scripts/install_local_database.sh +7 -6
- metadata +1032 -669
- data/.tbls.yml +0 -31
- data/Rakefile +0 -159
- 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 -353
- 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/lib/htm/mcp/cli.rb +0 -582
- data/lib/htm/tasks.rb +0 -79
- data/lib/tasks/db.rake +0 -17
- data/lib/tasks/doc.rake +0 -300
- data/lib/tasks/files.rake +0 -292
- data/lib/tasks/htm.rake +0 -704
- data/lib/tasks/jobs.rake +0 -435
- data/lib/tasks/tags.rake +0 -189
- data/scripts/backfill_parent_tags.rb +0 -376
- data/scripts/normalize_plural_tags.rb +0 -335
data/lib/htm/mcp/tools.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative 'tool'
|
|
4
4
|
|
|
5
5
|
class HTM
|
|
6
6
|
module MCP
|
|
@@ -10,15 +10,20 @@ class HTM
|
|
|
10
10
|
DEFAULT_ROBOT_NAME = "mcp_default"
|
|
11
11
|
|
|
12
12
|
class << self
|
|
13
|
-
|
|
13
|
+
attr_reader :logger
|
|
14
|
+
|
|
15
|
+
# Use the given logger for all MCP session logging
|
|
16
|
+
def attach_logger(logger)
|
|
17
|
+
@logger = logger
|
|
18
|
+
end
|
|
14
19
|
|
|
15
20
|
def htm_instance
|
|
16
|
-
@htm_instance ||=
|
|
21
|
+
@htm_instance ||= build(DEFAULT_ROBOT_NAME)
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
def set_robot(name)
|
|
20
25
|
@robot_name = name
|
|
21
|
-
@htm_instance =
|
|
26
|
+
@htm_instance = build(name)
|
|
22
27
|
logger&.info "Robot set: #{name} (id=#{@htm_instance.robot_id})"
|
|
23
28
|
@htm_instance
|
|
24
29
|
end
|
|
@@ -30,249 +35,227 @@ class HTM
|
|
|
30
35
|
def robot_initialized?
|
|
31
36
|
@robot_name != nil
|
|
32
37
|
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# An HTM instance for the robot, its working memory refilled from the
|
|
42
|
+
# database so context survives a server restart
|
|
43
|
+
def build(name)
|
|
44
|
+
HTM.new(robot_name: name).tap { it.working_memory.restore(it.robot_id) }
|
|
45
|
+
end
|
|
33
46
|
end
|
|
34
47
|
end
|
|
35
48
|
|
|
36
49
|
# Tool: Set the robot identity for this session
|
|
37
|
-
class SetRobotTool <
|
|
38
|
-
description "Set the robot identity for this session. Call this first to establish your robot name."
|
|
50
|
+
class SetRobotTool < Tool
|
|
51
|
+
description "Set the robot identity for this session. Call this first to establish your robot name. " \
|
|
52
|
+
"The robot's working memory from earlier sessions is restored."
|
|
39
53
|
|
|
40
54
|
arguments do
|
|
41
55
|
required(:name).filled(:string).description("The robot name (will be created if it doesn't exist)")
|
|
42
56
|
end
|
|
43
57
|
|
|
44
58
|
def call(name:)
|
|
45
|
-
|
|
59
|
+
log_info "SetRobotTool called: name=#{name.inspect}"
|
|
46
60
|
|
|
47
|
-
htm
|
|
48
|
-
robot = HTM::Models::Robot[htm.robot_id]
|
|
61
|
+
htm = Session.set_robot(name)
|
|
49
62
|
|
|
50
63
|
{
|
|
51
|
-
success:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
message:
|
|
64
|
+
success: true,
|
|
65
|
+
**robot_identity(htm),
|
|
66
|
+
node_count: robot_record(htm).node_count,
|
|
67
|
+
working_memory_nodes: htm.working_memory.node_count,
|
|
68
|
+
message: "Robot '#{name}' is now active for this session"
|
|
56
69
|
}.to_json
|
|
57
70
|
end
|
|
58
71
|
end
|
|
59
72
|
|
|
60
73
|
# Tool: Get current robot info
|
|
61
|
-
class GetRobotTool <
|
|
74
|
+
class GetRobotTool < Tool
|
|
75
|
+
read_only!
|
|
62
76
|
description "Get information about the current robot for this session"
|
|
63
77
|
|
|
64
78
|
arguments do
|
|
65
79
|
end
|
|
66
80
|
|
|
67
81
|
def call
|
|
68
|
-
|
|
82
|
+
log_info "GetRobotTool called"
|
|
69
83
|
|
|
70
|
-
htm
|
|
71
|
-
robot = HTM::Models::Robot[htm.robot_id]
|
|
84
|
+
htm = session_htm
|
|
72
85
|
|
|
73
86
|
{
|
|
74
87
|
success: true,
|
|
75
|
-
|
|
76
|
-
robot_name: htm.robot_name,
|
|
88
|
+
**robot_identity(htm),
|
|
77
89
|
initialized: Session.robot_initialized?,
|
|
78
|
-
memory_summary:
|
|
90
|
+
memory_summary: robot_record(htm).memory_summary
|
|
79
91
|
}.to_json
|
|
80
92
|
end
|
|
81
93
|
end
|
|
82
94
|
|
|
83
95
|
# Tool: Get working memory contents for session restore
|
|
84
|
-
class GetWorkingMemoryTool <
|
|
96
|
+
class GetWorkingMemoryTool < Tool
|
|
97
|
+
read_only!
|
|
85
98
|
description "Get all working memory contents for the current robot. Use this to restore a previous session."
|
|
86
99
|
|
|
87
100
|
arguments do
|
|
88
101
|
end
|
|
89
102
|
|
|
90
103
|
def call
|
|
91
|
-
htm =
|
|
92
|
-
|
|
93
|
-
Session.logger&.info "GetWorkingMemoryTool called for robot=#{htm.robot_name}"
|
|
94
|
-
|
|
95
|
-
# Get all nodes in working memory with their metadata
|
|
96
|
-
# Filter out any robot_nodes where the node has been deleted
|
|
97
|
-
working_memory_nodes = robot.robot_nodes_dataset
|
|
98
|
-
.in_working_memory
|
|
99
|
-
.eager(node: :tags)
|
|
100
|
-
.order(Sequel.desc(:last_remembered_at))
|
|
101
|
-
.all
|
|
102
|
-
.filter_map do |rn|
|
|
103
|
-
node = rn.node
|
|
104
|
-
next unless node # Exclude if node is nil (was deleted)
|
|
104
|
+
htm = session_htm
|
|
105
|
+
log_info "GetWorkingMemoryTool called for robot=#{htm.robot_name}"
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
content: node.content,
|
|
109
|
-
tags: node.tags.map(&:name),
|
|
110
|
-
remember_count: rn.remember_count,
|
|
111
|
-
last_remembered_at: rn.last_remembered_at&.iso8601,
|
|
112
|
-
created_at: node.created_at.iso8601
|
|
113
|
-
}
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
Session.logger&.info "GetWorkingMemoryTool complete: #{working_memory_nodes.length} nodes in working memory"
|
|
107
|
+
nodes = working_memory_entries(robot_record(htm))
|
|
108
|
+
count = nodes.length
|
|
117
109
|
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
robot_id: htm.robot_id,
|
|
121
|
-
robot_name: htm.robot_name,
|
|
122
|
-
count: working_memory_nodes.length,
|
|
123
|
-
working_memory: working_memory_nodes
|
|
124
|
-
}.to_json
|
|
110
|
+
log_info "GetWorkingMemoryTool complete: #{count} nodes in working memory"
|
|
111
|
+
{ success: true, **robot_identity(htm), count:, working_memory: nodes }.to_json
|
|
125
112
|
rescue StandardError => e
|
|
126
|
-
|
|
113
|
+
log_error "GetWorkingMemoryTool error: #{e.message}"
|
|
127
114
|
{ success: false, error: e.message, count: 0, working_memory: [] }.to_json
|
|
128
115
|
end
|
|
129
116
|
end
|
|
130
117
|
|
|
131
118
|
# Tool: Remember information
|
|
132
|
-
class RememberTool <
|
|
133
|
-
description "Store information in HTM long-term memory with optional tags"
|
|
119
|
+
class RememberTool < Tool
|
|
120
|
+
description "Store information in HTM long-term memory with optional tags and metadata. " \
|
|
121
|
+
"Embeddings, tags (and propositions, when enabled) are added in the background."
|
|
134
122
|
|
|
135
123
|
arguments do
|
|
136
124
|
required(:content).filled(:string).description("The content to remember")
|
|
137
125
|
optional(:tags).array(:string).description("Optional tags for categorization (e.g., ['database:postgresql', 'config'])")
|
|
138
126
|
optional(:metadata).hash.description("Optional metadata key-value pairs")
|
|
127
|
+
optional(:occurred_at).filled(:string).description(
|
|
128
|
+
"When it happened (ISO8601 or natural language like 'yesterday'). Default: a time the content " \
|
|
129
|
+
"states ('3 days ago', 'March 3, 2025'), else now"
|
|
130
|
+
)
|
|
131
|
+
optional(:occurred_until).filled(:string).description("When it stopped happening, for an event span")
|
|
132
|
+
optional(:valid_from).filled(:string).description("When the stated state became true (default: occurred_at)")
|
|
133
|
+
optional(:valid_until).filled(:string).description("When the stated state stopped being true")
|
|
134
|
+
optional(:supersedes).array(:integer).description(
|
|
135
|
+
"IDs of memories this one replaces. They are retired (soft-deleted, validity ended) in the same " \
|
|
136
|
+
"transaction and stay in this memory's timeline"
|
|
137
|
+
)
|
|
138
|
+
optional(:reason).filled(:string).description("Why the superseded memories are wrong now")
|
|
139
|
+
optional(:transition).filled(:string).description("Kind of change: 'removed', 'restored' or 'changed'")
|
|
140
|
+
optional(:status).filled(:string).description(
|
|
141
|
+
"How it is known: 'asserted' (default; stated directly), 'extracted' (copied from a source), " \
|
|
142
|
+
"'inferred' (concluded from other memories) or 'hypothesis' (unconfirmed)"
|
|
143
|
+
)
|
|
144
|
+
optional(:confidence).filled(:float).description("Confidence in it, 0.0-1.0 (default: unrated)")
|
|
145
|
+
optional(:evidence).array(:integer).description(
|
|
146
|
+
"IDs of memories it rests on (give them for inferred memories and hypotheses)"
|
|
147
|
+
)
|
|
139
148
|
end
|
|
140
149
|
|
|
141
|
-
def call(content:, tags: [], metadata: {}
|
|
142
|
-
|
|
150
|
+
def call(content:, tags: [], metadata: {}, supersedes: [], status: 'asserted', confidence: nil, evidence: [],
|
|
151
|
+
**event_time)
|
|
152
|
+
log_info "RememberTool called: content=#{content[0..50].inspect}..."
|
|
143
153
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
guarded do
|
|
155
|
+
htm = session_htm
|
|
156
|
+
node_id = htm.remember(content, tags:, metadata:, supersedes:, status:, confidence:, evidence:, **event_time)
|
|
157
|
+
node = HTM::Models::Node.eager(:tags).first!(id: node_id)
|
|
158
|
+
names = tag_names(node)
|
|
147
159
|
|
|
148
|
-
|
|
160
|
+
log_info "Memory stored: node_id=#{node_id}, robot=#{htm.robot_name}, tags=#{names}"
|
|
149
161
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
{
|
|
163
|
+
success: true,
|
|
164
|
+
node_id:,
|
|
165
|
+
**robot_identity(htm),
|
|
166
|
+
content: node.content,
|
|
167
|
+
superseded: supersedes,
|
|
168
|
+
**knowledge(node).except(:conflicts),
|
|
169
|
+
tags: names,
|
|
170
|
+
occurred_at: node.occurred_at&.iso8601,
|
|
171
|
+
time_source: node.time_source,
|
|
172
|
+
created_at: node.created_at.iso8601
|
|
173
|
+
}.to_json
|
|
174
|
+
end
|
|
159
175
|
end
|
|
160
176
|
end
|
|
161
177
|
|
|
162
178
|
# Tool: Recall memories
|
|
163
|
-
class RecallTool <
|
|
164
|
-
|
|
179
|
+
class RecallTool < Tool
|
|
180
|
+
STATUS_FILTER = "Only memories known these ways: any of 'asserted', 'extracted', 'inferred', 'hypothesis' " \
|
|
181
|
+
"(['asserted', 'extracted'] keeps direct evidence only). Each result carries its " \
|
|
182
|
+
'epistemic_status, confidence, evidence and conflicts'
|
|
183
|
+
|
|
184
|
+
read_only!
|
|
185
|
+
description "Search and retrieve memories from HTM using semantic (vector), full-text, or hybrid search, " \
|
|
186
|
+
"optionally filtered by time and metadata. Found memories join the robot's working memory."
|
|
165
187
|
|
|
166
188
|
arguments do
|
|
167
189
|
required(:query).filled(:string).description("Search query - can be natural language or keywords")
|
|
168
190
|
optional(:limit).filled(:integer).description("Maximum number of results (default: 10)")
|
|
169
191
|
optional(:strategy).filled(:string).description("Search strategy: 'vector', 'fulltext', or 'hybrid' (default: 'hybrid')")
|
|
170
|
-
optional(:timeframe).filled(:string).description(
|
|
192
|
+
optional(:timeframe).filled(:string).description(
|
|
193
|
+
"Time filter: natural language ('today', 'yesterday', 'last week', 'few days ago', 'last month'), " \
|
|
194
|
+
"'auto' to extract it from the query, an ISO8601 range 'start..end', or an ISO8601 date (since then)"
|
|
195
|
+
)
|
|
196
|
+
optional(:metadata).hash.description("Only memories whose metadata contains these key-value pairs")
|
|
197
|
+
optional(:time_axis).filled(:string).description(
|
|
198
|
+
"What timeframe filters on: 'event' (default; when the memory happened, any overlap with its span) " \
|
|
199
|
+
"or 'recorded' (when HTM stored it)"
|
|
200
|
+
)
|
|
201
|
+
optional(:as_of).filled(:string).description(
|
|
202
|
+
"Only memories whose state was true at this moment (ISO8601 or natural language)"
|
|
203
|
+
)
|
|
204
|
+
optional(:query_tags).array(:string).description("Tags that boost relevance (used with with_relevance)")
|
|
205
|
+
optional(:with_relevance).filled(:bool).description(
|
|
206
|
+
"Rank by a composite relevance score (semantic, tag, recency, access) and return it (default: false)"
|
|
207
|
+
)
|
|
208
|
+
optional(:include_history).filled(:bool).description(
|
|
209
|
+
"Follow each result with the earlier states it replaced (superseded, merged or archived), each with " \
|
|
210
|
+
"a status and a history_note saying what changed and when (default: false)"
|
|
211
|
+
)
|
|
212
|
+
optional(:status).array(:string).description(STATUS_FILTER)
|
|
213
|
+
optional(:min_confidence).filled(:float).description("Only memories at least this confident, 0.0-1.0 (unrated = 1.0)")
|
|
171
214
|
end
|
|
172
215
|
|
|
173
|
-
def call(query:, limit: 10, strategy: 'hybrid',
|
|
174
|
-
htm
|
|
175
|
-
|
|
216
|
+
def call(query:, limit: 10, strategy: 'hybrid', **)
|
|
217
|
+
htm = session_htm
|
|
218
|
+
robot_name = htm.robot_name
|
|
219
|
+
log_info "RecallTool called: query=#{query.inspect}, strategy=#{strategy}, limit=#{limit}, robot=#{robot_name}"
|
|
176
220
|
|
|
177
|
-
|
|
178
|
-
limit
|
|
179
|
-
strategy: strategy.to_sym,
|
|
180
|
-
raw: true
|
|
181
|
-
}
|
|
221
|
+
guarded do
|
|
222
|
+
results = recall_results(htm, query, "Recall", limit:, strategy:, **)
|
|
182
223
|
|
|
183
|
-
|
|
184
|
-
if timeframe
|
|
185
|
-
recall_opts[:timeframe] = parse_timeframe(timeframe)
|
|
224
|
+
{ success: true, query:, strategy:, robot_name:, count: results.length, results: }.to_json
|
|
186
225
|
end
|
|
187
|
-
|
|
188
|
-
memories = htm.recall(query, **recall_opts)
|
|
189
|
-
|
|
190
|
-
results = memories.map do |memory|
|
|
191
|
-
node = HTM::Models::Node.eager(:tags).first(id: memory['id'])
|
|
192
|
-
next unless node
|
|
193
|
-
{
|
|
194
|
-
id: memory['id'],
|
|
195
|
-
content: memory['content'],
|
|
196
|
-
tags: node.tags.map(&:name),
|
|
197
|
-
created_at: memory['created_at'],
|
|
198
|
-
score: memory['combined_score'] || memory['similarity']
|
|
199
|
-
}
|
|
200
|
-
end.compact
|
|
201
|
-
|
|
202
|
-
Session.logger&.info "Recall complete: found #{results.length} memories"
|
|
203
|
-
|
|
204
|
-
{
|
|
205
|
-
success: true,
|
|
206
|
-
query: query,
|
|
207
|
-
strategy: strategy,
|
|
208
|
-
robot_name: htm.robot_name,
|
|
209
|
-
count: results.length,
|
|
210
|
-
results: results
|
|
211
|
-
}.to_json
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
private
|
|
215
|
-
|
|
216
|
-
def parse_timeframe(timeframe)
|
|
217
|
-
now = Time.now
|
|
218
|
-
case timeframe.downcase
|
|
219
|
-
when 'today'
|
|
220
|
-
# Beginning of today
|
|
221
|
-
Time.new(now.year, now.month, now.day)..now
|
|
222
|
-
when 'this week'
|
|
223
|
-
# 7 days ago
|
|
224
|
-
(now - 7 * 24 * 60 * 60)..now
|
|
225
|
-
when 'this month'
|
|
226
|
-
# 30 days ago
|
|
227
|
-
(now - 30 * 24 * 60 * 60)..now
|
|
228
|
-
else
|
|
229
|
-
# Try to parse as ISO8601 range (start..end)
|
|
230
|
-
if timeframe.include?('..')
|
|
231
|
-
parts = timeframe.split('..')
|
|
232
|
-
Time.parse(parts[0])..Time.parse(parts[1])
|
|
233
|
-
else
|
|
234
|
-
# Single date - from that date to now
|
|
235
|
-
Time.parse(timeframe)..now
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
rescue ArgumentError
|
|
239
|
-
nil # Invalid timeframe, skip filtering
|
|
240
226
|
end
|
|
241
227
|
end
|
|
242
228
|
|
|
243
229
|
# Tool: Forget a memory
|
|
244
|
-
class ForgetTool <
|
|
245
|
-
|
|
230
|
+
class ForgetTool < Tool
|
|
231
|
+
destructive!
|
|
232
|
+
description "Forget a memory. Soft-deletes by default (recoverable with restore); " \
|
|
233
|
+
"permanent: true deletes it for good and requires confirm: 'confirmed'."
|
|
246
234
|
|
|
247
235
|
arguments do
|
|
248
236
|
required(:node_id).filled(:integer).description("The ID of the node to forget")
|
|
237
|
+
optional(:permanent).filled(:bool).description("Delete permanently instead of soft-deleting (default: false)")
|
|
238
|
+
optional(:confirm).filled(:string).description("Must be 'confirmed' when permanent is true")
|
|
249
239
|
end
|
|
250
240
|
|
|
251
|
-
def call(node_id:)
|
|
252
|
-
htm
|
|
253
|
-
|
|
241
|
+
def call(node_id:, permanent: false, confirm: nil)
|
|
242
|
+
htm = session_htm
|
|
243
|
+
robot_name = htm.robot_name
|
|
244
|
+
log_info "ForgetTool called: node_id=#{node_id}, permanent=#{permanent}, robot=#{robot_name}"
|
|
254
245
|
|
|
255
|
-
|
|
246
|
+
guarded do
|
|
247
|
+
htm.forget(node_id, soft: !permanent, confirm: htm_confirmation(confirm))
|
|
256
248
|
|
|
257
|
-
|
|
249
|
+
log_info "Memory #{permanent ? 'permanently deleted' : 'soft-deleted'}: node_id=#{node_id}"
|
|
258
250
|
|
|
259
|
-
|
|
260
|
-
success:
|
|
261
|
-
|
|
262
|
-
robot_name: htm.robot_name,
|
|
263
|
-
message: "Memory soft-deleted. Use restore to recover."
|
|
264
|
-
}.to_json
|
|
265
|
-
rescue HTM::NotFoundError, Sequel::NoMatchingRow
|
|
266
|
-
Session.logger&.warn "ForgetTool failed: node #{node_id} not found"
|
|
267
|
-
{
|
|
268
|
-
success: false,
|
|
269
|
-
error: "Node #{node_id} not found"
|
|
270
|
-
}.to_json
|
|
251
|
+
message = permanent ? "Memory permanently deleted." : "Memory soft-deleted. Use restore to recover."
|
|
252
|
+
{ success: true, node_id:, robot_name:, permanent:, message: }.to_json
|
|
253
|
+
end
|
|
271
254
|
end
|
|
272
255
|
end
|
|
273
256
|
|
|
274
257
|
# Tool: Restore a forgotten memory
|
|
275
|
-
class RestoreTool <
|
|
258
|
+
class RestoreTool < Tool
|
|
276
259
|
description "Restore a soft-deleted memory"
|
|
277
260
|
|
|
278
261
|
arguments do
|
|
@@ -280,30 +263,23 @@ class HTM
|
|
|
280
263
|
end
|
|
281
264
|
|
|
282
265
|
def call(node_id:)
|
|
283
|
-
htm
|
|
284
|
-
|
|
266
|
+
htm = session_htm
|
|
267
|
+
robot_name = htm.robot_name
|
|
268
|
+
log_info "RestoreTool called: node_id=#{node_id}, robot=#{robot_name}"
|
|
285
269
|
|
|
286
|
-
|
|
270
|
+
guarded do
|
|
271
|
+
htm.restore(node_id)
|
|
287
272
|
|
|
288
|
-
|
|
273
|
+
log_info "Memory restored: node_id=#{node_id}"
|
|
289
274
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
node_id: node_id,
|
|
293
|
-
robot_name: htm.robot_name,
|
|
294
|
-
message: "Memory restored successfully"
|
|
295
|
-
}.to_json
|
|
296
|
-
rescue HTM::NotFoundError, Sequel::NoMatchingRow
|
|
297
|
-
Session.logger&.warn "RestoreTool failed: node #{node_id} not found"
|
|
298
|
-
{
|
|
299
|
-
success: false,
|
|
300
|
-
error: "Node #{node_id} not found"
|
|
301
|
-
}.to_json
|
|
275
|
+
{ success: true, node_id:, robot_name:, message: "Memory restored successfully" }.to_json
|
|
276
|
+
end
|
|
302
277
|
end
|
|
303
278
|
end
|
|
304
279
|
|
|
305
280
|
# Tool: List tags
|
|
306
|
-
class ListTagsTool <
|
|
281
|
+
class ListTagsTool < Tool
|
|
282
|
+
read_only!
|
|
307
283
|
description "List all tags in HTM, optionally filtered by prefix"
|
|
308
284
|
|
|
309
285
|
arguments do
|
|
@@ -311,31 +287,28 @@ class HTM
|
|
|
311
287
|
end
|
|
312
288
|
|
|
313
289
|
def call(prefix: nil)
|
|
314
|
-
|
|
290
|
+
log_info "ListTagsTool called: prefix=#{prefix.inspect}"
|
|
315
291
|
|
|
316
|
-
|
|
317
|
-
|
|
292
|
+
tags = tags_dataset(prefix).map { { name: it.name, node_count: it.nodes.count } }
|
|
293
|
+
count = tags.length
|
|
318
294
|
|
|
319
|
-
|
|
320
|
-
{
|
|
321
|
-
name: tag.name,
|
|
322
|
-
node_count: tag.nodes.count
|
|
323
|
-
}
|
|
324
|
-
end
|
|
295
|
+
log_info "ListTagsTool complete: found #{count} tags"
|
|
325
296
|
|
|
326
|
-
|
|
297
|
+
{ success: true, prefix:, count:, tags: }.to_json
|
|
298
|
+
end
|
|
327
299
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
300
|
+
private
|
|
301
|
+
|
|
302
|
+
# All tags ordered by name, narrowed to a prefix when one is given
|
|
303
|
+
def tags_dataset(prefix)
|
|
304
|
+
dataset = HTM::Models::Tag.order(:name)
|
|
305
|
+
prefix ? dataset.with_prefix(prefix) : dataset
|
|
334
306
|
end
|
|
335
307
|
end
|
|
336
308
|
|
|
337
309
|
# Tool: Search tags with fuzzy matching
|
|
338
|
-
class SearchTagsTool <
|
|
310
|
+
class SearchTagsTool < Tool
|
|
311
|
+
read_only!
|
|
339
312
|
description "Search for tags using fuzzy matching (typo-tolerant). Use this when you're unsure of exact tag names."
|
|
340
313
|
|
|
341
314
|
arguments do
|
|
@@ -345,37 +318,34 @@ class HTM
|
|
|
345
318
|
end
|
|
346
319
|
|
|
347
320
|
def call(query:, limit: 20, min_similarity: 0.3)
|
|
348
|
-
|
|
321
|
+
log_info "SearchTagsTool called: query=#{query.inspect}, limit=#{limit}, min_similarity=#{min_similarity}"
|
|
349
322
|
|
|
350
|
-
|
|
351
|
-
|
|
323
|
+
results = session_htm.long_term_memory.search_tags(query, limit:, min_similarity:)
|
|
324
|
+
tags = results.map { tag_match(it) }
|
|
325
|
+
count = tags.length
|
|
352
326
|
|
|
353
|
-
|
|
327
|
+
log_info "SearchTagsTool complete: found #{count} tags"
|
|
354
328
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
tag = HTM::Models::Tag.first(name: result[:name])
|
|
358
|
-
{
|
|
359
|
-
name: result[:name],
|
|
360
|
-
similarity: result[:similarity].round(3),
|
|
361
|
-
node_count: tag&.nodes&.count || 0
|
|
362
|
-
}
|
|
363
|
-
end
|
|
329
|
+
{ success: true, query:, min_similarity:, count:, tags: }.to_json
|
|
330
|
+
end
|
|
364
331
|
|
|
365
|
-
|
|
332
|
+
private
|
|
366
333
|
|
|
334
|
+
# A search_tags row enriched with the tag's node count
|
|
335
|
+
def tag_match(result)
|
|
336
|
+
name = result[:name]
|
|
337
|
+
tag = HTM::Models::Tag.first(name:)
|
|
367
338
|
{
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
tags: tags
|
|
373
|
-
}.to_json
|
|
339
|
+
name:,
|
|
340
|
+
similarity: result[:similarity].round(3),
|
|
341
|
+
node_count: tag&.nodes&.count || 0
|
|
342
|
+
}
|
|
374
343
|
end
|
|
375
344
|
end
|
|
376
345
|
|
|
377
346
|
# Tool: Find nodes by topic with fuzzy option
|
|
378
|
-
class FindByTopicTool <
|
|
347
|
+
class FindByTopicTool < Tool
|
|
348
|
+
read_only!
|
|
379
349
|
description "Find memory nodes by topic/tag with optional fuzzy matching for typo tolerance"
|
|
380
350
|
|
|
381
351
|
arguments do
|
|
@@ -386,96 +356,69 @@ class HTM
|
|
|
386
356
|
optional(:min_similarity).filled(:float).description("Minimum similarity for fuzzy mode (default: 0.3)")
|
|
387
357
|
end
|
|
388
358
|
|
|
389
|
-
|
|
390
|
-
|
|
359
|
+
# fuzzy and exact are optional flags; an omitted flag means false
|
|
360
|
+
def call(topic:, fuzzy: nil, exact: nil, limit: 20, min_similarity: 0.3)
|
|
361
|
+
flags = { fuzzy: fuzzy == true, exact: exact == true }
|
|
362
|
+
log_info "FindByTopicTool called: topic=#{topic.inspect}, fuzzy=#{flags[:fuzzy]}, exact=#{flags[:exact]}"
|
|
391
363
|
|
|
392
|
-
|
|
393
|
-
|
|
364
|
+
nodes = session_htm.long_term_memory.nodes_by_topic(topic, **flags, min_similarity:, limit:)
|
|
365
|
+
results = nodes.filter_map { topic_result(it) }
|
|
366
|
+
count = results.length
|
|
394
367
|
|
|
395
|
-
|
|
396
|
-
topic,
|
|
397
|
-
fuzzy: fuzzy,
|
|
398
|
-
exact: exact,
|
|
399
|
-
min_similarity: min_similarity,
|
|
400
|
-
limit: limit
|
|
401
|
-
)
|
|
402
|
-
|
|
403
|
-
# Enrich with tags
|
|
404
|
-
results = nodes.map do |node_attrs|
|
|
405
|
-
node = HTM::Models::Node.eager(:tags).first(id: node_attrs['id'])
|
|
406
|
-
next unless node
|
|
368
|
+
log_info "FindByTopicTool complete: found #{count} nodes"
|
|
407
369
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
content: node.content[0..200],
|
|
411
|
-
tags: node.tags.map(&:name),
|
|
412
|
-
created_at: node.created_at.iso8601
|
|
413
|
-
}
|
|
414
|
-
end.compact
|
|
370
|
+
{ success: true, topic:, **flags, count:, results: }.to_json
|
|
371
|
+
end
|
|
415
372
|
|
|
416
|
-
|
|
373
|
+
private
|
|
417
374
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
exact: exact,
|
|
423
|
-
count: results.length,
|
|
424
|
-
results: results
|
|
425
|
-
}.to_json
|
|
375
|
+
# A nodes_by_topic row as a truncated node summary, or nil when the node is gone
|
|
376
|
+
def topic_result(node_attrs)
|
|
377
|
+
node = node_with_tags(node_attrs['id'])
|
|
378
|
+
node && node_summary(node, content_limit: 200)
|
|
426
379
|
end
|
|
427
380
|
end
|
|
428
381
|
|
|
429
382
|
# Tool: Get memory statistics
|
|
430
|
-
class StatsTool <
|
|
431
|
-
|
|
383
|
+
class StatsTool < Tool
|
|
384
|
+
read_only!
|
|
385
|
+
description "Get statistics about HTM memory: nodes, enrichment coverage (embeddings, tags, propositions), " \
|
|
386
|
+
"tags, robots, loaded files, relationships, and this session's working memory"
|
|
432
387
|
|
|
433
388
|
arguments do
|
|
434
389
|
end
|
|
435
390
|
|
|
436
391
|
def call
|
|
437
|
-
htm =
|
|
438
|
-
|
|
439
|
-
Session.logger&.info "StatsTool called for robot=#{htm.robot_name}"
|
|
440
|
-
|
|
441
|
-
# Note: Node uses set_dataset to exclude deleted, so .count returns active nodes
|
|
442
|
-
total_nodes = HTM::Models::Node.count
|
|
443
|
-
deleted_nodes = HTM::Models::Node.deleted.count
|
|
444
|
-
nodes_with_embeddings = HTM::Models::Node.with_embeddings.count
|
|
445
|
-
nodes_with_tags = HTM::Models::Node
|
|
446
|
-
.join(:node_tags, node_id: :id)
|
|
447
|
-
.distinct
|
|
448
|
-
.count
|
|
449
|
-
total_tags = HTM::Models::Tag.count
|
|
450
|
-
total_robots = HTM::Models::Robot.count
|
|
451
|
-
|
|
452
|
-
Session.logger&.info "StatsTool complete: #{total_nodes} active nodes, #{total_tags} tags"
|
|
392
|
+
htm = session_htm
|
|
393
|
+
log_info "StatsTool called for robot=#{htm.robot_name}"
|
|
453
394
|
|
|
395
|
+
robot = current_robot(htm)
|
|
396
|
+
statistics = memory_statistics
|
|
397
|
+
|
|
398
|
+
log_info "StatsTool complete: #{statistics.dig(:nodes, :active)} active nodes, #{statistics.dig(:tags, :total)} tags"
|
|
399
|
+
|
|
400
|
+
{ success: true, current_robot: robot, statistics: }.to_json
|
|
401
|
+
rescue StandardError => e
|
|
402
|
+
log_error "StatsTool error: #{e.message}"
|
|
403
|
+
failure(e.message)
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
private
|
|
407
|
+
|
|
408
|
+
def current_robot(htm)
|
|
409
|
+
id = htm.robot_id
|
|
410
|
+
working_memory = htm.working_memory
|
|
454
411
|
{
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
active: total_nodes,
|
|
464
|
-
deleted: deleted_nodes,
|
|
465
|
-
with_embeddings: nodes_with_embeddings,
|
|
466
|
-
with_tags: nodes_with_tags
|
|
467
|
-
},
|
|
468
|
-
tags: {
|
|
469
|
-
total: total_tags
|
|
470
|
-
},
|
|
471
|
-
robots: {
|
|
472
|
-
total: total_robots
|
|
473
|
-
}
|
|
412
|
+
name: htm.robot_name,
|
|
413
|
+
id:,
|
|
414
|
+
memory_summary: HTM::Models::Robot[id].memory_summary,
|
|
415
|
+
working_memory: {
|
|
416
|
+
nodes: working_memory.node_count,
|
|
417
|
+
tokens: working_memory.token_count,
|
|
418
|
+
max_tokens: working_memory.max_tokens,
|
|
419
|
+
utilization: working_memory.utilization_percentage
|
|
474
420
|
}
|
|
475
|
-
}
|
|
476
|
-
rescue StandardError => e
|
|
477
|
-
Session.logger&.error "StatsTool error: #{e.message}"
|
|
478
|
-
{ success: false, error: e.message }.to_json
|
|
421
|
+
}
|
|
479
422
|
end
|
|
480
423
|
end
|
|
481
424
|
|