rookery-agent 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.
- package/LICENSE +21 -0
- package/README.md +367 -0
- package/docs/migration.md +88 -0
- package/package.json +39 -0
- package/packages/cli/dist/commands/chat.d.ts +52 -0
- package/packages/cli/dist/commands/chat.d.ts.map +1 -0
- package/packages/cli/dist/commands/chat.js +107 -0
- package/packages/cli/dist/commands/chat.js.map +1 -0
- package/packages/cli/dist/commands/config.d.ts +12 -0
- package/packages/cli/dist/commands/config.d.ts.map +1 -0
- package/packages/cli/dist/commands/config.js +156 -0
- package/packages/cli/dist/commands/config.js.map +1 -0
- package/packages/cli/dist/commands/doctor.d.ts +12 -0
- package/packages/cli/dist/commands/doctor.d.ts.map +1 -0
- package/packages/cli/dist/commands/doctor.js +137 -0
- package/packages/cli/dist/commands/doctor.js.map +1 -0
- package/packages/cli/dist/commands/memory.d.ts +34 -0
- package/packages/cli/dist/commands/memory.d.ts.map +1 -0
- package/packages/cli/dist/commands/memory.js +133 -0
- package/packages/cli/dist/commands/memory.js.map +1 -0
- package/packages/cli/dist/commands/org.d.ts +93 -0
- package/packages/cli/dist/commands/org.d.ts.map +1 -0
- package/packages/cli/dist/commands/org.js +389 -0
- package/packages/cli/dist/commands/org.js.map +1 -0
- package/packages/cli/dist/commands/serve.d.ts +13 -0
- package/packages/cli/dist/commands/serve.d.ts.map +1 -0
- package/packages/cli/dist/commands/serve.js +100 -0
- package/packages/cli/dist/commands/serve.js.map +1 -0
- package/packages/cli/dist/commands/sessions.d.ts +18 -0
- package/packages/cli/dist/commands/sessions.d.ts.map +1 -0
- package/packages/cli/dist/commands/sessions.js +88 -0
- package/packages/cli/dist/commands/sessions.js.map +1 -0
- package/packages/cli/dist/commands/shared.d.ts +59 -0
- package/packages/cli/dist/commands/shared.d.ts.map +1 -0
- package/packages/cli/dist/commands/shared.js +230 -0
- package/packages/cli/dist/commands/shared.js.map +1 -0
- package/packages/cli/dist/commands/tasks.d.ts +62 -0
- package/packages/cli/dist/commands/tasks.d.ts.map +1 -0
- package/packages/cli/dist/commands/tasks.js +262 -0
- package/packages/cli/dist/commands/tasks.js.map +1 -0
- package/packages/cli/dist/commands/tools.d.ts +8 -0
- package/packages/cli/dist/commands/tools.d.ts.map +1 -0
- package/packages/cli/dist/commands/tools.js +65 -0
- package/packages/cli/dist/commands/tools.js.map +1 -0
- package/packages/cli/dist/index.d.ts +15 -0
- package/packages/cli/dist/index.d.ts.map +1 -0
- package/packages/cli/dist/index.js +513 -0
- package/packages/cli/dist/index.js.map +1 -0
- package/packages/cli/dist/repl.d.ts +29 -0
- package/packages/cli/dist/repl.d.ts.map +1 -0
- package/packages/cli/dist/repl.js +634 -0
- package/packages/cli/dist/repl.js.map +1 -0
- package/packages/cli/dist/tui/App.d.ts +51 -0
- package/packages/cli/dist/tui/App.d.ts.map +1 -0
- package/packages/cli/dist/tui/App.js +461 -0
- package/packages/cli/dist/tui/App.js.map +1 -0
- package/packages/cli/dist/tui/commands.d.ts +34 -0
- package/packages/cli/dist/tui/commands.d.ts.map +1 -0
- package/packages/cli/dist/tui/commands.js +367 -0
- package/packages/cli/dist/tui/commands.js.map +1 -0
- package/packages/cli/dist/tui/components/ActivityLine.d.ts +16 -0
- package/packages/cli/dist/tui/components/ActivityLine.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/ActivityLine.js +7 -0
- package/packages/cli/dist/tui/components/ActivityLine.js.map +1 -0
- package/packages/cli/dist/tui/components/AssignmentsView.d.ts +31 -0
- package/packages/cli/dist/tui/components/AssignmentsView.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/AssignmentsView.js +79 -0
- package/packages/cli/dist/tui/components/AssignmentsView.js.map +1 -0
- package/packages/cli/dist/tui/components/Banner.d.ts +18 -0
- package/packages/cli/dist/tui/components/Banner.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Banner.js +16 -0
- package/packages/cli/dist/tui/components/Banner.js.map +1 -0
- package/packages/cli/dist/tui/components/CodeBlock.d.ts +19 -0
- package/packages/cli/dist/tui/components/CodeBlock.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/CodeBlock.js +21 -0
- package/packages/cli/dist/tui/components/CodeBlock.js.map +1 -0
- package/packages/cli/dist/tui/components/InputBox.d.ts +25 -0
- package/packages/cli/dist/tui/components/InputBox.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/InputBox.js +35 -0
- package/packages/cli/dist/tui/components/InputBox.js.map +1 -0
- package/packages/cli/dist/tui/components/Markdown.d.ts +74 -0
- package/packages/cli/dist/tui/components/Markdown.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Markdown.js +293 -0
- package/packages/cli/dist/tui/components/Markdown.js.map +1 -0
- package/packages/cli/dist/tui/components/Message.d.ts +29 -0
- package/packages/cli/dist/tui/components/Message.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Message.js +28 -0
- package/packages/cli/dist/tui/components/Message.js.map +1 -0
- package/packages/cli/dist/tui/components/Scrollback.d.ts +23 -0
- package/packages/cli/dist/tui/components/Scrollback.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Scrollback.js +36 -0
- package/packages/cli/dist/tui/components/Scrollback.js.map +1 -0
- package/packages/cli/dist/tui/components/SlashPalette.d.ts +17 -0
- package/packages/cli/dist/tui/components/SlashPalette.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/SlashPalette.js +19 -0
- package/packages/cli/dist/tui/components/SlashPalette.js.map +1 -0
- package/packages/cli/dist/tui/components/StatusLine.d.ts +61 -0
- package/packages/cli/dist/tui/components/StatusLine.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/StatusLine.js +55 -0
- package/packages/cli/dist/tui/components/StatusLine.js.map +1 -0
- package/packages/cli/dist/tui/components/ToolGroup.d.ts +33 -0
- package/packages/cli/dist/tui/components/ToolGroup.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/ToolGroup.js +52 -0
- package/packages/cli/dist/tui/components/ToolGroup.js.map +1 -0
- package/packages/cli/dist/tui/components/Wordmark.d.ts +35 -0
- package/packages/cli/dist/tui/components/Wordmark.d.ts.map +1 -0
- package/packages/cli/dist/tui/components/Wordmark.js +81 -0
- package/packages/cli/dist/tui/components/Wordmark.js.map +1 -0
- package/packages/cli/dist/tui/highlight.d.ts +29 -0
- package/packages/cli/dist/tui/highlight.d.ts.map +1 -0
- package/packages/cli/dist/tui/highlight.js +137 -0
- package/packages/cli/dist/tui/highlight.js.map +1 -0
- package/packages/cli/dist/tui/hooks/useColumns.d.ts +20 -0
- package/packages/cli/dist/tui/hooks/useColumns.d.ts.map +1 -0
- package/packages/cli/dist/tui/hooks/useColumns.js +38 -0
- package/packages/cli/dist/tui/hooks/useColumns.js.map +1 -0
- package/packages/cli/dist/tui/hooks/useHistory.d.ts +21 -0
- package/packages/cli/dist/tui/hooks/useHistory.d.ts.map +1 -0
- package/packages/cli/dist/tui/hooks/useHistory.js +57 -0
- package/packages/cli/dist/tui/hooks/useHistory.js.map +1 -0
- package/packages/cli/dist/tui/hooks/useSlash.d.ts +38 -0
- package/packages/cli/dist/tui/hooks/useSlash.d.ts.map +1 -0
- package/packages/cli/dist/tui/hooks/useSlash.js +89 -0
- package/packages/cli/dist/tui/hooks/useSlash.js.map +1 -0
- package/packages/cli/dist/tui/hooks/useTurn.d.ts +75 -0
- package/packages/cli/dist/tui/hooks/useTurn.d.ts.map +1 -0
- package/packages/cli/dist/tui/hooks/useTurn.js +396 -0
- package/packages/cli/dist/tui/hooks/useTurn.js.map +1 -0
- package/packages/cli/dist/tui/theme.d.ts +126 -0
- package/packages/cli/dist/tui/theme.d.ts.map +1 -0
- package/packages/cli/dist/tui/theme.js +127 -0
- package/packages/cli/dist/tui/theme.js.map +1 -0
- package/packages/cli/dist/tui/types.d.ts +205 -0
- package/packages/cli/dist/tui/types.d.ts.map +1 -0
- package/packages/cli/dist/tui/types.js +55 -0
- package/packages/cli/dist/tui/types.js.map +1 -0
- package/packages/cli/dist/ui/render.d.ts +74 -0
- package/packages/cli/dist/ui/render.d.ts.map +1 -0
- package/packages/cli/dist/ui/render.js +349 -0
- package/packages/cli/dist/ui/render.js.map +1 -0
- package/packages/cli/dist/ui/speech.d.ts +42 -0
- package/packages/cli/dist/ui/speech.d.ts.map +1 -0
- package/packages/cli/dist/ui/speech.js +257 -0
- package/packages/cli/dist/ui/speech.js.map +1 -0
- package/packages/cli/dist/ui/spinner.d.ts +17 -0
- package/packages/cli/dist/ui/spinner.d.ts.map +1 -0
- package/packages/cli/dist/ui/spinner.js +61 -0
- package/packages/cli/dist/ui/spinner.js.map +1 -0
- package/packages/cli/dist/ui/theme.d.ts +54 -0
- package/packages/cli/dist/ui/theme.d.ts.map +1 -0
- package/packages/cli/dist/ui/theme.js +74 -0
- package/packages/cli/dist/ui/theme.js.map +1 -0
- package/packages/cli/package.json +1 -0
- package/packages/core/dist/agents/legacy-persona.d.ts +4 -0
- package/packages/core/dist/agents/legacy-persona.d.ts.map +1 -0
- package/packages/core/dist/agents/legacy-persona.js +39 -0
- package/packages/core/dist/agents/legacy-persona.js.map +1 -0
- package/packages/core/dist/agents/orchestrator.d.ts +24 -0
- package/packages/core/dist/agents/orchestrator.d.ts.map +1 -0
- package/packages/core/dist/agents/orchestrator.js +88 -0
- package/packages/core/dist/agents/orchestrator.js.map +1 -0
- package/packages/core/dist/agents/persona.d.ts +56 -0
- package/packages/core/dist/agents/persona.d.ts.map +1 -0
- package/packages/core/dist/agents/persona.js +153 -0
- package/packages/core/dist/agents/persona.js.map +1 -0
- package/packages/core/dist/agents/roles.d.ts +21 -0
- package/packages/core/dist/agents/roles.d.ts.map +1 -0
- package/packages/core/dist/agents/roles.js +81 -0
- package/packages/core/dist/agents/roles.js.map +1 -0
- package/packages/core/dist/agents/team.d.ts +105 -0
- package/packages/core/dist/agents/team.d.ts.map +1 -0
- package/packages/core/dist/agents/team.js +623 -0
- package/packages/core/dist/agents/team.js.map +1 -0
- package/packages/core/dist/computer/keys.d.ts +12 -0
- package/packages/core/dist/computer/keys.d.ts.map +1 -0
- package/packages/core/dist/computer/keys.js +56 -0
- package/packages/core/dist/computer/keys.js.map +1 -0
- package/packages/core/dist/computer/mcp-server.d.ts +11 -0
- package/packages/core/dist/computer/mcp-server.d.ts.map +1 -0
- package/packages/core/dist/computer/mcp-server.js +228 -0
- package/packages/core/dist/computer/mcp-server.js.map +1 -0
- package/packages/core/dist/computer/powershell.d.ts +13 -0
- package/packages/core/dist/computer/powershell.d.ts.map +1 -0
- package/packages/core/dist/computer/powershell.js +359 -0
- package/packages/core/dist/computer/powershell.js.map +1 -0
- package/packages/core/dist/computer/tools.d.ts +43 -0
- package/packages/core/dist/computer/tools.d.ts.map +1 -0
- package/packages/core/dist/computer/tools.js +260 -0
- package/packages/core/dist/computer/tools.js.map +1 -0
- package/packages/core/dist/config.d.ts +32 -0
- package/packages/core/dist/config.d.ts.map +1 -0
- package/packages/core/dist/config.js +329 -0
- package/packages/core/dist/config.js.map +1 -0
- package/packages/core/dist/cron/parse.d.ts +52 -0
- package/packages/core/dist/cron/parse.d.ts.map +1 -0
- package/packages/core/dist/cron/parse.js +277 -0
- package/packages/core/dist/cron/parse.js.map +1 -0
- package/packages/core/dist/cron/scheduler.d.ts +102 -0
- package/packages/core/dist/cron/scheduler.d.ts.map +1 -0
- package/packages/core/dist/cron/scheduler.js +334 -0
- package/packages/core/dist/cron/scheduler.js.map +1 -0
- package/packages/core/dist/cron/script.d.ts +9 -0
- package/packages/core/dist/cron/script.d.ts.map +1 -0
- package/packages/core/dist/cron/script.js +113 -0
- package/packages/core/dist/cron/script.js.map +1 -0
- package/packages/core/dist/cron/store.d.ts +77 -0
- package/packages/core/dist/cron/store.d.ts.map +1 -0
- package/packages/core/dist/cron/store.js +229 -0
- package/packages/core/dist/cron/store.js.map +1 -0
- package/packages/core/dist/gateway/policy.d.ts +113 -0
- package/packages/core/dist/gateway/policy.d.ts.map +1 -0
- package/packages/core/dist/gateway/policy.js +373 -0
- package/packages/core/dist/gateway/policy.js.map +1 -0
- package/packages/core/dist/index.d.ts +45 -0
- package/packages/core/dist/index.d.ts.map +1 -0
- package/packages/core/dist/index.js +52 -0
- package/packages/core/dist/index.js.map +1 -0
- package/packages/core/dist/logger.d.ts +21 -0
- package/packages/core/dist/logger.d.ts.map +1 -0
- package/packages/core/dist/logger.js +61 -0
- package/packages/core/dist/logger.js.map +1 -0
- package/packages/core/dist/memory/db.d.ts +12 -0
- package/packages/core/dist/memory/db.d.ts.map +1 -0
- package/packages/core/dist/memory/db.js +414 -0
- package/packages/core/dist/memory/db.js.map +1 -0
- package/packages/core/dist/memory/extractor.d.ts +35 -0
- package/packages/core/dist/memory/extractor.d.ts.map +1 -0
- package/packages/core/dist/memory/extractor.js +159 -0
- package/packages/core/dist/memory/extractor.js.map +1 -0
- package/packages/core/dist/memory/gate.d.ts +68 -0
- package/packages/core/dist/memory/gate.d.ts.map +1 -0
- package/packages/core/dist/memory/gate.js +163 -0
- package/packages/core/dist/memory/gate.js.map +1 -0
- package/packages/core/dist/memory/recall.d.ts +61 -0
- package/packages/core/dist/memory/recall.d.ts.map +1 -0
- package/packages/core/dist/memory/recall.js +342 -0
- package/packages/core/dist/memory/recall.js.map +1 -0
- package/packages/core/dist/memory/sleep.d.ts +105 -0
- package/packages/core/dist/memory/sleep.d.ts.map +1 -0
- package/packages/core/dist/memory/sleep.js +888 -0
- package/packages/core/dist/memory/sleep.js.map +1 -0
- package/packages/core/dist/memory/store.d.ts +263 -0
- package/packages/core/dist/memory/store.d.ts.map +1 -0
- package/packages/core/dist/memory/store.js +999 -0
- package/packages/core/dist/memory/store.js.map +1 -0
- package/packages/core/dist/migration-cron.d.ts +37 -0
- package/packages/core/dist/migration-cron.d.ts.map +1 -0
- package/packages/core/dist/migration-cron.js +257 -0
- package/packages/core/dist/migration-cron.js.map +1 -0
- package/packages/core/dist/migration-scripts.d.ts +15 -0
- package/packages/core/dist/migration-scripts.d.ts.map +1 -0
- package/packages/core/dist/migration-scripts.js +97 -0
- package/packages/core/dist/migration-scripts.js.map +1 -0
- package/packages/core/dist/migration.d.ts +33 -0
- package/packages/core/dist/migration.d.ts.map +1 -0
- package/packages/core/dist/migration.js +296 -0
- package/packages/core/dist/migration.js.map +1 -0
- package/packages/core/dist/org/bridge.d.ts +42 -0
- package/packages/core/dist/org/bridge.d.ts.map +1 -0
- package/packages/core/dist/org/bridge.js +139 -0
- package/packages/core/dist/org/bridge.js.map +1 -0
- package/packages/core/dist/org/controller.d.ts +118 -0
- package/packages/core/dist/org/controller.d.ts.map +1 -0
- package/packages/core/dist/org/controller.js +1431 -0
- package/packages/core/dist/org/controller.js.map +1 -0
- package/packages/core/dist/org/mcp-bridge.d.ts +11 -0
- package/packages/core/dist/org/mcp-bridge.d.ts.map +1 -0
- package/packages/core/dist/org/mcp-bridge.js +148 -0
- package/packages/core/dist/org/mcp-bridge.js.map +1 -0
- package/packages/core/dist/org/planner.d.ts +60 -0
- package/packages/core/dist/org/planner.d.ts.map +1 -0
- package/packages/core/dist/org/planner.js +175 -0
- package/packages/core/dist/org/planner.js.map +1 -0
- package/packages/core/dist/org/ponytail.d.ts +24 -0
- package/packages/core/dist/org/ponytail.d.ts.map +1 -0
- package/packages/core/dist/org/ponytail.js +53 -0
- package/packages/core/dist/org/ponytail.js.map +1 -0
- package/packages/core/dist/org/project-mcp.d.ts +32 -0
- package/packages/core/dist/org/project-mcp.d.ts.map +1 -0
- package/packages/core/dist/org/project-mcp.js +53 -0
- package/packages/core/dist/org/project-mcp.js.map +1 -0
- package/packages/core/dist/org/prompts.d.ts +71 -0
- package/packages/core/dist/org/prompts.d.ts.map +1 -0
- package/packages/core/dist/org/prompts.js +268 -0
- package/packages/core/dist/org/prompts.js.map +1 -0
- package/packages/core/dist/org/store.d.ts +176 -0
- package/packages/core/dist/org/store.d.ts.map +1 -0
- package/packages/core/dist/org/store.js +594 -0
- package/packages/core/dist/org/store.js.map +1 -0
- package/packages/core/dist/org/tools.d.ts +22 -0
- package/packages/core/dist/org/tools.d.ts.map +1 -0
- package/packages/core/dist/org/tools.js +578 -0
- package/packages/core/dist/org/tools.js.map +1 -0
- package/packages/core/dist/profile.d.ts +16 -0
- package/packages/core/dist/profile.d.ts.map +1 -0
- package/packages/core/dist/profile.js +176 -0
- package/packages/core/dist/profile.js.map +1 -0
- package/packages/core/dist/providers/catalogue.d.ts +6 -0
- package/packages/core/dist/providers/catalogue.d.ts.map +1 -0
- package/packages/core/dist/providers/catalogue.js +104 -0
- package/packages/core/dist/providers/catalogue.js.map +1 -0
- package/packages/core/dist/providers/claude-code.d.ts +10 -0
- package/packages/core/dist/providers/claude-code.d.ts.map +1 -0
- package/packages/core/dist/providers/claude-code.js +321 -0
- package/packages/core/dist/providers/claude-code.js.map +1 -0
- package/packages/core/dist/providers/codex.d.ts +10 -0
- package/packages/core/dist/providers/codex.d.ts.map +1 -0
- package/packages/core/dist/providers/codex.js +375 -0
- package/packages/core/dist/providers/codex.js.map +1 -0
- package/packages/core/dist/providers/process.d.ts +48 -0
- package/packages/core/dist/providers/process.d.ts.map +1 -0
- package/packages/core/dist/providers/process.js +165 -0
- package/packages/core/dist/providers/process.js.map +1 -0
- package/packages/core/dist/providers/quota.d.ts +13 -0
- package/packages/core/dist/providers/quota.d.ts.map +1 -0
- package/packages/core/dist/providers/quota.js +231 -0
- package/packages/core/dist/providers/quota.js.map +1 -0
- package/packages/core/dist/providers/registry.d.ts +27 -0
- package/packages/core/dist/providers/registry.d.ts.map +1 -0
- package/packages/core/dist/providers/registry.js +64 -0
- package/packages/core/dist/providers/registry.js.map +1 -0
- package/packages/core/dist/runtime.d.ts +149 -0
- package/packages/core/dist/runtime.d.ts.map +1 -0
- package/packages/core/dist/runtime.js +778 -0
- package/packages/core/dist/runtime.js.map +1 -0
- package/packages/core/dist/skills/import.d.ts +41 -0
- package/packages/core/dist/skills/import.d.ts.map +1 -0
- package/packages/core/dist/skills/import.js +129 -0
- package/packages/core/dist/skills/import.js.map +1 -0
- package/packages/core/dist/skills/store.d.ts +57 -0
- package/packages/core/dist/skills/store.d.ts.map +1 -0
- package/packages/core/dist/skills/store.js +126 -0
- package/packages/core/dist/skills/store.js.map +1 -0
- package/packages/core/dist/tools/browser.d.ts +20 -0
- package/packages/core/dist/tools/browser.d.ts.map +1 -0
- package/packages/core/dist/tools/browser.js +72 -0
- package/packages/core/dist/tools/browser.js.map +1 -0
- package/packages/core/dist/tools/catalog.d.ts +67 -0
- package/packages/core/dist/tools/catalog.d.ts.map +1 -0
- package/packages/core/dist/tools/catalog.js +233 -0
- package/packages/core/dist/tools/catalog.js.map +1 -0
- package/packages/core/dist/tools/hub.d.ts +68 -0
- package/packages/core/dist/tools/hub.d.ts.map +1 -0
- package/packages/core/dist/tools/hub.js +213 -0
- package/packages/core/dist/tools/hub.js.map +1 -0
- package/packages/core/dist/types.d.ts +1031 -0
- package/packages/core/dist/types.d.ts.map +1 -0
- package/packages/core/dist/types.js +22 -0
- package/packages/core/dist/types.js.map +1 -0
- package/packages/core/dist/util/queue.d.ts +25 -0
- package/packages/core/dist/util/queue.d.ts.map +1 -0
- package/packages/core/dist/util/queue.js +64 -0
- package/packages/core/dist/util/queue.js.map +1 -0
- package/packages/core/package.json +1 -0
- package/packages/server/dist/auth.d.ts +12 -0
- package/packages/server/dist/auth.d.ts.map +1 -0
- package/packages/server/dist/auth.js +61 -0
- package/packages/server/dist/auth.js.map +1 -0
- package/packages/server/dist/context.d.ts +29 -0
- package/packages/server/dist/context.d.ts.map +1 -0
- package/packages/server/dist/context.js +46 -0
- package/packages/server/dist/context.js.map +1 -0
- package/packages/server/dist/env.d.ts +8 -0
- package/packages/server/dist/env.d.ts.map +1 -0
- package/packages/server/dist/env.js +36 -0
- package/packages/server/dist/env.js.map +1 -0
- package/packages/server/dist/gateways/push.d.ts +22 -0
- package/packages/server/dist/gateways/push.d.ts.map +1 -0
- package/packages/server/dist/gateways/push.js +267 -0
- package/packages/server/dist/gateways/push.js.map +1 -0
- package/packages/server/dist/gateways/telegram-api.d.ts +82 -0
- package/packages/server/dist/gateways/telegram-api.d.ts.map +1 -0
- package/packages/server/dist/gateways/telegram-api.js +168 -0
- package/packages/server/dist/gateways/telegram-api.js.map +1 -0
- package/packages/server/dist/gateways/telegram.d.ts +32 -0
- package/packages/server/dist/gateways/telegram.d.ts.map +1 -0
- package/packages/server/dist/gateways/telegram.js +583 -0
- package/packages/server/dist/gateways/telegram.js.map +1 -0
- package/packages/server/dist/index.d.ts +12 -0
- package/packages/server/dist/index.d.ts.map +1 -0
- package/packages/server/dist/index.js +12 -0
- package/packages/server/dist/index.js.map +1 -0
- package/packages/server/dist/main.d.ts +2 -0
- package/packages/server/dist/main.d.ts.map +1 -0
- package/packages/server/dist/main.js +74 -0
- package/packages/server/dist/main.js.map +1 -0
- package/packages/server/dist/routes/agents.d.ts +5 -0
- package/packages/server/dist/routes/agents.d.ts.map +1 -0
- package/packages/server/dist/routes/agents.js +6 -0
- package/packages/server/dist/routes/agents.js.map +1 -0
- package/packages/server/dist/routes/chat.d.ts +10 -0
- package/packages/server/dist/routes/chat.d.ts.map +1 -0
- package/packages/server/dist/routes/chat.js +36 -0
- package/packages/server/dist/routes/chat.js.map +1 -0
- package/packages/server/dist/routes/config.d.ts +4 -0
- package/packages/server/dist/routes/config.d.ts.map +1 -0
- package/packages/server/dist/routes/config.js +58 -0
- package/packages/server/dist/routes/config.js.map +1 -0
- package/packages/server/dist/routes/cron.d.ts +10 -0
- package/packages/server/dist/routes/cron.d.ts.map +1 -0
- package/packages/server/dist/routes/cron.js +128 -0
- package/packages/server/dist/routes/cron.js.map +1 -0
- package/packages/server/dist/routes/gateways.d.ts +10 -0
- package/packages/server/dist/routes/gateways.d.ts.map +1 -0
- package/packages/server/dist/routes/gateways.js +32 -0
- package/packages/server/dist/routes/gateways.js.map +1 -0
- package/packages/server/dist/routes/health.d.ts +8 -0
- package/packages/server/dist/routes/health.d.ts.map +1 -0
- package/packages/server/dist/routes/health.js +12 -0
- package/packages/server/dist/routes/health.js.map +1 -0
- package/packages/server/dist/routes/memories.d.ts +11 -0
- package/packages/server/dist/routes/memories.d.ts.map +1 -0
- package/packages/server/dist/routes/memories.js +134 -0
- package/packages/server/dist/routes/memories.js.map +1 -0
- package/packages/server/dist/routes/org.d.ts +13 -0
- package/packages/server/dist/routes/org.d.ts.map +1 -0
- package/packages/server/dist/routes/org.js +316 -0
- package/packages/server/dist/routes/org.js.map +1 -0
- package/packages/server/dist/routes/profile.d.ts +4 -0
- package/packages/server/dist/routes/profile.d.ts.map +1 -0
- package/packages/server/dist/routes/profile.js +51 -0
- package/packages/server/dist/routes/profile.js.map +1 -0
- package/packages/server/dist/routes/providers.d.ts +9 -0
- package/packages/server/dist/routes/providers.d.ts.map +1 -0
- package/packages/server/dist/routes/providers.js +41 -0
- package/packages/server/dist/routes/providers.js.map +1 -0
- package/packages/server/dist/routes/sessions.d.ts +9 -0
- package/packages/server/dist/routes/sessions.d.ts.map +1 -0
- package/packages/server/dist/routes/sessions.js +72 -0
- package/packages/server/dist/routes/sessions.js.map +1 -0
- package/packages/server/dist/routes/sleep.d.ts +12 -0
- package/packages/server/dist/routes/sleep.d.ts.map +1 -0
- package/packages/server/dist/routes/sleep.js +70 -0
- package/packages/server/dist/routes/sleep.js.map +1 -0
- package/packages/server/dist/routes/stats.d.ts +17 -0
- package/packages/server/dist/routes/stats.d.ts.map +1 -0
- package/packages/server/dist/routes/stats.js +57 -0
- package/packages/server/dist/routes/stats.js.map +1 -0
- package/packages/server/dist/routes/team.d.ts +11 -0
- package/packages/server/dist/routes/team.d.ts.map +1 -0
- package/packages/server/dist/routes/team.js +36 -0
- package/packages/server/dist/routes/team.js.map +1 -0
- package/packages/server/dist/routes/tools.d.ts +10 -0
- package/packages/server/dist/routes/tools.d.ts.map +1 -0
- package/packages/server/dist/routes/tools.js +128 -0
- package/packages/server/dist/routes/tools.js.map +1 -0
- package/packages/server/dist/routes/tts.d.ts +12 -0
- package/packages/server/dist/routes/tts.d.ts.map +1 -0
- package/packages/server/dist/routes/tts.js +38 -0
- package/packages/server/dist/routes/tts.js.map +1 -0
- package/packages/server/dist/routes/ws.d.ts +13 -0
- package/packages/server/dist/routes/ws.d.ts.map +1 -0
- package/packages/server/dist/routes/ws.js +96 -0
- package/packages/server/dist/routes/ws.js.map +1 -0
- package/packages/server/dist/schemas.d.ts +981 -0
- package/packages/server/dist/schemas.d.ts.map +1 -0
- package/packages/server/dist/schemas.js +339 -0
- package/packages/server/dist/schemas.js.map +1 -0
- package/packages/server/dist/server.d.ts +20 -0
- package/packages/server/dist/server.d.ts.map +1 -0
- package/packages/server/dist/server.js +234 -0
- package/packages/server/dist/server.js.map +1 -0
- package/packages/server/dist/services/stream.d.ts +77 -0
- package/packages/server/dist/services/stream.d.ts.map +1 -0
- package/packages/server/dist/services/stream.js +84 -0
- package/packages/server/dist/services/stream.js.map +1 -0
- package/packages/server/dist/services/tts.d.ts +53 -0
- package/packages/server/dist/services/tts.d.ts.map +1 -0
- package/packages/server/dist/services/tts.js +281 -0
- package/packages/server/dist/services/tts.js.map +1 -0
- package/packages/server/dist/services/voice-keys.d.ts +26 -0
- package/packages/server/dist/services/voice-keys.d.ts.map +1 -0
- package/packages/server/dist/services/voice-keys.js +51 -0
- package/packages/server/dist/services/voice-keys.js.map +1 -0
- package/packages/server/dist/static.d.ts +12 -0
- package/packages/server/dist/static.d.ts.map +1 -0
- package/packages/server/dist/static.js +63 -0
- package/packages/server/dist/static.js.map +1 -0
- package/packages/server/package.json +1 -0
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/3d-force-graph-BPZmoydi.js +1163 -0
- package/packages/web/dist/assets/bricolage-grotesque-latin-ext-wght-normal-CcLUaPy7.woff2 +0 -0
- package/packages/web/dist/assets/bricolage-grotesque-latin-wght-normal-DLoelf7F.woff2 +0 -0
- package/packages/web/dist/assets/bricolage-grotesque-vietnamese-wght-normal-BUzh504Q.woff2 +0 -0
- package/packages/web/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/packages/web/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/packages/web/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/packages/web/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/packages/web/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/packages/web/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/packages/web/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/packages/web/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/packages/web/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/packages/web/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/packages/web/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/packages/web/dist/assets/index-IBSTzK7-.js +1255 -0
- package/packages/web/dist/assets/index-qUXUui7W.css +1 -0
- package/packages/web/dist/assets/three-spritetext-B9ZIW7c-.js +4 -0
- package/packages/web/dist/assets/three.module-cmFfBtHS.js +4228 -0
- package/packages/web/dist/favicon.ico +0 -0
- package/packages/web/dist/favicon.svg +2 -0
- package/packages/web/dist/index.html +28 -0
- package/packages/web/dist/logo-light.svg +2 -0
- package/packages/web/dist/logo.svg +2 -0
- package/packages/web/dist/mark-light.svg +2 -0
- package/packages/web/dist/mark.svg +2 -0
- package/packages/web/package.json +1 -0
- package/scripts/rookery.mjs +183 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { MemoryConfig, MemoryEdge, MemoryRecord } from '../types.js';
|
|
2
|
+
import { type Store } from './store.js';
|
|
3
|
+
import type { MemoryCandidate } from './extractor.js';
|
|
4
|
+
/**
|
|
5
|
+
* The gate in front of the write path.
|
|
6
|
+
*
|
|
7
|
+
* Extraction proposes; this decides. Without it the bank grows for three
|
|
8
|
+
* reasons that have nothing to do with learning anything new:
|
|
9
|
+
*
|
|
10
|
+
* 1. the extractor runs after every turn and defaults to importance 0.5,
|
|
11
|
+
* 2. the duplicate guard is a unique index on the exact sentence, so one
|
|
12
|
+
* changed word makes a second record,
|
|
13
|
+
* 3. nothing ever dies, so both records stay forever.
|
|
14
|
+
*
|
|
15
|
+
* The gate closes the first two. Near-duplicates reinforce the memory that
|
|
16
|
+
* is already there instead of joining it, weak candidates are dropped, and
|
|
17
|
+
* pairs that are similar but not the same are queued for the night with a
|
|
18
|
+
* `co_occurs` edge, which is where condensation picks them up.
|
|
19
|
+
*
|
|
20
|
+
* Similarity is lexical on purpose. The provider CLIs return text, not
|
|
21
|
+
* embeddings, and a local embedding model would mean a native build step -
|
|
22
|
+
* exactly what `memory/db.ts` avoids by using `node:sqlite`. For sentences
|
|
23
|
+
* the same small model wrote from the same instructions, the Dice
|
|
24
|
+
* coefficient over normalised token sets is a good enough judge.
|
|
25
|
+
*/
|
|
26
|
+
export interface GateResult {
|
|
27
|
+
/** Newly written memories. */
|
|
28
|
+
stored: MemoryRecord[];
|
|
29
|
+
/** Existing memories a candidate reinforced instead of duplicating. */
|
|
30
|
+
reinforced: MemoryRecord[];
|
|
31
|
+
/** Candidates thrown away, with the reason, for the log and for tests. */
|
|
32
|
+
rejected: {
|
|
33
|
+
content: string;
|
|
34
|
+
reason: 'weak' | 'short' | 'duplicate-in-batch' | 'over-budget';
|
|
35
|
+
}[];
|
|
36
|
+
/** `co_occurs` edges queued for the nightly condensation. */
|
|
37
|
+
queued: MemoryEdge[];
|
|
38
|
+
}
|
|
39
|
+
export interface GateInput {
|
|
40
|
+
candidates: MemoryCandidate[];
|
|
41
|
+
owner: string;
|
|
42
|
+
config: MemoryConfig;
|
|
43
|
+
sourceSessionId?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Normalise a sentence to the token set similarity is measured on:
|
|
47
|
+
* lower case, no diacritics, no punctuation, no stop words.
|
|
48
|
+
*/
|
|
49
|
+
export declare function normalizeTokens(text: string): Set<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Dice coefficient over two token sets: twice the overlap divided by the
|
|
52
|
+
* combined size. 1 is the same sentence, 0 shares nothing.
|
|
53
|
+
*
|
|
54
|
+
* Dice rather than Jaccard because it is kinder to a longer sentence that
|
|
55
|
+
* contains a shorter one - "works with TypeScript" against "works mainly
|
|
56
|
+
* with TypeScript on Windows" should read as the same fact, not half of one.
|
|
57
|
+
*/
|
|
58
|
+
export declare function similarity(a: Set<string>, b: Set<string>): number;
|
|
59
|
+
/**
|
|
60
|
+
* Run the candidates of one turn through the gate and store what survives.
|
|
61
|
+
*
|
|
62
|
+
* Everything here is synchronous and local: no model call, no network. The
|
|
63
|
+
* expensive judgement already happened during extraction.
|
|
64
|
+
*/
|
|
65
|
+
export declare function admitCandidates(store: Store, input: GateInput): GateResult;
|
|
66
|
+
/** Tags become entities: the cheapest possible seed for the graph. */
|
|
67
|
+
export declare function linkEntities(store: Store, owner: string, memoryId: string, tags: string[]): void;
|
|
68
|
+
//# sourceMappingURL=gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/memory/gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,uEAAuE;IACvE,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,0EAA0E;IAC1E,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,oBAAoB,GAAG,aAAa,CAAA;KAAE,EAAE,CAAC;IACjG,6DAA6D;IAC7D,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,YAAY,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAKjE;AAOD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,UAAU,CAqF1E;AAyCD,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAWhG"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { entitySlug, mapMemory } from './store.js';
|
|
2
|
+
import { toMatchQuery, tokenize } from './recall.js';
|
|
3
|
+
/**
|
|
4
|
+
* Normalise a sentence to the token set similarity is measured on:
|
|
5
|
+
* lower case, no diacritics, no punctuation, no stop words.
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeTokens(text) {
|
|
8
|
+
return new Set(tokenize(text));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Dice coefficient over two token sets: twice the overlap divided by the
|
|
12
|
+
* combined size. 1 is the same sentence, 0 shares nothing.
|
|
13
|
+
*
|
|
14
|
+
* Dice rather than Jaccard because it is kinder to a longer sentence that
|
|
15
|
+
* contains a shorter one - "works with TypeScript" against "works mainly
|
|
16
|
+
* with TypeScript on Windows" should read as the same fact, not half of one.
|
|
17
|
+
*/
|
|
18
|
+
export function similarity(a, b) {
|
|
19
|
+
if (!a.size || !b.size)
|
|
20
|
+
return 0;
|
|
21
|
+
let shared = 0;
|
|
22
|
+
for (const token of a)
|
|
23
|
+
if (b.has(token))
|
|
24
|
+
shared += 1;
|
|
25
|
+
return (2 * shared) / (a.size + b.size);
|
|
26
|
+
}
|
|
27
|
+
/** Of two sentences saying the same thing, keep the one that says more. */
|
|
28
|
+
function richer(a, b) {
|
|
29
|
+
return b.trim().length > a.trim().length + 8 ? b : a;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Run the candidates of one turn through the gate and store what survives.
|
|
33
|
+
*
|
|
34
|
+
* Everything here is synchronous and local: no model call, no network. The
|
|
35
|
+
* expensive judgement already happened during extraction.
|
|
36
|
+
*/
|
|
37
|
+
export function admitCandidates(store, input) {
|
|
38
|
+
const { owner, config } = input;
|
|
39
|
+
const gate = config.gate;
|
|
40
|
+
const result = { stored: [], reinforced: [], rejected: [], queued: [] };
|
|
41
|
+
const seenThisTurn = [];
|
|
42
|
+
for (const candidate of input.candidates) {
|
|
43
|
+
if (result.stored.length + result.reinforced.length >= gate.maxPerTurn) {
|
|
44
|
+
result.rejected.push({ content: candidate.content, reason: 'over-budget' });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const content = candidate.content.trim();
|
|
48
|
+
if (content.length < 8) {
|
|
49
|
+
result.rejected.push({ content, reason: 'short' });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const tokens = normalizeTokens(content);
|
|
53
|
+
// Two near-identical candidates inside one batch: keep the first.
|
|
54
|
+
if (seenThisTurn.some((seen) => similarity(seen.tokens, tokens) >= gate.duplicateThreshold)) {
|
|
55
|
+
result.rejected.push({ content, reason: 'duplicate-in-batch' });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const knownEntity = candidate.tags.some((tag) => Boolean(store.findEntity(owner, tag)));
|
|
59
|
+
// A weak candidate still gets in when it talks about something the bank
|
|
60
|
+
// already knows: that is context accumulating, not noise.
|
|
61
|
+
if (candidate.importance < gate.minImportance && !knownEntity) {
|
|
62
|
+
result.rejected.push({ content, reason: 'weak' });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const neighbours = similarMemories(store, owner, content, tokens);
|
|
66
|
+
const twin = neighbours.find((entry) => entry.score >= gate.duplicateThreshold);
|
|
67
|
+
if (twin) {
|
|
68
|
+
// Same fact, different words. Reinforce what is there; keep whichever
|
|
69
|
+
// sentence carries more, and let the tags merge.
|
|
70
|
+
const kept = richer(twin.memory.content, content);
|
|
71
|
+
const reinforced = store.upsertMemory({
|
|
72
|
+
kind: twin.memory.kind,
|
|
73
|
+
content: twin.memory.content,
|
|
74
|
+
tags: [...new Set([...twin.memory.tags, ...candidate.tags])],
|
|
75
|
+
importance: Math.max(twin.memory.importance, candidate.importance),
|
|
76
|
+
owner,
|
|
77
|
+
});
|
|
78
|
+
const final = kept === twin.memory.content ? reinforced : store.updateMemory(reinforced.id, { content: kept }) ?? reinforced;
|
|
79
|
+
result.reinforced.push(final);
|
|
80
|
+
linkEntities(store, owner, final.id, candidate.tags);
|
|
81
|
+
seenThisTurn.push({ tokens, content });
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const record = store.upsertMemory({
|
|
85
|
+
kind: candidate.kind,
|
|
86
|
+
content,
|
|
87
|
+
tags: candidate.tags,
|
|
88
|
+
importance: candidate.importance,
|
|
89
|
+
owner,
|
|
90
|
+
sourceSessionId: input.sourceSessionId,
|
|
91
|
+
origin: 'extract',
|
|
92
|
+
});
|
|
93
|
+
result.stored.push(record);
|
|
94
|
+
linkEntities(store, owner, record.id, candidate.tags);
|
|
95
|
+
seenThisTurn.push({ tokens, content });
|
|
96
|
+
// Related but not the same: leave a marker for the night rather than
|
|
97
|
+
// deciding now. Condensation is a judgement call and needs a model.
|
|
98
|
+
for (const neighbour of neighbours) {
|
|
99
|
+
if (neighbour.score < gate.clusterThreshold)
|
|
100
|
+
continue;
|
|
101
|
+
const edge = store.addEdge({
|
|
102
|
+
owner,
|
|
103
|
+
srcId: record.id,
|
|
104
|
+
dstId: neighbour.memory.id,
|
|
105
|
+
relation: 'co_occurs',
|
|
106
|
+
weight: neighbour.score,
|
|
107
|
+
origin: 'gate',
|
|
108
|
+
});
|
|
109
|
+
if (edge)
|
|
110
|
+
result.queued.push(edge);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Candidates for "we may already know this", pulled through the same FTS
|
|
117
|
+
* index recall uses. Scanning the whole bank would be correct too, and far
|
|
118
|
+
* slower; anything genuinely near-identical shares enough words to be found.
|
|
119
|
+
*/
|
|
120
|
+
function similarMemories(store, owner, content, tokens) {
|
|
121
|
+
const match = toMatchQuery(content);
|
|
122
|
+
if (!match)
|
|
123
|
+
return [];
|
|
124
|
+
let rows;
|
|
125
|
+
try {
|
|
126
|
+
rows = store.db
|
|
127
|
+
.prepare(`SELECT m.* FROM memories_fts
|
|
128
|
+
JOIN memories m ON m.rowid = memories_fts.rowid
|
|
129
|
+
WHERE memories_fts MATCH ?
|
|
130
|
+
AND m.owner = ?
|
|
131
|
+
AND m.forgotten = 0
|
|
132
|
+
AND m.dormant_at IS NULL
|
|
133
|
+
LIMIT 15`)
|
|
134
|
+
.all(match, owner);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// A malformed MATCH must never cost the turn its memory.
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
return rows
|
|
141
|
+
.map((row) => {
|
|
142
|
+
const memory = mapMemory(row);
|
|
143
|
+
return { memory, score: similarity(tokens, normalizeTokens(memory.content)) };
|
|
144
|
+
})
|
|
145
|
+
.filter((entry) => entry.score > 0)
|
|
146
|
+
.sort((a, b) => b.score - a.score);
|
|
147
|
+
}
|
|
148
|
+
/** Tags become entities: the cheapest possible seed for the graph. */
|
|
149
|
+
export function linkEntities(store, owner, memoryId, tags) {
|
|
150
|
+
for (const tag of tags.slice(0, 6)) {
|
|
151
|
+
const name = tag.trim();
|
|
152
|
+
if (name.length < 2 || !entitySlug(name))
|
|
153
|
+
continue;
|
|
154
|
+
try {
|
|
155
|
+
const entity = store.upsertEntity({ owner, name });
|
|
156
|
+
store.linkEntity(memoryId, entity.id);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// An entity that will not normalise is not worth failing a turn over.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../../src/memory/gate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAc,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA4CrD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,CAAc,EAAE,CAAc;IACvD,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACjC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,CAAC;QAAE,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,CAAC,CAAC;IACrD,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED,2EAA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AC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,YAAY,CAAC,KAAY,EAAE,KAAa,EAAE,QAAgB,EAAE,IAAc;IACxF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QACnD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACnD,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,sEAAsE;QACxE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type MemoryKind, type MemoryQuery, type ScoredMemory } from '../types.js';
|
|
2
|
+
import { type Store } from './store.js';
|
|
3
|
+
/**
|
|
4
|
+
* Turn free text into a safe FTS5 MATCH expression.
|
|
5
|
+
* Every token is quoted, so punctuation can never be read as FTS syntax.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toMatchQuery(text: string): string;
|
|
8
|
+
export declare function tokenize(text: string): string[];
|
|
9
|
+
export interface RecallOptions extends MemoryQuery {
|
|
10
|
+
/** Drop candidates scoring below this. */
|
|
11
|
+
threshold?: number;
|
|
12
|
+
/** Mark the returned memories as accessed. Off for read-only inspection. */
|
|
13
|
+
touch?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Reach past the literal match through the graph. On by default; the
|
|
16
|
+
* inspector switches it off so a search shows what actually matched.
|
|
17
|
+
*/
|
|
18
|
+
expand?: boolean;
|
|
19
|
+
/** Score a memory inherits through a shared entity. */
|
|
20
|
+
hopEntity?: number;
|
|
21
|
+
/** Score a memory inherits through a `refines` or `caused_by` edge. */
|
|
22
|
+
hopEdge?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find the memories worth putting in front of the model for this turn.
|
|
26
|
+
* Returns an empty array for an unsearchable query rather than dumping
|
|
27
|
+
* everything, so a greeting does not drag in the whole memory bank.
|
|
28
|
+
*/
|
|
29
|
+
export declare function recall(store: Store, options: RecallOptions): ScoredMemory[];
|
|
30
|
+
/**
|
|
31
|
+
* Of a pair that cannot both be true, only the newer one goes into a prompt.
|
|
32
|
+
* The older one stays in the bank and stays visible in the inspector - the
|
|
33
|
+
* night reports contradictions, it never decides them, and neither does this.
|
|
34
|
+
*/
|
|
35
|
+
export declare function dropContradicted(store: Store, memories: ScoredMemory[]): ScoredMemory[];
|
|
36
|
+
/**
|
|
37
|
+
* The memories that belong in every turn regardless of the question.
|
|
38
|
+
*
|
|
39
|
+
* Lexical recall can only match words that are actually present, so a
|
|
40
|
+
* question about a category ("which programming language do I prefer?") will
|
|
41
|
+
* never match a memory naming the instance ("works mainly with TypeScript").
|
|
42
|
+
* A small, high-importance profile carried in every turn closes that gap far
|
|
43
|
+
* more cheaply than an embedding model would, and it is what makes the
|
|
44
|
+
* assistant feel like it knows you rather than like it is running a search.
|
|
45
|
+
*/
|
|
46
|
+
export declare function coreProfile(store: Store, options?: {
|
|
47
|
+
limit?: number;
|
|
48
|
+
minImportance?: number;
|
|
49
|
+
owner?: string;
|
|
50
|
+
}): ScoredMemory[];
|
|
51
|
+
/**
|
|
52
|
+
* Format recalled memories as the block injected into the system prompt.
|
|
53
|
+
*
|
|
54
|
+
* Grouped by entity when a store is available: a model reads "Rookery: three
|
|
55
|
+
* things" far better than twelve unrelated bullets, and the grouping is the
|
|
56
|
+
* only place the graph becomes visible to the model at all. Without a store
|
|
57
|
+
* it falls back to the flat list, which is what the tests and the CLI use.
|
|
58
|
+
*/
|
|
59
|
+
export declare function renderMemoryBlock(memories: ScoredMemory[], budget?: number, subject?: string, store?: Store): string;
|
|
60
|
+
export declare const MEMORY_KINDS: MemoryKind[];
|
|
61
|
+
//# sourceMappingURL=recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.d.ts","sourceRoot":"","sources":["../../src/memory/recall.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,WAAW,EAEhB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAgCnD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKjD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ/C;AAED,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,GAAG,YAAY,EAAE,CAmF3E;AA4DD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAiBvF;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GACvE,YAAY,EAAE,CA0BhB;AAYD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,YAAY,EAAE,EACxB,MAAM,SAAO,EACb,OAAO,SAAc,EACrB,KAAK,CAAC,EAAE,KAAK,GACZ,MAAM,CAuCR;AAqCD,eAAO,MAAM,YAAY,EAAE,UAAU,EAOpC,CAAC"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { ASSISTANT_MEMORY_OWNER, } from '../types.js';
|
|
2
|
+
import { mapMemory } from './store.js';
|
|
3
|
+
/**
|
|
4
|
+
* Memory recall.
|
|
5
|
+
*
|
|
6
|
+
* A memory surfaces on a blend of four signals rather than raw text match
|
|
7
|
+
* alone, because for a personal assistant "what matters" is not the same as
|
|
8
|
+
* "what shares words with the question":
|
|
9
|
+
*
|
|
10
|
+
* relevance - FTS5 BM25 over content and tags
|
|
11
|
+
* importance - how much weight the memory was given when stored
|
|
12
|
+
* recency - exponential decay, halving roughly every 30 days
|
|
13
|
+
* usage - log-scaled access count, so proven-useful memories stick
|
|
14
|
+
*
|
|
15
|
+
* Every query is scoped to one owner: the assistant's bank by default, or
|
|
16
|
+
* one agent's. An agent never sees what the assistant knows about the user
|
|
17
|
+
* and the assistant never recalls an agent's working notes.
|
|
18
|
+
*/
|
|
19
|
+
const WEIGHTS = { relevance: 0.55, importance: 0.2, recency: 0.15, usage: 0.1 };
|
|
20
|
+
const RECENCY_HALF_LIFE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
21
|
+
/** Words too common to narrow anything down, in the two languages Rookery targets. */
|
|
22
|
+
const STOP_WORDS = new Set([
|
|
23
|
+
'the', 'a', 'an', 'and', 'or', 'but', 'is', 'are', 'was', 'were', 'be', 'been', 'to', 'of',
|
|
24
|
+
'in', 'on', 'at', 'for', 'with', 'my', 'me', 'i', 'you', 'it', 'that', 'this', 'do', 'does',
|
|
25
|
+
'did', 'what', 'how', 'why', 'when', 'can', 'could', 'would', 'should', 'please',
|
|
26
|
+
'der', 'die', 'das', 'und', 'oder', 'ist', 'sind', 'war', 'ein', 'eine', 'einen', 'zu', 'von',
|
|
27
|
+
'im', 'in', 'am', 'auf', 'fuer', 'für', 'mit', 'mein', 'meine', 'mir', 'mich', 'ich', 'du',
|
|
28
|
+
'es', 'dass', 'was', 'wie', 'warum', 'wann', 'kann', 'koennte', 'bitte', 'nicht', 'den', 'dem',
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Turn free text into a safe FTS5 MATCH expression.
|
|
32
|
+
* Every token is quoted, so punctuation can never be read as FTS syntax.
|
|
33
|
+
*/
|
|
34
|
+
export function toMatchQuery(text) {
|
|
35
|
+
const tokens = tokenize(text);
|
|
36
|
+
if (!tokens.length)
|
|
37
|
+
return '';
|
|
38
|
+
// Prefix-match the tokens so "deploy" also finds "deployment".
|
|
39
|
+
return tokens.map((token) => '"' + token + '"*').join(' OR ');
|
|
40
|
+
}
|
|
41
|
+
export function tokenize(text) {
|
|
42
|
+
return text
|
|
43
|
+
.toLowerCase()
|
|
44
|
+
.normalize('NFKD')
|
|
45
|
+
.replace(/[^\p{L}\p{N}\s-]/gu, ' ')
|
|
46
|
+
.split(/[\s-]+/)
|
|
47
|
+
.filter((token) => token.length > 2 && !STOP_WORDS.has(token))
|
|
48
|
+
.slice(0, 24);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Find the memories worth putting in front of the model for this turn.
|
|
52
|
+
* Returns an empty array for an unsearchable query rather than dumping
|
|
53
|
+
* everything, so a greeting does not drag in the whole memory bank.
|
|
54
|
+
*/
|
|
55
|
+
export function recall(store, options) {
|
|
56
|
+
const limit = options.limit ?? 8;
|
|
57
|
+
const threshold = options.threshold ?? 0.12;
|
|
58
|
+
const owner = options.owner ?? ASSISTANT_MEMORY_OWNER;
|
|
59
|
+
const match = toMatchQuery(options.text);
|
|
60
|
+
if (!match)
|
|
61
|
+
return [];
|
|
62
|
+
const kinds = options.kinds ?? [];
|
|
63
|
+
const kindFilter = kinds.length ? ' AND m.kind IN (' + kinds.map(() => '?').join(', ') + ')' : '';
|
|
64
|
+
// bm25() returns a negative number where lower is better; negate it so the
|
|
65
|
+
// scale runs the same direction as every other signal.
|
|
66
|
+
const sql = `SELECT m.*, -bm25(memories_fts, 1.0, 0.5) AS relevance
|
|
67
|
+
FROM memories_fts
|
|
68
|
+
JOIN memories m ON m.rowid = memories_fts.rowid
|
|
69
|
+
WHERE memories_fts MATCH ?
|
|
70
|
+
AND m.owner = ?
|
|
71
|
+
AND m.forgotten = 0
|
|
72
|
+
AND m.dormant_at IS NULL
|
|
73
|
+
AND m.superseded_by IS NULL
|
|
74
|
+
AND m.importance >= ?` +
|
|
75
|
+
kindFilter +
|
|
76
|
+
` ORDER BY relevance DESC LIMIT ?`;
|
|
77
|
+
let rows;
|
|
78
|
+
try {
|
|
79
|
+
rows = store.db
|
|
80
|
+
.prepare(sql)
|
|
81
|
+
.all(match, owner, options.minImportance ?? 0, ...kinds, limit * 4);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// A malformed MATCH should degrade to "no memories", never break the turn.
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
const maxRelevance = Math.max(...rows.map((row) => Number(row.relevance) || 0), 1);
|
|
89
|
+
const queryTokens = new Set(tokenize(options.text));
|
|
90
|
+
const scored = rows.map((row) => {
|
|
91
|
+
const record = mapMemory(row);
|
|
92
|
+
const relevance = (Number(row.relevance) || 0) / maxRelevance;
|
|
93
|
+
const recency = Math.pow(0.5, (now - record.updatedAt) / RECENCY_HALF_LIFE_MS);
|
|
94
|
+
const usage = Math.min(1, Math.log2(record.accessCount + 1) / 5);
|
|
95
|
+
// A memory whose tag the user just said is almost certainly on topic.
|
|
96
|
+
const tagHit = record.tags.some((tag) => queryTokens.has(tag.toLowerCase())) ? 0.1 : 0;
|
|
97
|
+
const score = WEIGHTS.relevance * relevance +
|
|
98
|
+
WEIGHTS.importance * record.importance +
|
|
99
|
+
WEIGHTS.recency * recency +
|
|
100
|
+
WEIGHTS.usage * usage +
|
|
101
|
+
tagHit;
|
|
102
|
+
return {
|
|
103
|
+
...record,
|
|
104
|
+
score,
|
|
105
|
+
hop: 'direct',
|
|
106
|
+
reason: describe(relevance, record.importance, recency, tagHit > 0),
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
const direct = scored.filter((memory) => memory.score >= threshold).sort((a, b) => b.score - a.score);
|
|
110
|
+
// The second hop: what the question could not say in words. Only the best
|
|
111
|
+
// few direct hits get to pull neighbours in, so a vague question does not
|
|
112
|
+
// drag the whole bank along behind it.
|
|
113
|
+
const expanded = options.expand === false ? [] : expand(store, owner, direct.slice(0, 3), options);
|
|
114
|
+
const byId = new Map();
|
|
115
|
+
for (const memory of [...direct, ...expanded]) {
|
|
116
|
+
const existing = byId.get(memory.id);
|
|
117
|
+
// Maximum, never a sum: reaching the same memory two ways is one memory.
|
|
118
|
+
if (!existing || memory.score > existing.score)
|
|
119
|
+
byId.set(memory.id, memory);
|
|
120
|
+
}
|
|
121
|
+
const top = [...byId.values()].sort((a, b) => b.score - a.score).slice(0, limit);
|
|
122
|
+
if (options.touch !== false && top.length) {
|
|
123
|
+
store.touchMemories(top.map((memory) => memory.id));
|
|
124
|
+
}
|
|
125
|
+
return top;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Pull in what the direct hits are connected to.
|
|
129
|
+
*
|
|
130
|
+
* This is what closes the gap lexical search cannot: "which language do I
|
|
131
|
+
* prefer?" shares no word with "works mainly with TypeScript", but both hang
|
|
132
|
+
* off the entity `typescript`. Common entities are damped - one that half the
|
|
133
|
+
* bank mentions says nothing about this question in particular.
|
|
134
|
+
*/
|
|
135
|
+
function expand(store, owner, seeds, options) {
|
|
136
|
+
if (!seeds.length)
|
|
137
|
+
return [];
|
|
138
|
+
const hopEntity = options.hopEntity ?? 0.45;
|
|
139
|
+
const hopEdge = options.hopEdge ?? 0.6;
|
|
140
|
+
const seedIds = seeds.map((memory) => memory.id);
|
|
141
|
+
const out = new Map();
|
|
142
|
+
const offer = (record, score, hop, reason) => {
|
|
143
|
+
if (seedIds.includes(record.id))
|
|
144
|
+
return;
|
|
145
|
+
if (record.forgotten || record.dormantAt || record.supersededBy)
|
|
146
|
+
return;
|
|
147
|
+
const existing = out.get(record.id);
|
|
148
|
+
if (existing && existing.score >= score)
|
|
149
|
+
return;
|
|
150
|
+
out.set(record.id, { ...record, score, hop, reason });
|
|
151
|
+
};
|
|
152
|
+
for (const seed of seeds) {
|
|
153
|
+
const entities = store.entitiesFor(seed.id);
|
|
154
|
+
for (const entity of entities) {
|
|
155
|
+
if (entity.mentions <= 1)
|
|
156
|
+
continue;
|
|
157
|
+
const damping = Math.min(1, 3 / Math.max(1, entity.mentions));
|
|
158
|
+
const inherited = hopEntity * seed.score * damping;
|
|
159
|
+
if (inherited < (options.threshold ?? 0.12) * 0.5)
|
|
160
|
+
continue;
|
|
161
|
+
for (const record of store.memoriesForEntities([entity.id], { exclude: seedIds, limit: 8 })) {
|
|
162
|
+
offer(record, inherited * (0.6 + 0.4 * record.importance), 'entity', 'connected through ' + entity.name);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const edges = store.edgesFrom(seedIds, ['refines', 'caused_by']);
|
|
167
|
+
for (const edge of edges) {
|
|
168
|
+
const seed = seeds.find((memory) => memory.id === edge.srcId);
|
|
169
|
+
if (!seed)
|
|
170
|
+
continue;
|
|
171
|
+
const record = store.getMemory(edge.dstId);
|
|
172
|
+
if (!record || record.owner !== owner)
|
|
173
|
+
continue;
|
|
174
|
+
offer(record, hopEdge * seed.score * edge.weight, 'edge', edge.relation === 'refines' ? 'refines a match' : 'explains a match');
|
|
175
|
+
}
|
|
176
|
+
return [...out.values()];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Of a pair that cannot both be true, only the newer one goes into a prompt.
|
|
180
|
+
* The older one stays in the bank and stays visible in the inspector - the
|
|
181
|
+
* night reports contradictions, it never decides them, and neither does this.
|
|
182
|
+
*/
|
|
183
|
+
export function dropContradicted(store, memories) {
|
|
184
|
+
if (memories.length < 2)
|
|
185
|
+
return memories;
|
|
186
|
+
const ids = memories.map((memory) => memory.id);
|
|
187
|
+
const edges = store.edgesFrom(ids, ['contradicts']);
|
|
188
|
+
if (!edges.length)
|
|
189
|
+
return memories;
|
|
190
|
+
const loser = new Set();
|
|
191
|
+
for (const edge of edges) {
|
|
192
|
+
const a = memories.find((memory) => memory.id === edge.srcId);
|
|
193
|
+
const b = memories.find((memory) => memory.id === edge.dstId);
|
|
194
|
+
if (!a || !b)
|
|
195
|
+
continue;
|
|
196
|
+
loser.add(a.updatedAt >= b.updatedAt ? b.id : a.id);
|
|
197
|
+
}
|
|
198
|
+
return memories.map((memory) => loser.has(memory.id)
|
|
199
|
+
? { ...memory, reason: memory.reason + ', outdated by a newer note' }
|
|
200
|
+
: memory).filter((memory) => !loser.has(memory.id));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The memories that belong in every turn regardless of the question.
|
|
204
|
+
*
|
|
205
|
+
* Lexical recall can only match words that are actually present, so a
|
|
206
|
+
* question about a category ("which programming language do I prefer?") will
|
|
207
|
+
* never match a memory naming the instance ("works mainly with TypeScript").
|
|
208
|
+
* A small, high-importance profile carried in every turn closes that gap far
|
|
209
|
+
* more cheaply than an embedding model would, and it is what makes the
|
|
210
|
+
* assistant feel like it knows you rather than like it is running a search.
|
|
211
|
+
*/
|
|
212
|
+
export function coreProfile(store, options = {}) {
|
|
213
|
+
const limit = options.limit ?? 5;
|
|
214
|
+
const minImportance = options.minImportance ?? 0.7;
|
|
215
|
+
const owner = options.owner ?? ASSISTANT_MEMORY_OWNER;
|
|
216
|
+
// Pinned first, then insights, then plain weight: what the user fixed in
|
|
217
|
+
// place and what the nights concluded outrank whatever scored highest.
|
|
218
|
+
const rows = store.db
|
|
219
|
+
.prepare(`SELECT * FROM memories
|
|
220
|
+
WHERE owner = ? AND forgotten = 0 AND dormant_at IS NULL AND superseded_by IS NULL
|
|
221
|
+
AND (importance >= ? OR pinned = 1)
|
|
222
|
+
ORDER BY pinned DESC, (kind = 'insight') DESC, importance DESC, updated_at DESC
|
|
223
|
+
LIMIT ?`)
|
|
224
|
+
.all(owner, minImportance, limit);
|
|
225
|
+
return rows.map((row) => {
|
|
226
|
+
const record = mapMemory(row);
|
|
227
|
+
return {
|
|
228
|
+
...record,
|
|
229
|
+
score: 1,
|
|
230
|
+
hop: 'direct',
|
|
231
|
+
reason: record.pinned ? 'pinned' : record.kind === 'insight' ? 'insight' : 'core profile',
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function describe(relevance, importance, recency, taggedHit) {
|
|
236
|
+
const parts = [];
|
|
237
|
+
if (relevance > 0.6)
|
|
238
|
+
parts.push('strong text match');
|
|
239
|
+
else if (relevance > 0.25)
|
|
240
|
+
parts.push('text match');
|
|
241
|
+
if (importance >= 0.75)
|
|
242
|
+
parts.push('high importance');
|
|
243
|
+
if (recency > 0.7)
|
|
244
|
+
parts.push('recent');
|
|
245
|
+
if (taggedHit)
|
|
246
|
+
parts.push('tag hit');
|
|
247
|
+
return parts.length ? parts.join(', ') : 'weak match';
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Format recalled memories as the block injected into the system prompt.
|
|
251
|
+
*
|
|
252
|
+
* Grouped by entity when a store is available: a model reads "Rookery: three
|
|
253
|
+
* things" far better than twelve unrelated bullets, and the grouping is the
|
|
254
|
+
* only place the graph becomes visible to the model at all. Without a store
|
|
255
|
+
* it falls back to the flat list, which is what the tests and the CLI use.
|
|
256
|
+
*/
|
|
257
|
+
export function renderMemoryBlock(memories, budget = 2000, subject = 'this user', store) {
|
|
258
|
+
if (!memories.length)
|
|
259
|
+
return '';
|
|
260
|
+
const lines = [];
|
|
261
|
+
let used = 0;
|
|
262
|
+
const push = (line) => {
|
|
263
|
+
if (used + line.length > budget)
|
|
264
|
+
return false;
|
|
265
|
+
lines.push(line);
|
|
266
|
+
used += line.length + 1;
|
|
267
|
+
return true;
|
|
268
|
+
};
|
|
269
|
+
const groups = store ? groupByEntity(store, memories) : null;
|
|
270
|
+
if (groups && groups.grouped.length) {
|
|
271
|
+
for (const group of groups.grouped) {
|
|
272
|
+
if (!push(group.entity.name + ':'))
|
|
273
|
+
break;
|
|
274
|
+
let full = false;
|
|
275
|
+
for (const memory of group.memories) {
|
|
276
|
+
if (!push(' - (' + memory.kind + ') ' + memory.content)) {
|
|
277
|
+
full = true;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (full)
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
for (const memory of groups.loose) {
|
|
285
|
+
if (!push('- (' + memory.kind + ') ' + memory.content))
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
for (const memory of memories) {
|
|
291
|
+
if (!push('- (' + memory.kind + ') ' + memory.content))
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (!lines.length)
|
|
296
|
+
return '';
|
|
297
|
+
return ('What you already know about ' + subject + ' (from earlier work):\n' +
|
|
298
|
+
lines.join('\n') +
|
|
299
|
+
'\nUse this naturally. Do not announce that you are reading from memory.');
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Bucket memories under the entity that best explains them. Each memory
|
|
303
|
+
* appears once, under its rarest entity - the rarest one is the most
|
|
304
|
+
* informative, since an entity half the bank mentions groups nothing.
|
|
305
|
+
*/
|
|
306
|
+
function groupByEntity(store, memories) {
|
|
307
|
+
const buckets = new Map();
|
|
308
|
+
const loose = [];
|
|
309
|
+
for (const memory of memories) {
|
|
310
|
+
const entities = store.entitiesFor(memory.id).filter((entity) => entity.mentions > 1);
|
|
311
|
+
if (!entities.length) {
|
|
312
|
+
loose.push(memory);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const best = entities.reduce((a, b) => (a.mentions <= b.mentions ? a : b));
|
|
316
|
+
const bucket = buckets.get(best.id);
|
|
317
|
+
if (bucket)
|
|
318
|
+
bucket.memories.push(memory);
|
|
319
|
+
else
|
|
320
|
+
buckets.set(best.id, { entity: best, memories: [memory] });
|
|
321
|
+
}
|
|
322
|
+
// A group of one is not a group; it reads better as a plain line.
|
|
323
|
+
const grouped = [];
|
|
324
|
+
for (const bucket of buckets.values()) {
|
|
325
|
+
if (bucket.memories.length > 1)
|
|
326
|
+
grouped.push(bucket);
|
|
327
|
+
else
|
|
328
|
+
loose.push(...bucket.memories);
|
|
329
|
+
}
|
|
330
|
+
grouped.sort((a, b) => b.memories.length - a.memories.length);
|
|
331
|
+
loose.sort((a, b) => b.score - a.score);
|
|
332
|
+
return { grouped, loose };
|
|
333
|
+
}
|
|
334
|
+
export const MEMORY_KINDS = [
|
|
335
|
+
'fact',
|
|
336
|
+
'preference',
|
|
337
|
+
'project',
|
|
338
|
+
'event',
|
|
339
|
+
'summary',
|
|
340
|
+
'insight',
|
|
341
|
+
];
|
|
342
|
+
//# sourceMappingURL=recall.js.map
|