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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class HTM
|
|
4
|
+
module Admin
|
|
5
|
+
module MemoryCommands
|
|
6
|
+
# Commands that search by tag: list and fuzzy-search tags, the most
|
|
7
|
+
# used tags and tags used together, and the memories carrying tags
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# HTM::Admin::MemoryCommands::TagSearch.new.tagged(%w[database:postgresql], match: "all")
|
|
11
|
+
#
|
|
12
|
+
class TagSearch < Base
|
|
13
|
+
MATCHES = %w[any all].freeze
|
|
14
|
+
|
|
15
|
+
# Every tag (or those under +prefix+) with how many memories carry it
|
|
16
|
+
#
|
|
17
|
+
# @return [Hash] { prefix:, count:, tags: }
|
|
18
|
+
#
|
|
19
|
+
def list(prefix = nil)
|
|
20
|
+
Admin.connect!
|
|
21
|
+
tags = TagCommands.scope(prefix).order(:name).all
|
|
22
|
+
counts = HTM::Models::NodeTag.where(tag_id: tags.map(&:id)).group_and_count(:tag_id).to_hash(:tag_id, :count)
|
|
23
|
+
entries = tags.map { { name: it.name, node_count: counts.fetch(it.id, 0) } }
|
|
24
|
+
report({ prefix:, count: entries.length, tags: entries }) { print_counted(entries, :node_count) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Tags whose names resemble +query+ (typo-tolerant trigram match)
|
|
28
|
+
#
|
|
29
|
+
# @return [Hash] { query:, count:, tags: }
|
|
30
|
+
#
|
|
31
|
+
def search(query, limit: 20, min_similarity: 0.3)
|
|
32
|
+
rows = long_term_memory.search_tags(query, limit:, min_similarity:)
|
|
33
|
+
tags = rows.map { { name: it[:name], similarity: it[:similarity].to_f.round(3) } }
|
|
34
|
+
report({ query:, count: tags.length, tags: }) { print_counted(tags, :similarity) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The most used tags, optionally counting only memories from +timeframe+
|
|
38
|
+
#
|
|
39
|
+
# @return [Hash] { timeframe:, count:, tags: }
|
|
40
|
+
#
|
|
41
|
+
def popular(limit: 20, timeframe: nil)
|
|
42
|
+
tags = long_term_memory.popular_tags(limit:, timeframe: NodeView.timeframe_span(timeframe))
|
|
43
|
+
report({ timeframe:, count: tags.length, tags: }) { print_counted(tags, :usage_count) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Pairs of tags used together on the same memories, most shared first
|
|
47
|
+
#
|
|
48
|
+
# @return [Hash] { count:, relationships: }
|
|
49
|
+
#
|
|
50
|
+
def pairs(min_shared_nodes: 2, limit: 50)
|
|
51
|
+
rows = long_term_memory.topic_relationships(min_shared_nodes:, limit:)
|
|
52
|
+
pairs = rows.map { { topic1: it['topic1'], topic2: it['topic2'], shared_nodes: it['shared_nodes'].to_i } }
|
|
53
|
+
report({ count: pairs.length, relationships: pairs }) do
|
|
54
|
+
out.puts 'No tags share enough memories.' if pairs.empty?
|
|
55
|
+
pairs.each { out.puts format('%<shared>6d %<topic1>s + %<topic2>s', shared: it[:shared_nodes], **it) }
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Memories carrying any (or all) of +tags+, ranked by relevance
|
|
60
|
+
#
|
|
61
|
+
# @return [Hash] { tags:, match:, count:, results: }
|
|
62
|
+
# @raise [ArgumentError] for an unknown match
|
|
63
|
+
#
|
|
64
|
+
def tagged(tags, match: 'any', limit: 20, timeframe: nil)
|
|
65
|
+
raise ArgumentError, "match must be one of: #{MATCHES.join(', ')}" unless MATCHES.include?(match)
|
|
66
|
+
|
|
67
|
+
rows = long_term_memory.search_by_tags(tags:, match: match.to_sym, limit:,
|
|
68
|
+
filters: SearchFilters.build(timeframe: NodeView.normalized_timeframe(timeframe)))
|
|
69
|
+
results = NodeView.recall_entries(rows)
|
|
70
|
+
report({ tags:, match:, count: results.length, results: }) { print_entries(results, 'No memories carry those tags.') }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Memories under a topic: tags starting with +topic+, exactly +topic+,
|
|
74
|
+
# or (fuzzy) tags resembling it
|
|
75
|
+
#
|
|
76
|
+
# @param mode [Hash] exact: or fuzzy:
|
|
77
|
+
# @return [Hash] { topic:, count:, results: }
|
|
78
|
+
#
|
|
79
|
+
def topic(topic, limit: 20, min_similarity: 0.3, **mode)
|
|
80
|
+
rows = long_term_memory.nodes_by_topic(topic, **mode, min_similarity:, limit:)
|
|
81
|
+
ids = rows.map { it[:id] || it['id'] }
|
|
82
|
+
nodes = HTM::Models::Node.where(id: ids).eager(:tags).all.to_h { [it.id, it] }
|
|
83
|
+
results = ids.filter_map { nodes[it] }.map { NodeView.node_summary(it) }
|
|
84
|
+
report({ topic:, count: results.length, results: }) { print_entries(results, "No memories under #{topic}.") }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
# One "value name" line per entry
|
|
90
|
+
def print_counted(entries, key)
|
|
91
|
+
return out.puts('No tags.') if entries.empty?
|
|
92
|
+
|
|
93
|
+
entries.each { out.puts format('%<value>8s %<name>s', value: it[key], name: it[:name]) }
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class HTM
|
|
4
|
+
module Admin
|
|
5
|
+
module MemoryCommands
|
|
6
|
+
# The lines the memory commands print: each function turns a result
|
|
7
|
+
# hash (as NodeView builds it) into text, so the Console classes only
|
|
8
|
+
# decide what to print and where.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# HTM::Admin::MemoryCommands::Text.entry_lines({ tags: ["db"], evidence: [3] })
|
|
12
|
+
# # => [" tags: db", " from: #3"]
|
|
13
|
+
#
|
|
14
|
+
module Text
|
|
15
|
+
# The verb and closing hint of a forget report, by whether it was permanent
|
|
16
|
+
FORGOT = { true => ['Permanently deleted', ''], false => ['Forgot', ' (restore with: htm restore ID)'] }.freeze
|
|
17
|
+
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
# @return [String, nil] "#12, #15", or nil when there are no ids
|
|
21
|
+
def ids(ids) = (MemoryCommands.id_list(ids) if ids&.any?)
|
|
22
|
+
|
|
23
|
+
# @return [String, nil] "label: #12, #15", or nil when there are no ids
|
|
24
|
+
def id_line(label, ids)
|
|
25
|
+
list = ids(ids)
|
|
26
|
+
"#{label}: #{list}" if list
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# How the memory in +entry+ is known (see MemoryCommands.knowledge)
|
|
30
|
+
def knowledge(entry) = MemoryCommands.knowledge(*entry.values_at(:epistemic_status, :confidence))
|
|
31
|
+
|
|
32
|
+
# The lines under a node's heading: its tags, history note, evidence and conflicts
|
|
33
|
+
#
|
|
34
|
+
# @param entry [Hash] a node or result entry
|
|
35
|
+
# @return [Array<String>]
|
|
36
|
+
#
|
|
37
|
+
def entry_lines(entry)
|
|
38
|
+
tags, note, evidence, conflicts = entry.values_at(:tags, :history_note, :evidence, :conflicts)
|
|
39
|
+
[(" tags: #{tags.join(', ')}" if tags&.any?), (" #{note}" if note),
|
|
40
|
+
id_line(' from', evidence), id_line(' conflicts with', conflicts)].compact
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The lines after "Remembered node N": what it replaced, how it is known, when it happened
|
|
44
|
+
#
|
|
45
|
+
# @param entry [Hash] Edit#remember's result
|
|
46
|
+
# @return [Array<String>]
|
|
47
|
+
#
|
|
48
|
+
def remembered_lines(entry)
|
|
49
|
+
superseded, status, confidence, evidence, occurred, created, tags =
|
|
50
|
+
entry.values_at(:superseded, :epistemic_status, :confidence, :evidence, :occurred_at, :created_at, :tags)
|
|
51
|
+
[id_line(' supersedes', superseded),
|
|
52
|
+
(" known: #{MemoryCommands.knowledge(status, confidence)}" if status != 'asserted' || confidence),
|
|
53
|
+
id_line(' from', evidence),
|
|
54
|
+
(" occurred: #{MemoryCommands.short_time(occurred)}" if occurred != created),
|
|
55
|
+
(" tags: #{tags.join(', ')}" if tags&.any?)].compact
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# "Forgot 2 nodes: 4, 5 (restore with: htm restore ID)"
|
|
59
|
+
#
|
|
60
|
+
# @param result [Hash] { node_ids:, permanent: }
|
|
61
|
+
# @return [String]
|
|
62
|
+
#
|
|
63
|
+
def forgot(result)
|
|
64
|
+
node_ids, permanent = result.values_at(:node_ids, :permanent)
|
|
65
|
+
verb, hint = FORGOT.fetch(permanent)
|
|
66
|
+
return "#{verb} 0 nodes." if node_ids.empty?
|
|
67
|
+
|
|
68
|
+
"#{verb} #{MemoryCommands.plural(node_ids.size, 'node')}: #{node_ids.join(', ')}#{hint}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# A first-mention answer (NodeView.first_mention_view) as lines
|
|
72
|
+
#
|
|
73
|
+
# @return [Array<String>]
|
|
74
|
+
#
|
|
75
|
+
def first_mention_lines(answer)
|
|
76
|
+
matches, topic, established, direct, earlier, known =
|
|
77
|
+
answer.values_at(:matches, :topic, :established, :earliest_direct, :earlier_indirect, :earliest_known)
|
|
78
|
+
head = "#{matches} #{matches == 1 ? 'memory' : 'memories'} for #{topic.inspect}"
|
|
79
|
+
return [head, 'Nothing in memory mentions it.'] if matches.zero?
|
|
80
|
+
|
|
81
|
+
[head, established ? 'First mention established:' : 'First mention NOT established.',
|
|
82
|
+
direct ? " earliest direct: #{mention_line(direct)}" : ' no direct evidence',
|
|
83
|
+
*earlier.map { " earlier indirect: #{mention_line(it)}" },
|
|
84
|
+
(" earliest known: #{MemoryCommands.short_time(known)}" unless established)].compact
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# "2026-03-01 09:00 [12] stated content"
|
|
88
|
+
def mention_line(entry)
|
|
89
|
+
at = MemoryCommands.short_time(entry[:at])
|
|
90
|
+
at = "~#{at}" if entry[:time_source] == 'inferred'
|
|
91
|
+
evidence = ids(entry[:evidence])
|
|
92
|
+
from = evidence ? " (from #{evidence})" : ''
|
|
93
|
+
"#{at} [#{entry[:node_id]}] #{knowledge(entry)}#{from} #{MemoryCommands.preview(entry[:content])}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# "2026-03-01 09:00 [10] superseded content" or
|
|
97
|
+
# "2026-06-01 09:00 -> #12 supersedes #10 (changed): reason"
|
|
98
|
+
def timeline_line(entry)
|
|
99
|
+
at = MemoryCommands.short_time(entry[:at])
|
|
100
|
+
return "#{at} #{state_line(entry)}" if entry[:type] == 'state'
|
|
101
|
+
|
|
102
|
+
transition, reason = entry.values_at(:transition, :reason)
|
|
103
|
+
"#{at} -> #{link_phrase(entry)}#{" (#{transition})" if transition}#{": #{reason}" if reason}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# "[10] superseded stated content"
|
|
107
|
+
def state_line(entry)
|
|
108
|
+
"[#{entry[:node_id]}] #{entry[:status].ljust(10)} #{knowledge(entry)} " \
|
|
109
|
+
"#{MemoryCommands.preview(entry[:content])}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# "#12 supersedes #10", "#10 merged into #12", "#10 archived into digest #12"
|
|
113
|
+
def link_phrase(entry)
|
|
114
|
+
newer, older = entry.values_at(:node_id, :replaces)
|
|
115
|
+
case entry[:kind]
|
|
116
|
+
when 'supersedes' then "##{newer} supersedes ##{older}"
|
|
117
|
+
when 'merged_into' then "##{older} merged into ##{newer}"
|
|
118
|
+
else "##{older} archived into digest ##{newer}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# "#12 supersedes #10 (changed: moved); ..."
|
|
123
|
+
def link_lines(links)
|
|
124
|
+
links.map do |link|
|
|
125
|
+
extra = [link[:transition], link[:reason]].compact.join(': ')
|
|
126
|
+
"##{link[:from]} #{link[:kind]} ##{link[:to]}#{" (#{extra})" unless extra.empty?}"
|
|
127
|
+
end.join('; ')
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# A node's details (Search#show) as "label" => value pairs, blanks left out
|
|
131
|
+
#
|
|
132
|
+
# @return [Hash{String => Object}]
|
|
133
|
+
#
|
|
134
|
+
def detail_pairs(detail)
|
|
135
|
+
dimension, file, links = detail.values_at(:embedding_dimension, :source_file, :links)
|
|
136
|
+
{
|
|
137
|
+
'Occurred' => span(*detail.values_at(:occurred_at, :occurred_until)),
|
|
138
|
+
'Valid' => validity(detail), 'Time source' => detail[:time_source],
|
|
139
|
+
'Created' => detail[:created_at], 'Updated' => detail[:updated_at],
|
|
140
|
+
'Last accessed' => detail[:last_accessed], 'Access count' => detail[:access_count],
|
|
141
|
+
'Tokens' => detail[:token_count], 'Embedding' => dimension ? "#{dimension} dimensions" : 'none',
|
|
142
|
+
'Proposition' => detail[:proposition] ? 'yes' : 'no',
|
|
143
|
+
'Source' => file && "#{file} (chunk #{detail[:chunk_position]})",
|
|
144
|
+
'Deleted' => detail[:deleted_at], 'Status' => detail[:status], 'Known' => knowledge(detail),
|
|
145
|
+
'Evidence' => ids(detail[:evidence]), 'Conflicts' => ids(detail[:conflicts]),
|
|
146
|
+
'Links' => (link_lines(links) if links&.any?), 'Tags' => detail[:tags].join(', '),
|
|
147
|
+
'Metadata' => detail[:metadata].to_json
|
|
148
|
+
}.compact
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# "[12] proposition" for a stored proposition, "- proposition" otherwise
|
|
152
|
+
def proposition_line(proposition, node_id) = "#{node_id ? "[#{node_id}] " : '- '}#{proposition}"
|
|
153
|
+
|
|
154
|
+
def span(from, to) = to ? "#{from} .. #{to}" : from
|
|
155
|
+
|
|
156
|
+
# "from .. until" when the node states a validity window, else nil
|
|
157
|
+
def validity(detail)
|
|
158
|
+
from, to = detail.values_at(:valid_from, :valid_until)
|
|
159
|
+
"#{from || 'occurred_at'} .. #{to || 'now'}" if from || to
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class HTM
|
|
4
|
+
module Admin
|
|
5
|
+
module MemoryCommands
|
|
6
|
+
# Commands on a robot's working memory: list it, assemble it into an
|
|
7
|
+
# LLM context, clear it. The memory is reloaded from the database, so
|
|
8
|
+
# it is the context the robot built up in earlier runs.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# HTM::Admin::MemoryCommands::WorkingMemory.new(robot: "coder").context(strategy: "recent")
|
|
12
|
+
#
|
|
13
|
+
class WorkingMemory < Base
|
|
14
|
+
STRATEGIES = %w[recent frequent balanced].freeze
|
|
15
|
+
|
|
16
|
+
# The robot's working memory entries, most recently remembered first
|
|
17
|
+
#
|
|
18
|
+
# @return [Hash] { robot_name:, count:, working_memory: }
|
|
19
|
+
#
|
|
20
|
+
def list
|
|
21
|
+
robot_id = memory.robot_id
|
|
22
|
+
entries = NodeView.working_memory_entries(HTM::Models::Robot[robot_id])
|
|
23
|
+
count = entries.length
|
|
24
|
+
name = memory.robot_name
|
|
25
|
+
report({ robot_name: name, count:, working_memory: entries }) do
|
|
26
|
+
out.puts "Working memory of #{name}: #{MemoryCommands.plural(count, 'node')}"
|
|
27
|
+
print_entries(entries, '')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The working memory as one context string for an LLM prompt; text
|
|
32
|
+
# output is the context alone, ready to pipe
|
|
33
|
+
#
|
|
34
|
+
# @param strategy [String] recent, frequent or balanced
|
|
35
|
+
# @param max_tokens [Integer, nil] token budget (the working memory size when nil)
|
|
36
|
+
# @return [Hash] { robot_name:, strategy:, node_count:, token_count:, context: }
|
|
37
|
+
# @raise [ArgumentError] for an unknown strategy
|
|
38
|
+
#
|
|
39
|
+
def context(strategy: 'balanced', max_tokens: nil)
|
|
40
|
+
raise ArgumentError, "strategy must be one of: #{STRATEGIES.join(', ')}" unless STRATEGIES.include?(strategy)
|
|
41
|
+
|
|
42
|
+
working_memory = restored
|
|
43
|
+
text = working_memory.assemble_context(**{ strategy: strategy.to_sym, max_tokens: }.compact)
|
|
44
|
+
data = { robot_name: memory.robot_name, strategy:, node_count: working_memory.node_count,
|
|
45
|
+
token_count: HTM.count_tokens(text), context: text }
|
|
46
|
+
report(data) { out.puts text }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Clear the robot's working memory; the memories stay in long-term memory
|
|
50
|
+
#
|
|
51
|
+
# @return [Hash] { robot_name:, cleared: }
|
|
52
|
+
#
|
|
53
|
+
def clear
|
|
54
|
+
cleared = memory.clear_working_memory
|
|
55
|
+
name = memory.robot_name
|
|
56
|
+
report({ robot_name: name, cleared: }) do
|
|
57
|
+
out.puts "Cleared #{MemoryCommands.plural(cleared, 'node')} from #{name}'s working memory."
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def restored
|
|
64
|
+
working_memory = memory.working_memory
|
|
65
|
+
working_memory.restore(memory.robot_id)
|
|
66
|
+
working_memory
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'logger'
|
|
5
|
+
require_relative '../node_view'
|
|
6
|
+
|
|
7
|
+
class HTM
|
|
8
|
+
module Admin
|
|
9
|
+
# The commands that work on memory itself from the command line: recall,
|
|
10
|
+
# remember, show, forget, restore, tag, the working memory and tag
|
|
11
|
+
# searches (htm recall, htm remember, htm wm ..., htm tags search, ...).
|
|
12
|
+
#
|
|
13
|
+
# The module functions parse command-line input; the Console classes
|
|
14
|
+
# under it run the commands against a terminal and a robot's memory and
|
|
15
|
+
# print text, or JSON with json: true.
|
|
16
|
+
module MemoryCommands
|
|
17
|
+
# The robot the command line remembers and recalls as, unless --robot
|
|
18
|
+
# or HTM_ROBOT_NAME names another
|
|
19
|
+
DEFAULT_ROBOT = 'htm_cli'
|
|
20
|
+
|
|
21
|
+
# Characters of content a result shows unless --full
|
|
22
|
+
PREVIEW_LENGTH = 300
|
|
23
|
+
|
|
24
|
+
module_function
|
|
25
|
+
|
|
26
|
+
# @return [String] +name+, else HTM_ROBOT_NAME, else DEFAULT_ROBOT
|
|
27
|
+
def robot_name(name = nil) = [name, ENV.fetch('HTM_ROBOT_NAME', nil), DEFAULT_ROBOT].compact.first
|
|
28
|
+
|
|
29
|
+
# Send HTM's and RubyLLM's logging to $stderr so it never mixes with
|
|
30
|
+
# a command's output: warnings only unless +level+ says otherwise
|
|
31
|
+
def log_to_stderr!(level = Logger::WARN)
|
|
32
|
+
logger = Logger.new($stderr, level:)
|
|
33
|
+
logger.formatter = proc { |severity, _time, _progname, msg| "#{severity}: #{msg}\n" }
|
|
34
|
+
HTM.configure { it.logger = logger }
|
|
35
|
+
RubyLLM.config.logger = logger if defined?(RubyLLM)
|
|
36
|
+
logger
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Metadata from --metadata key:value pairs. A value that reads as JSON
|
|
40
|
+
# (2, true, null, "x", [1]) becomes that value, so it matches the type
|
|
41
|
+
# stored in the node; anything else stays a string.
|
|
42
|
+
#
|
|
43
|
+
# @param pairs [Hash{String => String}, nil]
|
|
44
|
+
# @return [Hash{String => Object}]
|
|
45
|
+
#
|
|
46
|
+
def parse_metadata(pairs) = pairs.to_h.transform_values { json_value(it) }
|
|
47
|
+
|
|
48
|
+
def json_value(text)
|
|
49
|
+
JSON.parse(text)
|
|
50
|
+
rescue JSON::ParserError
|
|
51
|
+
text
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# The text a command works on: its words joined by spaces, or +input+
|
|
55
|
+
# (stdin) when there are none or the only one is "-"
|
|
56
|
+
#
|
|
57
|
+
# @raise [HTM::Admin::Error] when there is no text
|
|
58
|
+
#
|
|
59
|
+
def read_text(words, input: $stdin)
|
|
60
|
+
text = words.empty? || words == ['-'] ? read_input(input) : words.join(' ')
|
|
61
|
+
text = text.to_s.strip
|
|
62
|
+
raise Admin::Error, 'Error: no text given (pass it as arguments or on stdin)' if text.empty?
|
|
63
|
+
|
|
64
|
+
text
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def read_input(input) = input.tty? ? nil : input.read
|
|
68
|
+
|
|
69
|
+
# @return [Time] the purge cutoff: +before+ (ISO8601) when given, else +days+ ago
|
|
70
|
+
# @raise [ArgumentError] for an unparseable +before+
|
|
71
|
+
def cutoff(days:, before: nil) = before ? Time.parse(before) : Time.now - (days.to_i * 86_400)
|
|
72
|
+
|
|
73
|
+
# @return [String] +content+ on one line, cut to +length+ characters
|
|
74
|
+
def preview(content, length = PREVIEW_LENGTH)
|
|
75
|
+
text = content.to_s.gsub(/\s+/, ' ').strip
|
|
76
|
+
text.length > length ? "#{text[0, length]}..." : text
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# @return [String] "3 nodes", "1 node"
|
|
80
|
+
def plural(count, noun) = "#{count} #{noun}#{'s' unless count == 1}"
|
|
81
|
+
|
|
82
|
+
# @return [String] an ISO8601 time as "YYYY-MM-DD HH:MM", or "-"
|
|
83
|
+
def short_time(iso) = iso ? iso.to_s[0, 16].tr('T', ' ') : '-'
|
|
84
|
+
|
|
85
|
+
# "#12, #15"
|
|
86
|
+
def id_list(ids) = Array(ids).map { "##{it}" }.join(', ')
|
|
87
|
+
|
|
88
|
+
# How a memory is known, as printed: "stated", "inferred 0.60"; nil without a status
|
|
89
|
+
def knowledge(status, confidence)
|
|
90
|
+
return unless status
|
|
91
|
+
|
|
92
|
+
name = status.to_s
|
|
93
|
+
word = HTM::Epistemics::WORDS.fetch(name, name)
|
|
94
|
+
confidence ? Kernel.format('%<word>s %<confidence>.2f', word:, confidence:) : word
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# The memory commands' shared terminal: the robot's HTM, JSON or text
|
|
98
|
+
# output, and how a node or result is printed
|
|
99
|
+
class Base < Admin::Console
|
|
100
|
+
# @param robot [String, nil] robot name (see MemoryCommands.robot_name)
|
|
101
|
+
# @param json [Boolean, nil] print JSON instead of text
|
|
102
|
+
# @param full [Boolean, nil] print whole contents instead of previews
|
|
103
|
+
# @param memory [HTM, nil] the memory to use (a test's); built from +robot+ when nil
|
|
104
|
+
#
|
|
105
|
+
def initialize(robot: nil, json: nil, full: nil, memory: nil, **)
|
|
106
|
+
super(**)
|
|
107
|
+
@robot = robot
|
|
108
|
+
@json = json
|
|
109
|
+
@full = full
|
|
110
|
+
@memory = memory
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
# Confirmation prompts go to $stderr under --json so stdout stays JSON
|
|
116
|
+
def prompt_out = @json ? $stderr : out
|
|
117
|
+
|
|
118
|
+
def cancelled = Admin.cancelled(prompt_out)
|
|
119
|
+
|
|
120
|
+
# @return [HTM] the robot's memory
|
|
121
|
+
def memory
|
|
122
|
+
@memory ||= begin
|
|
123
|
+
Admin.connect!
|
|
124
|
+
HTM.new(robot_name: MemoryCommands.robot_name(@robot))
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def long_term_memory = memory.long_term_memory
|
|
129
|
+
|
|
130
|
+
# Print +data+ as JSON, or run the block to print it as text
|
|
131
|
+
#
|
|
132
|
+
# @return [Hash] +data+
|
|
133
|
+
#
|
|
134
|
+
def report(data)
|
|
135
|
+
@json ? out.puts(JSON.pretty_generate(data)) : yield
|
|
136
|
+
data
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Print each entry, or +empty+ when there are none
|
|
140
|
+
def print_entries(entries, empty)
|
|
141
|
+
return out.puts(empty) if entries.empty?
|
|
142
|
+
|
|
143
|
+
entries.each { print_entry(it) }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# One node or result: a heading line, its tags and its content
|
|
147
|
+
def print_entry(entry)
|
|
148
|
+
out.puts
|
|
149
|
+
out.puts entry_heading(entry), Text.entry_lines(entry), content_lines(entry[:content])
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def entry_heading(entry)
|
|
153
|
+
scores = entry.slice(:score, :relevance, :weight, :remember_count).compact.map { |key, value| "#{key} #{value}" }
|
|
154
|
+
knowledge = Text.knowledge(entry)
|
|
155
|
+
["[#{entry[:id]}]", MemoryCommands.short_time(entry[:occurred_at] || entry[:created_at]), knowledge, *scores]
|
|
156
|
+
.compact.join(' ')
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def content_lines(content)
|
|
160
|
+
text = @full ? content.to_s : MemoryCommands.preview(content)
|
|
161
|
+
text.lines.map { " #{it.chomp}" }
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Print +pairs+ as aligned "label: value" lines under +title+
|
|
165
|
+
def print_pairs(title, pairs)
|
|
166
|
+
out.puts title
|
|
167
|
+
width = pairs.keys.map(&:length).max.to_i
|
|
168
|
+
pairs.each { |label, value| out.puts " #{label.ljust(width)} #{value}" }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
require_relative 'memory_commands/text'
|
|
176
|
+
require_relative 'memory_commands/search'
|
|
177
|
+
require_relative 'memory_commands/edit'
|
|
178
|
+
require_relative 'memory_commands/working_memory'
|
|
179
|
+
require_relative 'memory_commands/tag_search'
|