byterover-cli 0.3.4 → 0.4.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/README.md +119 -63
- package/bin/dev.js +8 -1
- package/bin/run.js +7 -0
- package/dist/commands/cipher-agent/run.d.ts +30 -0
- package/dist/commands/cipher-agent/run.js +123 -61
- package/dist/commands/cipher-agent/set-prompt.d.ts +2 -0
- package/dist/commands/cipher-agent/set-prompt.js +13 -8
- package/dist/commands/cipher-agent/show-prompt.d.ts +2 -0
- package/dist/commands/cipher-agent/show-prompt.js +17 -12
- package/dist/commands/curate.d.ts +3 -60
- package/dist/commands/curate.js +45 -341
- package/dist/commands/foo.d.ts +4 -2
- package/dist/commands/foo.js +21 -16
- package/dist/commands/main.d.ts +9 -0
- package/dist/commands/main.js +34 -0
- package/dist/commands/query.d.ts +2 -48
- package/dist/commands/query.js +19 -287
- package/dist/commands/status.d.ts +2 -13
- package/dist/commands/status.js +12 -91
- package/dist/commands/watch.d.ts +2 -0
- package/dist/commands/watch.js +23 -19
- package/dist/config/environment.d.ts +1 -1
- package/dist/config/environment.js +2 -2
- package/dist/constants.d.ts +4 -5
- package/dist/constants.js +5 -5
- package/dist/core/domain/cipher/errors/storage-error.d.ts +89 -0
- package/dist/core/domain/cipher/errors/storage-error.js +130 -0
- package/dist/core/domain/cipher/queue/types.d.ts +71 -0
- package/dist/core/domain/cipher/queue/types.js +9 -0
- package/dist/core/domain/cipher/storage/message-storage-types.d.ts +218 -0
- package/dist/core/domain/cipher/storage/message-storage-types.js +18 -0
- package/dist/core/domain/cipher/tools/constants.d.ts +1 -0
- package/dist/core/domain/cipher/tools/constants.js +1 -0
- package/dist/core/domain/entities/event.d.ts +1 -1
- package/dist/core/domain/entities/event.js +5 -0
- package/dist/core/domain/entities/global-config.d.ts +36 -0
- package/dist/core/domain/entities/global-config.js +66 -0
- package/dist/core/domain/knowledge/directory-manager.d.ts +10 -0
- package/dist/core/domain/knowledge/directory-manager.js +18 -0
- package/dist/core/domain/knowledge/markdown-writer.d.ts +9 -0
- package/dist/core/domain/knowledge/markdown-writer.js +51 -1
- package/dist/core/interfaces/cipher/i-agent-storage.d.ts +152 -0
- package/dist/core/interfaces/cipher/i-agent-storage.js +1 -0
- package/dist/core/interfaces/cipher/i-cipher-agent.d.ts +2 -0
- package/dist/core/interfaces/cipher/i-key-storage.d.ts +91 -0
- package/dist/core/interfaces/cipher/i-key-storage.js +1 -0
- package/dist/core/interfaces/i-global-config-store.d.ts +34 -0
- package/dist/core/interfaces/i-global-config-store.js +1 -0
- package/dist/core/interfaces/i-onboarding-preference-store.d.ts +20 -0
- package/dist/core/interfaces/i-onboarding-preference-store.js +1 -0
- package/dist/core/interfaces/i-terminal.d.ts +146 -0
- package/dist/core/interfaces/i-terminal.js +1 -0
- package/dist/core/interfaces/i-workspace-detector-service.d.ts +8 -0
- package/dist/core/interfaces/i-workspace-detector-service.js +1 -0
- package/dist/core/interfaces/usecase/i-clear-use-case.d.ts +6 -0
- package/dist/core/interfaces/usecase/i-clear-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-curate-use-case.d.ts +10 -0
- package/dist/core/interfaces/usecase/i-curate-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-generate-rules-use-case.d.ts +3 -0
- package/dist/core/interfaces/usecase/i-generate-rules-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-init-use-case.d.ts +5 -0
- package/dist/core/interfaces/usecase/i-init-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-login-use-case.d.ts +3 -0
- package/dist/core/interfaces/usecase/i-login-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-logout-use-case.d.ts +5 -0
- package/dist/core/interfaces/usecase/i-logout-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-pull-use-case.d.ts +5 -0
- package/dist/core/interfaces/usecase/i-pull-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-push-use-case.d.ts +6 -0
- package/dist/core/interfaces/usecase/i-push-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-query-use-case.d.ts +9 -0
- package/dist/core/interfaces/usecase/i-query-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-space-list-use-case.d.ts +3 -0
- package/dist/core/interfaces/usecase/i-space-list-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-space-switch-use-case.d.ts +3 -0
- package/dist/core/interfaces/usecase/i-space-switch-use-case.js +1 -0
- package/dist/core/interfaces/usecase/i-status-use-case.d.ts +5 -0
- package/dist/core/interfaces/usecase/i-status-use-case.js +1 -0
- package/dist/hooks/init/update-notifier.js +1 -5
- package/dist/hooks/init/welcome.js +1 -2
- package/dist/infra/cipher/agent-service-factory.d.ts +13 -6
- package/dist/infra/cipher/agent-service-factory.js +40 -16
- package/dist/infra/cipher/cipher-agent.js +4 -4
- package/dist/infra/cipher/consumer/consumer-lock.d.ts +20 -0
- package/dist/infra/cipher/consumer/consumer-lock.js +40 -0
- package/dist/infra/cipher/consumer/consumer-service.d.ts +99 -0
- package/dist/infra/cipher/consumer/consumer-service.js +165 -0
- package/dist/infra/cipher/consumer/execution-consumer.d.ts +121 -0
- package/dist/infra/cipher/consumer/execution-consumer.js +523 -0
- package/dist/infra/cipher/consumer/index.d.ts +33 -0
- package/dist/infra/cipher/consumer/index.js +33 -0
- package/dist/infra/cipher/consumer/queue-polling-service.d.ts +120 -0
- package/dist/infra/cipher/consumer/queue-polling-service.js +248 -0
- package/dist/infra/cipher/http/internal-llm-http-service.d.ts +94 -0
- package/dist/infra/cipher/http/internal-llm-http-service.js +118 -0
- package/dist/infra/cipher/llm/context/compaction/compaction-service.d.ts +106 -0
- package/dist/infra/cipher/llm/context/compaction/compaction-service.js +132 -0
- package/dist/infra/cipher/llm/context/compaction/index.d.ts +9 -0
- package/dist/infra/cipher/llm/context/compaction/index.js +9 -0
- package/dist/infra/cipher/llm/context/context-manager.d.ts +46 -2
- package/dist/infra/cipher/llm/context/context-manager.js +68 -4
- package/dist/infra/cipher/llm/context/rw-lock.d.ts +72 -0
- package/dist/infra/cipher/llm/context/rw-lock.js +145 -0
- package/dist/infra/cipher/llm/generators/byterover-content-generator.d.ts +7 -7
- package/dist/infra/cipher/llm/generators/byterover-content-generator.js +8 -8
- package/dist/infra/cipher/llm/internal-llm-service.js +2 -0
- package/dist/infra/cipher/session/session-manager.d.ts +4 -4
- package/dist/infra/cipher/session/session-manager.js +5 -5
- package/dist/infra/cipher/storage/agent-storage.d.ts +246 -0
- package/dist/infra/cipher/storage/agent-storage.js +956 -0
- package/dist/infra/cipher/storage/dual-format-history-storage.d.ts +77 -0
- package/dist/infra/cipher/storage/dual-format-history-storage.js +149 -0
- package/dist/infra/cipher/storage/granular-history-storage.d.ts +65 -0
- package/dist/infra/cipher/storage/granular-history-storage.js +118 -0
- package/dist/infra/cipher/storage/message-storage-service.d.ts +108 -0
- package/dist/infra/cipher/storage/message-storage-service.js +529 -0
- package/dist/infra/cipher/storage/process-utils.d.ts +16 -0
- package/dist/infra/cipher/storage/process-utils.js +43 -0
- package/dist/infra/cipher/storage/sqlite-key-storage.d.ts +105 -0
- package/dist/infra/cipher/storage/sqlite-key-storage.js +404 -0
- package/dist/infra/cipher/system-prompt/simple-prompt-factory.d.ts +1 -0
- package/dist/infra/cipher/system-prompt/simple-prompt-factory.js +7 -0
- package/dist/infra/cipher/tools/default-policy-rules.js +1 -1
- package/dist/infra/cipher/tools/implementations/curate-tool.d.ts +10 -0
- package/dist/infra/cipher/tools/implementations/curate-tool.js +371 -0
- package/dist/infra/cipher/tools/implementations/find-knowledge-topics-tool.js +11 -8
- package/dist/infra/cipher/tools/tool-manager.d.ts +8 -2
- package/dist/infra/cipher/tools/tool-manager.js +29 -2
- package/dist/infra/cipher/tools/tool-registry.js +7 -0
- package/dist/infra/http/authenticated-http-client.d.ts +21 -0
- package/dist/infra/http/authenticated-http-client.js +38 -0
- package/dist/infra/repl/commands/arg-parser.d.ts +97 -0
- package/dist/infra/repl/commands/arg-parser.js +129 -0
- package/dist/infra/repl/commands/clear-command.d.ts +5 -0
- package/dist/infra/repl/commands/clear-command.js +61 -0
- package/dist/infra/repl/commands/curate-command.d.ts +9 -0
- package/dist/infra/repl/commands/curate-command.js +88 -0
- package/dist/infra/repl/commands/gen-rules-command.d.ts +7 -0
- package/dist/infra/repl/commands/gen-rules-command.js +38 -0
- package/dist/infra/repl/commands/index.d.ts +8 -0
- package/dist/infra/repl/commands/index.js +36 -0
- package/dist/infra/repl/commands/init-command.d.ts +7 -0
- package/dist/infra/repl/commands/init-command.js +83 -0
- package/dist/infra/repl/commands/login-command.d.ts +7 -0
- package/dist/infra/repl/commands/login-command.js +50 -0
- package/dist/infra/repl/commands/logout-command.d.ts +5 -0
- package/dist/infra/repl/commands/logout-command.js +48 -0
- package/dist/infra/repl/commands/pull-command.d.ts +5 -0
- package/dist/infra/repl/commands/pull-command.js +61 -0
- package/dist/infra/repl/commands/push-command.d.ts +5 -0
- package/dist/infra/repl/commands/push-command.js +66 -0
- package/dist/infra/repl/commands/query-command.d.ts +5 -0
- package/dist/infra/repl/commands/query-command.js +66 -0
- package/dist/infra/repl/commands/space/index.d.ts +5 -0
- package/dist/infra/repl/commands/space/index.js +14 -0
- package/dist/infra/repl/commands/space/list-command.d.ts +5 -0
- package/dist/infra/repl/commands/space/list-command.js +70 -0
- package/dist/infra/repl/commands/space/switch-command.d.ts +5 -0
- package/dist/infra/repl/commands/space/switch-command.js +37 -0
- package/dist/infra/repl/commands/status-command.d.ts +5 -0
- package/dist/infra/repl/commands/status-command.js +39 -0
- package/dist/infra/repl/repl-startup.d.ts +18 -0
- package/dist/infra/repl/repl-startup.js +26 -0
- package/dist/infra/storage/file-global-config-store.d.ts +22 -0
- package/dist/infra/storage/file-global-config-store.js +65 -0
- package/dist/infra/storage/file-onboarding-preference-store.d.ts +10 -0
- package/dist/infra/storage/file-onboarding-preference-store.js +46 -0
- package/dist/infra/terminal/oclif-terminal.d.ts +19 -0
- package/dist/infra/terminal/oclif-terminal.js +60 -0
- package/dist/infra/terminal/repl-terminal.d.ts +31 -0
- package/dist/infra/terminal/repl-terminal.js +116 -0
- package/dist/infra/tracking/mixpanel-tracking-service.d.ts +11 -1
- package/dist/infra/tracking/mixpanel-tracking-service.js +18 -13
- package/dist/infra/usecase/clear-use-case.d.ts +20 -0
- package/dist/infra/usecase/clear-use-case.js +58 -0
- package/dist/infra/usecase/curate-use-case.d.ts +66 -0
- package/dist/infra/usecase/curate-use-case.js +283 -0
- package/dist/{commands/gen-rules.d.ts → infra/usecase/generate-rules-use-case.d.ts} +14 -20
- package/dist/{commands/gen-rules.js → infra/usecase/generate-rules-use-case.js} +59 -78
- package/dist/infra/usecase/init-use-case.d.ts +139 -0
- package/dist/{commands/init.js → infra/usecase/init-use-case.js} +184 -230
- package/dist/infra/usecase/login-use-case.d.ts +28 -0
- package/dist/infra/usecase/login-use-case.js +88 -0
- package/dist/infra/usecase/logout-use-case.d.ts +22 -0
- package/dist/infra/usecase/logout-use-case.js +51 -0
- package/dist/infra/usecase/pull-use-case.d.ts +35 -0
- package/dist/infra/usecase/pull-use-case.js +89 -0
- package/dist/infra/usecase/push-use-case.d.ts +37 -0
- package/dist/infra/usecase/push-use-case.js +124 -0
- package/dist/infra/usecase/query-use-case.d.ts +78 -0
- package/dist/infra/usecase/query-use-case.js +401 -0
- package/dist/infra/usecase/space-list-use-case.d.ts +27 -0
- package/dist/infra/usecase/space-list-use-case.js +64 -0
- package/dist/infra/usecase/space-switch-use-case.d.ts +36 -0
- package/dist/infra/usecase/space-switch-use-case.js +140 -0
- package/dist/infra/usecase/status-use-case.d.ts +27 -0
- package/dist/infra/usecase/status-use-case.js +97 -0
- package/dist/infra/workspace/workspace-detector-service.d.ts +3 -6
- package/dist/resources/prompts/curate-context-tree-curation.yml +23 -11
- package/dist/resources/prompts/query-context-tree-retrieval.yml +3 -4
- package/dist/resources/prompts/system-prompt.yml +1 -1
- package/dist/resources/prompts/tool-outputs.yml +4 -3
- package/dist/templates/sections/command-reference.md +12 -0
- package/dist/templates/sections/workflow.md +10 -1
- package/dist/tui/app.d.ts +9 -0
- package/dist/tui/app.js +26 -0
- package/dist/tui/components/enter-prompt.d.ts +13 -0
- package/dist/tui/components/enter-prompt.js +15 -0
- package/dist/tui/components/execution/execution-changes.d.ts +14 -0
- package/dist/tui/components/execution/execution-changes.js +15 -0
- package/dist/tui/components/execution/execution-content.d.ts +25 -0
- package/dist/tui/components/execution/execution-content.js +67 -0
- package/dist/tui/components/execution/execution-input.d.ts +12 -0
- package/dist/tui/components/execution/execution-input.js +16 -0
- package/dist/tui/components/execution/execution-progress.d.ts +21 -0
- package/dist/tui/components/execution/execution-progress.js +21 -0
- package/dist/tui/components/execution/execution-status.d.ts +13 -0
- package/dist/tui/components/execution/execution-status.js +19 -0
- package/dist/tui/components/execution/index.d.ts +11 -0
- package/dist/tui/components/execution/index.js +11 -0
- package/dist/tui/components/execution/log-item.d.ts +17 -0
- package/dist/tui/components/execution/log-item.js +25 -0
- package/dist/tui/components/footer.d.ts +5 -0
- package/dist/tui/components/footer.js +12 -0
- package/dist/tui/components/header.d.ts +18 -0
- package/dist/tui/components/header.js +18 -0
- package/dist/tui/components/index.d.ts +17 -0
- package/dist/tui/components/index.js +14 -0
- package/dist/tui/components/inline-prompts/index.d.ts +15 -0
- package/dist/tui/components/inline-prompts/index.js +10 -0
- package/dist/tui/components/inline-prompts/inline-confirm.d.ts +17 -0
- package/dist/tui/components/inline-prompts/inline-confirm.js +32 -0
- package/dist/tui/components/inline-prompts/inline-file-selector.d.ts +43 -0
- package/dist/tui/components/inline-prompts/inline-file-selector.js +185 -0
- package/dist/tui/components/inline-prompts/inline-input.d.ts +19 -0
- package/dist/tui/components/inline-prompts/inline-input.js +32 -0
- package/dist/tui/components/inline-prompts/inline-search.d.ts +20 -0
- package/dist/tui/components/inline-prompts/inline-search.js +50 -0
- package/dist/tui/components/inline-prompts/inline-select.d.ts +20 -0
- package/dist/tui/components/inline-prompts/inline-select.js +34 -0
- package/dist/tui/components/logo.d.ts +43 -0
- package/dist/tui/components/logo.js +103 -0
- package/dist/tui/components/message-item.d.ts +12 -0
- package/dist/tui/components/message-item.js +12 -0
- package/dist/tui/components/onboarding/copyable-prompt.d.ts +15 -0
- package/dist/tui/components/onboarding/copyable-prompt.js +65 -0
- package/dist/tui/components/onboarding/index.d.ts +7 -0
- package/dist/tui/components/onboarding/index.js +6 -0
- package/dist/tui/components/onboarding/onboarding-flow.d.ts +13 -0
- package/dist/tui/components/onboarding/onboarding-flow.js +304 -0
- package/dist/tui/components/onboarding/onboarding-step.d.ts +23 -0
- package/dist/tui/components/onboarding/onboarding-step.js +12 -0
- package/dist/tui/components/output-log.d.ts +14 -0
- package/dist/tui/components/output-log.js +13 -0
- package/dist/tui/components/scrollable-list.d.ts +30 -0
- package/dist/tui/components/scrollable-list.js +121 -0
- package/dist/tui/components/suggestions.d.ts +16 -0
- package/dist/tui/components/suggestions.js +162 -0
- package/dist/tui/components/tab-bar.d.ts +10 -0
- package/dist/tui/components/tab-bar.js +12 -0
- package/dist/tui/constants.d.ts +11 -0
- package/dist/tui/constants.js +13 -0
- package/dist/tui/contexts/auth-context.d.ts +30 -0
- package/dist/tui/contexts/auth-context.js +153 -0
- package/dist/tui/contexts/consumer.d.ts +31 -0
- package/dist/tui/contexts/consumer.js +56 -0
- package/dist/tui/contexts/index.d.ts +6 -0
- package/dist/tui/contexts/index.js +6 -0
- package/dist/tui/contexts/onboarding-context.d.ts +43 -0
- package/dist/tui/contexts/onboarding-context.js +181 -0
- package/dist/tui/contexts/services-context.d.ts +29 -0
- package/dist/tui/contexts/services-context.js +20 -0
- package/dist/tui/contexts/use-commands.d.ts +29 -0
- package/dist/tui/contexts/use-commands.js +53 -0
- package/dist/tui/contexts/use-mode.d.ts +43 -0
- package/dist/tui/contexts/use-mode.js +76 -0
- package/dist/tui/contexts/use-theme.d.ts +53 -0
- package/dist/tui/contexts/use-theme.js +60 -0
- package/dist/tui/hooks/index.d.ts +17 -0
- package/dist/tui/hooks/index.js +14 -0
- package/dist/tui/hooks/use-activity-logs.d.ts +26 -0
- package/dist/tui/hooks/use-activity-logs.js +90 -0
- package/dist/tui/hooks/use-consumer.d.ts +12 -0
- package/dist/tui/hooks/use-consumer.js +50 -0
- package/dist/tui/hooks/use-onboarding.d.ts +7 -0
- package/dist/tui/hooks/use-onboarding.js +6 -0
- package/dist/tui/hooks/use-queue-polling.d.ts +31 -0
- package/dist/tui/hooks/use-queue-polling.js +90 -0
- package/dist/tui/hooks/use-slash-command-processor.d.ts +16 -0
- package/dist/tui/hooks/use-slash-command-processor.js +132 -0
- package/dist/tui/hooks/use-slash-completion.d.ts +30 -0
- package/dist/tui/hooks/use-slash-completion.js +230 -0
- package/dist/tui/hooks/use-tab-navigation.d.ts +10 -0
- package/dist/tui/hooks/use-tab-navigation.js +35 -0
- package/dist/tui/hooks/use-visible-window.d.ts +22 -0
- package/dist/tui/hooks/use-visible-window.js +37 -0
- package/dist/tui/index.d.ts +1 -0
- package/dist/tui/index.js +1 -0
- package/dist/tui/providers/app-providers.d.ts +25 -0
- package/dist/tui/providers/app-providers.js +9 -0
- package/dist/tui/types/commands.d.ts +252 -0
- package/dist/tui/types/commands.js +16 -0
- package/dist/tui/types/dialogs.d.ts +37 -0
- package/dist/tui/types/dialogs.js +4 -0
- package/dist/tui/types/index.d.ts +11 -0
- package/dist/tui/types/index.js +7 -0
- package/dist/tui/types/messages.d.ts +55 -0
- package/dist/tui/types/messages.js +4 -0
- package/dist/tui/types/prompts.d.ts +100 -0
- package/dist/tui/types/prompts.js +4 -0
- package/dist/tui/types/ui.d.ts +14 -0
- package/dist/tui/types/ui.js +4 -0
- package/dist/tui/types.d.ts +1 -0
- package/dist/tui/types.js +1 -0
- package/dist/tui/views/command-view.d.ts +12 -0
- package/dist/tui/views/command-view.js +451 -0
- package/dist/tui/views/index.d.ts +6 -0
- package/dist/tui/views/index.js +6 -0
- package/dist/tui/views/login-view.d.ts +10 -0
- package/dist/tui/views/login-view.js +30 -0
- package/dist/tui/views/logs-view.d.ts +11 -0
- package/dist/tui/views/logs-view.js +73 -0
- package/dist/utils/file-validator.d.ts +16 -0
- package/dist/utils/file-validator.js +81 -0
- package/dist/utils/global-config-path.d.ts +15 -0
- package/dist/utils/global-config-path.js +38 -0
- package/oclif.manifest.json +29 -315
- package/package.json +11 -4
- package/dist/commands/clear.d.ts +0 -19
- package/dist/commands/clear.js +0 -78
- package/dist/commands/init.d.ts +0 -130
- package/dist/commands/login.d.ts +0 -22
- package/dist/commands/login.js +0 -108
- package/dist/commands/logout.d.ts +0 -16
- package/dist/commands/logout.js +0 -61
- package/dist/commands/pull.d.ts +0 -33
- package/dist/commands/pull.js +0 -115
- package/dist/commands/push.d.ts +0 -35
- package/dist/commands/push.js +0 -160
- package/dist/commands/space/list.d.ts +0 -25
- package/dist/commands/space/list.js +0 -114
- package/dist/commands/space/switch.d.ts +0 -36
- package/dist/commands/space/switch.js +0 -160
- package/dist/infra/cipher/grpc/internal-llm-grpc-service.d.ts +0 -149
- package/dist/infra/cipher/grpc/internal-llm-grpc-service.js +0 -364
- package/dist/infra/cipher/grpc/internal-llm-grpc.proto +0 -94
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for granular message and part storage.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the storage format for the new granular history system,
|
|
5
|
+
* where messages and parts are stored separately to enable:
|
|
6
|
+
* - Streaming message loading (newest to oldest)
|
|
7
|
+
* - Selective tool output pruning
|
|
8
|
+
* - Compaction boundary markers
|
|
9
|
+
*
|
|
10
|
+
* Storage key structure:
|
|
11
|
+
* - ["session", sessionId] → SessionRecord
|
|
12
|
+
* - ["message", sessionId, messageId] → StoredMessage
|
|
13
|
+
* - ["part", messageId, partId] → StoredPart
|
|
14
|
+
*/
|
|
15
|
+
import type { ToolCall } from '../../../interfaces/cipher/message-types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Session-level record stored at ["session", sessionId].
|
|
18
|
+
* Contains metadata and acts as a marker for granular format detection.
|
|
19
|
+
*/
|
|
20
|
+
export interface SessionRecord {
|
|
21
|
+
/** Unix timestamp when session was created */
|
|
22
|
+
createdAt: number;
|
|
23
|
+
/** ID of the latest compaction boundary message, if any */
|
|
24
|
+
lastCompactionMessageId?: string;
|
|
25
|
+
/** Total number of messages in the session */
|
|
26
|
+
messageCount: number;
|
|
27
|
+
/** ID of the most recent message for efficient iteration */
|
|
28
|
+
newestMessageId?: string;
|
|
29
|
+
/** ID of the oldest message for complete traversal */
|
|
30
|
+
oldestMessageId?: string;
|
|
31
|
+
/** Unique session identifier */
|
|
32
|
+
sessionId: string;
|
|
33
|
+
/** Optional user-provided or auto-generated title */
|
|
34
|
+
title?: string;
|
|
35
|
+
/** Unix timestamp of last update */
|
|
36
|
+
updatedAt: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Individual message stored at ["message", sessionId, messageId].
|
|
40
|
+
*
|
|
41
|
+
* Messages are stored individually to enable:
|
|
42
|
+
* - Streaming from newest to oldest
|
|
43
|
+
* - Efficient single-message updates
|
|
44
|
+
* - Compaction boundary markers
|
|
45
|
+
*/
|
|
46
|
+
export interface StoredMessage {
|
|
47
|
+
/**
|
|
48
|
+
* Flag indicating this is a compaction boundary.
|
|
49
|
+
* When loading history, stop at the first compaction boundary.
|
|
50
|
+
* Messages before this point are summarized and not needed.
|
|
51
|
+
*/
|
|
52
|
+
compactionBoundary?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Summary content if this is a compaction boundary message.
|
|
55
|
+
* Contains the LLM-generated summary of prior conversation.
|
|
56
|
+
*/
|
|
57
|
+
compactionSummary?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The text content of the message.
|
|
60
|
+
* - null for assistant messages with only tool calls
|
|
61
|
+
* - string for most messages
|
|
62
|
+
*/
|
|
63
|
+
content: null | string;
|
|
64
|
+
/** Unix timestamp when message was created */
|
|
65
|
+
createdAt: number;
|
|
66
|
+
/** Unique message identifier (UUID) */
|
|
67
|
+
id: string;
|
|
68
|
+
/**
|
|
69
|
+
* Name of the tool that produced this result.
|
|
70
|
+
* Only present for tool messages.
|
|
71
|
+
*/
|
|
72
|
+
name?: string;
|
|
73
|
+
/** ID of the next message (toward newest) for linked traversal */
|
|
74
|
+
nextMessageId?: string;
|
|
75
|
+
/** IDs of parts associated with this message, in order */
|
|
76
|
+
partIds: string[];
|
|
77
|
+
/** ID of the previous message (toward oldest) for linked traversal */
|
|
78
|
+
prevMessageId?: string;
|
|
79
|
+
/** Optional reasoning text from the model */
|
|
80
|
+
reasoning?: string;
|
|
81
|
+
/** Message role */
|
|
82
|
+
role: 'assistant' | 'system' | 'tool' | 'user';
|
|
83
|
+
/** Session this message belongs to */
|
|
84
|
+
sessionId: string;
|
|
85
|
+
/** Raw thought text from the model (Gemini) */
|
|
86
|
+
thought?: string;
|
|
87
|
+
/** Parsed thought summary (Gemini) */
|
|
88
|
+
thoughtSummary?: {
|
|
89
|
+
description: string;
|
|
90
|
+
subject: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* ID of the tool call this message is responding to.
|
|
94
|
+
* Only present for tool messages.
|
|
95
|
+
*/
|
|
96
|
+
toolCallId?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Tool calls made by the assistant.
|
|
99
|
+
* Only present for assistant messages requesting tool execution.
|
|
100
|
+
*/
|
|
101
|
+
toolCalls?: ToolCall[];
|
|
102
|
+
/** Unix timestamp of last update */
|
|
103
|
+
updatedAt: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Message part stored at ["part", messageId, partId].
|
|
107
|
+
*
|
|
108
|
+
* Parts contain content that may be pruned independently:
|
|
109
|
+
* - Tool outputs (large, can be marked as compacted)
|
|
110
|
+
* - File attachments
|
|
111
|
+
* - Image data
|
|
112
|
+
*
|
|
113
|
+
* Parts are stored separately to enable:
|
|
114
|
+
* - Selective pruning of old tool outputs
|
|
115
|
+
* - Lazy loading of large content
|
|
116
|
+
* - Efficient streaming without loading all content
|
|
117
|
+
*/
|
|
118
|
+
export interface StoredPart {
|
|
119
|
+
/**
|
|
120
|
+
* Unix timestamp when this part was marked as compacted.
|
|
121
|
+
* If set, the original content has been cleared to save space,
|
|
122
|
+
* and a placeholder message should be shown instead.
|
|
123
|
+
*/
|
|
124
|
+
compactedAt?: number;
|
|
125
|
+
/**
|
|
126
|
+
* The actual content of the part.
|
|
127
|
+
* - Tool output: string (JSON or text)
|
|
128
|
+
* - File: base64 encoded data or file path
|
|
129
|
+
* - Text: raw text content
|
|
130
|
+
* - Image: base64 encoded data
|
|
131
|
+
*
|
|
132
|
+
* When compactedAt is set, this will be empty or contain a placeholder.
|
|
133
|
+
*/
|
|
134
|
+
content: string;
|
|
135
|
+
/** Unix timestamp when part was created */
|
|
136
|
+
createdAt: number;
|
|
137
|
+
/** Original filename for file parts */
|
|
138
|
+
filename?: string;
|
|
139
|
+
/** Unique part identifier (UUID) */
|
|
140
|
+
id: string;
|
|
141
|
+
/** ID of the message this part belongs to */
|
|
142
|
+
messageId: string;
|
|
143
|
+
/** MIME type for file and image parts */
|
|
144
|
+
mimeType?: string;
|
|
145
|
+
/**
|
|
146
|
+
* For tool_output parts, the name of the tool.
|
|
147
|
+
* Used for display and filtering.
|
|
148
|
+
*/
|
|
149
|
+
toolName?: string;
|
|
150
|
+
/** Type of part content */
|
|
151
|
+
type: 'compaction' | 'file' | 'image' | 'text' | 'tool_output';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Placeholder message shown when tool output has been compacted.
|
|
155
|
+
*/
|
|
156
|
+
export declare const COMPACTED_TOOL_OUTPUT_PLACEHOLDER = "[Old tool result content cleared]";
|
|
157
|
+
/**
|
|
158
|
+
* Result of loading messages with compaction awareness.
|
|
159
|
+
*/
|
|
160
|
+
export interface LoadMessagesResult {
|
|
161
|
+
/** Whether a compaction boundary was reached */
|
|
162
|
+
hitCompactionBoundary: boolean;
|
|
163
|
+
/** Loaded messages in chronological order (oldest first) */
|
|
164
|
+
messages: StoredMessageWithParts[];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* StoredMessage combined with its resolved parts.
|
|
168
|
+
* Used when converting back to InternalMessage format.
|
|
169
|
+
*/
|
|
170
|
+
export interface StoredMessageWithParts extends StoredMessage {
|
|
171
|
+
/** Resolved part objects (not just IDs) */
|
|
172
|
+
parts: StoredPart[];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Configuration for message streaming.
|
|
176
|
+
*/
|
|
177
|
+
export interface StreamMessagesOptions {
|
|
178
|
+
/**
|
|
179
|
+
* Maximum number of messages to load.
|
|
180
|
+
* Useful for preview/summary views.
|
|
181
|
+
*/
|
|
182
|
+
limit?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Session ID to stream messages from.
|
|
185
|
+
*/
|
|
186
|
+
sessionId: string;
|
|
187
|
+
/**
|
|
188
|
+
* Whether to stop at the first compaction boundary.
|
|
189
|
+
* Default: true
|
|
190
|
+
*/
|
|
191
|
+
stopAtCompaction?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Configuration for tool output pruning.
|
|
195
|
+
*/
|
|
196
|
+
export interface PruneToolOutputsOptions {
|
|
197
|
+
/**
|
|
198
|
+
* Target token count to keep in tool outputs.
|
|
199
|
+
* Tool outputs beyond this (from oldest) will be marked as compacted.
|
|
200
|
+
* Default: 40000 (same as OpenCode)
|
|
201
|
+
*/
|
|
202
|
+
keepTokens?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Session ID to prune tool outputs from.
|
|
205
|
+
*/
|
|
206
|
+
sessionId: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Compaction operation result.
|
|
210
|
+
*/
|
|
211
|
+
export interface CompactionResult {
|
|
212
|
+
/** Number of parts that were compacted */
|
|
213
|
+
compactedCount: number;
|
|
214
|
+
/** New compaction boundary message ID */
|
|
215
|
+
compactionMessageId?: string;
|
|
216
|
+
/** Estimated tokens saved */
|
|
217
|
+
tokensSaved: number;
|
|
218
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for granular message and part storage.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the storage format for the new granular history system,
|
|
5
|
+
* where messages and parts are stored separately to enable:
|
|
6
|
+
* - Streaming message loading (newest to oldest)
|
|
7
|
+
* - Selective tool output pruning
|
|
8
|
+
* - Compaction boundary markers
|
|
9
|
+
*
|
|
10
|
+
* Storage key structure:
|
|
11
|
+
* - ["session", sessionId] → SessionRecord
|
|
12
|
+
* - ["message", sessionId, messageId] → StoredMessage
|
|
13
|
+
* - ["part", messageId, partId] → StoredPart
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Placeholder message shown when tool output has been compacted.
|
|
17
|
+
*/
|
|
18
|
+
export const COMPACTED_TOOL_OUTPUT_PLACEHOLDER = '[Old tool result content cleared]';
|
|
@@ -6,6 +6,7 @@ export declare const ToolName: {
|
|
|
6
6
|
readonly BASH_EXEC: 'bash_exec';
|
|
7
7
|
readonly BASH_OUTPUT: 'bash_output';
|
|
8
8
|
readonly CREATE_KNOWLEDGE_TOPIC: 'create_knowledge_topic';
|
|
9
|
+
readonly CURATE: 'curate';
|
|
9
10
|
readonly DELETE_MEMORY: 'delete_memory';
|
|
10
11
|
readonly DETECT_DOMAINS: 'detect_domains';
|
|
11
12
|
readonly EDIT_FILE: 'edit_file';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Array of all supported Events.
|
|
3
3
|
*/
|
|
4
|
-
export declare const EVENT_VALUES: readonly ["auth:signed_in", "auth:signed_out", "space:init", "space:changed", "rule:generate", "mem:status", "mem:curate", "mem:pull", "mem:push", "mem:query"];
|
|
4
|
+
export declare const EVENT_VALUES: readonly ["auth:signed_in", "auth:signed_out", "space:init", "space:changed", "rule:generate", "mem:status", "mem:curate", "mem:pull", "mem:push", "mem:query", "onboarding:init_completed", "onboarding:curate_completed", "onboarding:query_completed", "onboarding:skipped", "onboarding:completed"];
|
|
5
5
|
export type EventName = (typeof EVENT_VALUES)[number];
|
|
6
6
|
export interface PropertyDict {
|
|
7
7
|
[key: string]: any;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameters for creating a GlobalConfig instance.
|
|
3
|
+
*/
|
|
4
|
+
export interface GlobalConfigParams {
|
|
5
|
+
readonly deviceId: string;
|
|
6
|
+
readonly version: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Represents the global configuration stored in the user's config directory.
|
|
10
|
+
* Contains device-level settings that persist across all projects.
|
|
11
|
+
*/
|
|
12
|
+
export declare class GlobalConfig {
|
|
13
|
+
readonly deviceId: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
private constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new GlobalConfig with the given device ID and current version.
|
|
18
|
+
*
|
|
19
|
+
* @param deviceId - The unique device identifier (UUID v4)
|
|
20
|
+
* @returns A new GlobalConfig instance
|
|
21
|
+
* @throws Error if deviceId is empty
|
|
22
|
+
*/
|
|
23
|
+
static create(deviceId: string): GlobalConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Deserializes config from JSON format.
|
|
26
|
+
* Returns undefined for invalid JSON structure (graceful failure).
|
|
27
|
+
*
|
|
28
|
+
* @param json - The JSON object to deserialize
|
|
29
|
+
* @returns GlobalConfig instance or undefined if invalid
|
|
30
|
+
*/
|
|
31
|
+
static fromJson(json: unknown): GlobalConfig | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Serializes the config to JSON format.
|
|
34
|
+
*/
|
|
35
|
+
toJson(): Record<string, string>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { GLOBAL_CONFIG_VERSION } from '../../../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for GlobalConfig JSON validation.
|
|
4
|
+
*/
|
|
5
|
+
const isGlobalConfigJson = (json) => {
|
|
6
|
+
if (typeof json !== 'object' || json === null || json === undefined)
|
|
7
|
+
return false;
|
|
8
|
+
const obj = json;
|
|
9
|
+
if (typeof obj.deviceId !== 'string' || obj.deviceId.trim().length === 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (typeof obj.version !== 'string') {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Represents the global configuration stored in the user's config directory.
|
|
19
|
+
* Contains device-level settings that persist across all projects.
|
|
20
|
+
*/
|
|
21
|
+
export class GlobalConfig {
|
|
22
|
+
deviceId;
|
|
23
|
+
version;
|
|
24
|
+
constructor(params) {
|
|
25
|
+
this.deviceId = params.deviceId;
|
|
26
|
+
this.version = params.version;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new GlobalConfig with the given device ID and current version.
|
|
30
|
+
*
|
|
31
|
+
* @param deviceId - The unique device identifier (UUID v4)
|
|
32
|
+
* @returns A new GlobalConfig instance
|
|
33
|
+
* @throws Error if deviceId is empty
|
|
34
|
+
*/
|
|
35
|
+
static create(deviceId) {
|
|
36
|
+
if (deviceId.trim().length === 0) {
|
|
37
|
+
throw new Error('Device ID cannot be empty');
|
|
38
|
+
}
|
|
39
|
+
return new GlobalConfig({
|
|
40
|
+
deviceId,
|
|
41
|
+
version: GLOBAL_CONFIG_VERSION,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Deserializes config from JSON format.
|
|
46
|
+
* Returns undefined for invalid JSON structure (graceful failure).
|
|
47
|
+
*
|
|
48
|
+
* @param json - The JSON object to deserialize
|
|
49
|
+
* @returns GlobalConfig instance or undefined if invalid
|
|
50
|
+
*/
|
|
51
|
+
static fromJson(json) {
|
|
52
|
+
if (!isGlobalConfigJson(json)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return new GlobalConfig(json);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Serializes the config to JSON format.
|
|
59
|
+
*/
|
|
60
|
+
toJson() {
|
|
61
|
+
return {
|
|
62
|
+
deviceId: this.deviceId,
|
|
63
|
+
version: this.version,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -34,6 +34,16 @@ export declare const DirectoryManager: {
|
|
|
34
34
|
* @returns Whether topic was created, updated, or skipped
|
|
35
35
|
*/
|
|
36
36
|
createOrUpdateTopic(topicPath: string): Promise<CreateOrUpdateResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Delete a topic/subtopic folder recursively.
|
|
39
|
+
* Removes the folder and all its contents.
|
|
40
|
+
*
|
|
41
|
+
* @param topicPath - Full path to topic folder to delete
|
|
42
|
+
* @returns Whether the topic was deleted
|
|
43
|
+
*/
|
|
44
|
+
deleteTopicRecursive(topicPath: string): Promise<{
|
|
45
|
+
deleted: boolean;
|
|
46
|
+
}>;
|
|
37
47
|
/**
|
|
38
48
|
* Ensure the base knowledge structure exists.
|
|
39
49
|
* Creates .brv/context-tree/ directory if it doesn't exist.
|
|
@@ -43,6 +43,24 @@ export const DirectoryManager = {
|
|
|
43
43
|
return { created: true, skipped: false, updated: false };
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
+
/**
|
|
47
|
+
* Delete a topic/subtopic folder recursively.
|
|
48
|
+
* Removes the folder and all its contents.
|
|
49
|
+
*
|
|
50
|
+
* @param topicPath - Full path to topic folder to delete
|
|
51
|
+
* @returns Whether the topic was deleted
|
|
52
|
+
*/
|
|
53
|
+
async deleteTopicRecursive(topicPath) {
|
|
54
|
+
try {
|
|
55
|
+
await fs.access(topicPath);
|
|
56
|
+
await fs.rm(topicPath, { force: true, recursive: true });
|
|
57
|
+
return { deleted: true };
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Path doesn't exist or already deleted
|
|
61
|
+
return { deleted: false };
|
|
62
|
+
}
|
|
63
|
+
},
|
|
46
64
|
/**
|
|
47
65
|
* Ensure the base knowledge structure exists.
|
|
48
66
|
* Creates .brv/context-tree/ directory if it doesn't exist.
|
|
@@ -15,4 +15,13 @@ export declare const MarkdownWriter: {
|
|
|
15
15
|
* Used for both topics and subtopics in the knowledge hierarchy.
|
|
16
16
|
*/
|
|
17
17
|
generateContext(data: ContextData): string;
|
|
18
|
+
/**
|
|
19
|
+
* Merge two context.md contents into one.
|
|
20
|
+
* Combines snippets and relations, deduplicating where possible.
|
|
21
|
+
*
|
|
22
|
+
* @param sourceContent - Raw content from source context.md
|
|
23
|
+
* @param targetContent - Raw content from target context.md
|
|
24
|
+
* @returns Merged context.md content
|
|
25
|
+
*/
|
|
26
|
+
mergeContexts(sourceContent: string, targetContent: string): string;
|
|
18
27
|
};
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
import { generateRelationsSection } from './relation-parser.js';
|
|
1
|
+
import { generateRelationsSection, parseRelations } from './relation-parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract snippets from context.md content.
|
|
4
|
+
* Removes relations section and splits by separator.
|
|
5
|
+
*/
|
|
6
|
+
function extractSnippetsFromContent(content) {
|
|
7
|
+
// Remove relations section if present
|
|
8
|
+
let snippetContent = content;
|
|
9
|
+
const relationsMatch = content.match(/## Relations[\s\S]*?(?=\n[^@\n]|$)/);
|
|
10
|
+
if (relationsMatch) {
|
|
11
|
+
snippetContent = content.replace(relationsMatch[0], '').trim();
|
|
12
|
+
}
|
|
13
|
+
// Split by separator and filter empty
|
|
14
|
+
const snippets = snippetContent
|
|
15
|
+
.split(/\n---\n/)
|
|
16
|
+
.map(s => s.trim())
|
|
17
|
+
.filter(s => s && s !== 'No context available.');
|
|
18
|
+
return snippets;
|
|
19
|
+
}
|
|
2
20
|
/**
|
|
3
21
|
* Generates Markdown files for knowledge context.
|
|
4
22
|
*/
|
|
@@ -13,6 +31,38 @@ export const MarkdownWriter = {
|
|
|
13
31
|
const relationsSection = generateRelationsSection(relations);
|
|
14
32
|
return `${relationsSection}
|
|
15
33
|
${snippets.length > 0 ? snippets.map(s => `${s}`).join('\n\n---\n\n') : 'No context available.'}
|
|
34
|
+
`;
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Merge two context.md contents into one.
|
|
38
|
+
* Combines snippets and relations, deduplicating where possible.
|
|
39
|
+
*
|
|
40
|
+
* @param sourceContent - Raw content from source context.md
|
|
41
|
+
* @param targetContent - Raw content from target context.md
|
|
42
|
+
* @returns Merged context.md content
|
|
43
|
+
*/
|
|
44
|
+
mergeContexts(sourceContent, targetContent) {
|
|
45
|
+
// Extract relations from both contents
|
|
46
|
+
const sourceRelations = parseRelations(sourceContent);
|
|
47
|
+
const targetRelations = parseRelations(targetContent);
|
|
48
|
+
// Merge and deduplicate relations
|
|
49
|
+
const mergedRelations = [...new Set([...sourceRelations, ...targetRelations])];
|
|
50
|
+
const sourceSnippets = extractSnippetsFromContent(sourceContent);
|
|
51
|
+
const targetSnippets = extractSnippetsFromContent(targetContent);
|
|
52
|
+
// Merge snippets (target first, then source)
|
|
53
|
+
// Deduplicate by exact match
|
|
54
|
+
const seenSnippets = new Set();
|
|
55
|
+
const mergedSnippets = [];
|
|
56
|
+
for (const snippet of [...targetSnippets, ...sourceSnippets]) {
|
|
57
|
+
if (!seenSnippets.has(snippet)) {
|
|
58
|
+
seenSnippets.add(snippet);
|
|
59
|
+
mergedSnippets.push(snippet);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Generate merged content
|
|
63
|
+
const relationsSection = generateRelationsSection(mergedRelations);
|
|
64
|
+
return `${relationsSection}
|
|
65
|
+
${mergedSnippets.length > 0 ? mergedSnippets.join('\n\n---\n\n') : 'No context available.'}
|
|
16
66
|
`;
|
|
17
67
|
},
|
|
18
68
|
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { Execution, ExecutionStatus, ExecutionType, ToolCall, ToolCallInfo, ToolCallStatus, ToolCallUpdateOptions } from '../../domain/cipher/queue/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for agent execution storage.
|
|
4
|
+
*
|
|
5
|
+
* Manages the execution queue, tool call tracking, and consumer locks.
|
|
6
|
+
* Implementations can use different storage backends (SQLite, in-memory, etc.)
|
|
7
|
+
*/
|
|
8
|
+
export interface IAgentStorage {
|
|
9
|
+
/**
|
|
10
|
+
* Acquire consumer lock (register this consumer).
|
|
11
|
+
* Only ONE consumer can run at a time.
|
|
12
|
+
* @param consumerId - Unique ID for this consumer
|
|
13
|
+
* @returns true if lock acquired, false if another consumer is already running
|
|
14
|
+
*/
|
|
15
|
+
acquireConsumerLock(consumerId: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Add a tool call record.
|
|
18
|
+
* @returns tool call id
|
|
19
|
+
*/
|
|
20
|
+
addToolCall(executionId: string, info: ToolCallInfo): string;
|
|
21
|
+
/**
|
|
22
|
+
* Cleanup old executions, keep only maxKeep most recent completed/failed.
|
|
23
|
+
* @returns number of deleted executions
|
|
24
|
+
*/
|
|
25
|
+
cleanupOldExecutions(maxKeep?: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Cleanup orphaned executions (status='running') from previous session crash.
|
|
28
|
+
* @returns number of orphaned executions
|
|
29
|
+
*/
|
|
30
|
+
cleanupOrphanedExecutions(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Cleanup stale consumers and orphan their executions.
|
|
33
|
+
* @param timeoutMs - heartbeat timeout (default 30 seconds)
|
|
34
|
+
* @returns number of orphaned executions
|
|
35
|
+
*/
|
|
36
|
+
cleanupStaleConsumers(timeoutMs?: number): number;
|
|
37
|
+
/**
|
|
38
|
+
* Close storage connection.
|
|
39
|
+
*/
|
|
40
|
+
close(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new execution.
|
|
43
|
+
* @param type - 'curate' or 'query'
|
|
44
|
+
* @param input - content (curate) or query string (query)
|
|
45
|
+
* @returns execution id
|
|
46
|
+
*/
|
|
47
|
+
createExecution(type: ExecutionType, input: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Dequeue multiple executions at once (atomic batch SELECT + UPDATE).
|
|
50
|
+
* @param limit - max number of executions to dequeue
|
|
51
|
+
* @param consumerId - ID of the consumer claiming these executions
|
|
52
|
+
* @returns array of executions (may be empty if queue is empty)
|
|
53
|
+
*/
|
|
54
|
+
dequeueBatch(limit: number, consumerId?: string): Execution[];
|
|
55
|
+
/**
|
|
56
|
+
* Dequeue next queued execution (atomic SELECT + UPDATE).
|
|
57
|
+
* @param consumerId - ID of the consumer claiming this execution
|
|
58
|
+
* @returns execution or null if queue is empty
|
|
59
|
+
*/
|
|
60
|
+
dequeueExecution(consumerId?: string): Execution | null;
|
|
61
|
+
/**
|
|
62
|
+
* Get execution by id.
|
|
63
|
+
*/
|
|
64
|
+
getExecution(id: string): Execution | null;
|
|
65
|
+
/**
|
|
66
|
+
* Get executions updated since timestamp (for incremental polling).
|
|
67
|
+
*/
|
|
68
|
+
getExecutionsSince(timestamp: number): Execution[];
|
|
69
|
+
/**
|
|
70
|
+
* Get execution with all its tool calls (for UI display).
|
|
71
|
+
*/
|
|
72
|
+
getExecutionWithToolCalls(id: string): null | {
|
|
73
|
+
execution: Execution;
|
|
74
|
+
toolCalls: ToolCall[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Get all queued executions.
|
|
78
|
+
*/
|
|
79
|
+
getQueuedExecutions(): Execution[];
|
|
80
|
+
/**
|
|
81
|
+
* Get recent executions (for UI display).
|
|
82
|
+
*/
|
|
83
|
+
getRecentExecutions(limit?: number): Execution[];
|
|
84
|
+
/**
|
|
85
|
+
* Get all running executions.
|
|
86
|
+
*/
|
|
87
|
+
getRunningExecutions(): Execution[];
|
|
88
|
+
/**
|
|
89
|
+
* Get all executions belonging to a specific consumer session.
|
|
90
|
+
* Returns executions ordered by created_at ASC (oldest first, newest last).
|
|
91
|
+
* @param consumerId - The consumer ID to filter by
|
|
92
|
+
*/
|
|
93
|
+
getSessionExecutions(consumerId: string): Execution[];
|
|
94
|
+
/**
|
|
95
|
+
* Get queue statistics (queries DB directly for accurate counts).
|
|
96
|
+
*/
|
|
97
|
+
getStats(): {
|
|
98
|
+
completed: number;
|
|
99
|
+
failed: number;
|
|
100
|
+
queued: number;
|
|
101
|
+
running: number;
|
|
102
|
+
total: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Get all tool calls for an execution.
|
|
106
|
+
*/
|
|
107
|
+
getToolCalls(executionId: string): ToolCall[];
|
|
108
|
+
/**
|
|
109
|
+
* Check if any consumer is currently active (has recent heartbeat).
|
|
110
|
+
* @param timeoutMs - heartbeat timeout (default 30 seconds)
|
|
111
|
+
*/
|
|
112
|
+
hasActiveConsumer(timeoutMs?: number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Check if a specific consumer lock exists in the database.
|
|
115
|
+
* Used by Consumer to verify its lock is still valid after DB reconnection.
|
|
116
|
+
*/
|
|
117
|
+
hasConsumerLock(consumerId: string): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Initialize storage.
|
|
120
|
+
*/
|
|
121
|
+
initialize(options?: {
|
|
122
|
+
cleanupOrphans?: boolean;
|
|
123
|
+
}): Promise<void>;
|
|
124
|
+
/** Whether the storage has been initialized */
|
|
125
|
+
readonly initialized: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Check if the DB file has been replaced (different inode).
|
|
128
|
+
* Returns true if DB needs reconnection.
|
|
129
|
+
*/
|
|
130
|
+
isDbFileChanged(): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Reconnect to the database (close and reinitialize).
|
|
133
|
+
* Use when DB file has been replaced by another process (e.g., brv init).
|
|
134
|
+
*/
|
|
135
|
+
reconnect(): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Release consumer lock (unregister this consumer).
|
|
138
|
+
*/
|
|
139
|
+
releaseConsumerLock(consumerId: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* Update consumer heartbeat.
|
|
142
|
+
*/
|
|
143
|
+
updateConsumerHeartbeat(consumerId: string): void;
|
|
144
|
+
/**
|
|
145
|
+
* Update execution status.
|
|
146
|
+
*/
|
|
147
|
+
updateExecutionStatus(id: string, status: ExecutionStatus, result?: string, error?: string): void;
|
|
148
|
+
/**
|
|
149
|
+
* Update tool call status and result.
|
|
150
|
+
*/
|
|
151
|
+
updateToolCall(id: string, status: ToolCallStatus, options?: ToolCallUpdateOptions): void;
|
|
152
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -10,6 +10,8 @@ export interface ExecutionContext {
|
|
|
10
10
|
commandType?: 'curate' | 'query';
|
|
11
11
|
/** Metadata about the conversation (for JSON input mode) */
|
|
12
12
|
conversationMetadata?: ConversationMetadata;
|
|
13
|
+
/** File reference instructions for agent to read files (for curate command with --files flag) */
|
|
14
|
+
fileReferenceInstructions?: string;
|
|
13
15
|
/** Whether running in JSON input mode (headless with conversation history) */
|
|
14
16
|
isJsonInputMode?: boolean;
|
|
15
17
|
}
|