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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DB-based consumer lock utilities
|
|
3
|
+
*
|
|
4
|
+
* The actual locking is now handled by AgentStorage methods:
|
|
5
|
+
* - acquireConsumerLock(consumerId)
|
|
6
|
+
* - releaseConsumerLock(consumerId)
|
|
7
|
+
* - hasActiveConsumer(timeoutMs)
|
|
8
|
+
*
|
|
9
|
+
* These utility functions provide a simple interface for checking consumer status.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Check if a consumer is currently running (has active heartbeat in DB)
|
|
13
|
+
* Auto-detects .brv/blobs path from cwd
|
|
14
|
+
*/
|
|
15
|
+
export declare function isConsumerRunning(): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a consumer is currently running (sync version)
|
|
18
|
+
* Assumes storage is already initialized
|
|
19
|
+
*/
|
|
20
|
+
export declare function isConsumerRunningSync(): boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getAgentStorage, getAgentStorageSync } from '../storage/agent-storage.js';
|
|
2
|
+
// Consumer is considered stale after 30 seconds without heartbeat
|
|
3
|
+
const STALE_TIMEOUT_MS = 30_000;
|
|
4
|
+
/**
|
|
5
|
+
* DB-based consumer lock utilities
|
|
6
|
+
*
|
|
7
|
+
* The actual locking is now handled by AgentStorage methods:
|
|
8
|
+
* - acquireConsumerLock(consumerId)
|
|
9
|
+
* - releaseConsumerLock(consumerId)
|
|
10
|
+
* - hasActiveConsumer(timeoutMs)
|
|
11
|
+
*
|
|
12
|
+
* These utility functions provide a simple interface for checking consumer status.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Check if a consumer is currently running (has active heartbeat in DB)
|
|
16
|
+
* Auto-detects .brv/blobs path from cwd
|
|
17
|
+
*/
|
|
18
|
+
export async function isConsumerRunning() {
|
|
19
|
+
try {
|
|
20
|
+
const storage = await getAgentStorage();
|
|
21
|
+
return storage.hasActiveConsumer(STALE_TIMEOUT_MS);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// If we can't check, assume not running
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a consumer is currently running (sync version)
|
|
30
|
+
* Assumes storage is already initialized
|
|
31
|
+
*/
|
|
32
|
+
export function isConsumerRunningSync() {
|
|
33
|
+
try {
|
|
34
|
+
const storage = getAgentStorageSync();
|
|
35
|
+
return storage.hasActiveConsumer(STALE_TIMEOUT_MS);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export interface ConsumerServiceOptions {
|
|
2
|
+
/** Max concurrent jobs (default: 5) */
|
|
3
|
+
concurrency?: number;
|
|
4
|
+
/** Poll interval in ms (default: 1000) */
|
|
5
|
+
pollInterval?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ConsumerService - Singleton background worker that processes the execution queue
|
|
9
|
+
*
|
|
10
|
+
* Architecture:
|
|
11
|
+
* ```
|
|
12
|
+
* ┌─────────────────┐
|
|
13
|
+
* │ ConsumerService │ ← Singleton, start once in main
|
|
14
|
+
* │ (process jobs) │
|
|
15
|
+
* └────────┬────────┘
|
|
16
|
+
* │ writes
|
|
17
|
+
* ▼
|
|
18
|
+
* ┌─────────────────┐
|
|
19
|
+
* │ AgentStorage │ ← SQLite DB (source of truth)
|
|
20
|
+
* │ (agent.db) │
|
|
21
|
+
* └────────┬────────┘
|
|
22
|
+
* │ polls
|
|
23
|
+
* ▼
|
|
24
|
+
* ┌─────────────────┐
|
|
25
|
+
* │QueuePollingServ │ ← UI subscribes here for updates
|
|
26
|
+
* └─────────────────┘
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Main - start consumer singleton (once)
|
|
32
|
+
* const consumer = getConsumerService({ concurrency: 5 })
|
|
33
|
+
* await consumer.start()
|
|
34
|
+
*
|
|
35
|
+
* // UI components - use QueuePollingService for monitoring
|
|
36
|
+
* import { getQueuePollingService } from './queue-polling-service'
|
|
37
|
+
* const poller = getQueuePollingService({ pollInterval: 500 })
|
|
38
|
+
* poller.on('snapshot', (snapshot) => renderUI(snapshot))
|
|
39
|
+
* await poller.start()
|
|
40
|
+
*
|
|
41
|
+
* // Cleanup
|
|
42
|
+
* consumer.dispose()
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Features:
|
|
46
|
+
* - Auto-loads auth token from Keychain
|
|
47
|
+
* - Auto-loads project config from .brv/config.json
|
|
48
|
+
* - Handles lock acquisition/release
|
|
49
|
+
* - Single dispose() for full cleanup
|
|
50
|
+
*/
|
|
51
|
+
export declare class ConsumerService {
|
|
52
|
+
private consumer;
|
|
53
|
+
private readonly options;
|
|
54
|
+
private running;
|
|
55
|
+
constructor(options?: ConsumerServiceOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Stop the consumer and cleanup all resources
|
|
58
|
+
*/
|
|
59
|
+
dispose(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get the consumer ID (unique per session)
|
|
62
|
+
* Returns null if consumer hasn't started yet
|
|
63
|
+
*/
|
|
64
|
+
getConsumerId(): null | string;
|
|
65
|
+
/**
|
|
66
|
+
* Check if consumer is running
|
|
67
|
+
*/
|
|
68
|
+
isRunning(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Start the consumer
|
|
71
|
+
*
|
|
72
|
+
* - Loads auth token from Keychain
|
|
73
|
+
* - Loads project config from .brv/config.json
|
|
74
|
+
* - Acquires consumer lock
|
|
75
|
+
* - Starts processing queue
|
|
76
|
+
*
|
|
77
|
+
* @throws Error if not authenticated
|
|
78
|
+
* @throws Error if another consumer is already running
|
|
79
|
+
*/
|
|
80
|
+
start(): Promise<void>;
|
|
81
|
+
stop(): void;
|
|
82
|
+
private setupSignalHandlers;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get or create singleton ConsumerService
|
|
86
|
+
*
|
|
87
|
+
* Usage:
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const consumer = getConsumerService()
|
|
90
|
+
* await consumer.start()
|
|
91
|
+
* // later...
|
|
92
|
+
* consumer.dispose()
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function getConsumerService(options?: ConsumerServiceOptions): ConsumerService;
|
|
96
|
+
/**
|
|
97
|
+
* Dispose singleton and clear reference
|
|
98
|
+
*/
|
|
99
|
+
export declare function disposeConsumerService(): void;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ProjectConfigStore } from '../../config/file-config-store.js';
|
|
2
|
+
import { KeychainTokenStore } from '../../storage/keychain-token-store.js';
|
|
3
|
+
import { closeAgentStorage } from '../storage/agent-storage.js';
|
|
4
|
+
import { createExecutionConsumer } from './execution-consumer.js';
|
|
5
|
+
// ==================== SERVICE ====================
|
|
6
|
+
/**
|
|
7
|
+
* ConsumerService - Singleton background worker that processes the execution queue
|
|
8
|
+
*
|
|
9
|
+
* Architecture:
|
|
10
|
+
* ```
|
|
11
|
+
* ┌─────────────────┐
|
|
12
|
+
* │ ConsumerService │ ← Singleton, start once in main
|
|
13
|
+
* │ (process jobs) │
|
|
14
|
+
* └────────┬────────┘
|
|
15
|
+
* │ writes
|
|
16
|
+
* ▼
|
|
17
|
+
* ┌─────────────────┐
|
|
18
|
+
* │ AgentStorage │ ← SQLite DB (source of truth)
|
|
19
|
+
* │ (agent.db) │
|
|
20
|
+
* └────────┬────────┘
|
|
21
|
+
* │ polls
|
|
22
|
+
* ▼
|
|
23
|
+
* ┌─────────────────┐
|
|
24
|
+
* │QueuePollingServ │ ← UI subscribes here for updates
|
|
25
|
+
* └─────────────────┘
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Main - start consumer singleton (once)
|
|
31
|
+
* const consumer = getConsumerService({ concurrency: 5 })
|
|
32
|
+
* await consumer.start()
|
|
33
|
+
*
|
|
34
|
+
* // UI components - use QueuePollingService for monitoring
|
|
35
|
+
* import { getQueuePollingService } from './queue-polling-service'
|
|
36
|
+
* const poller = getQueuePollingService({ pollInterval: 500 })
|
|
37
|
+
* poller.on('snapshot', (snapshot) => renderUI(snapshot))
|
|
38
|
+
* await poller.start()
|
|
39
|
+
*
|
|
40
|
+
* // Cleanup
|
|
41
|
+
* consumer.dispose()
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Features:
|
|
45
|
+
* - Auto-loads auth token from Keychain
|
|
46
|
+
* - Auto-loads project config from .brv/config.json
|
|
47
|
+
* - Handles lock acquisition/release
|
|
48
|
+
* - Single dispose() for full cleanup
|
|
49
|
+
*/
|
|
50
|
+
export class ConsumerService {
|
|
51
|
+
consumer = null;
|
|
52
|
+
options;
|
|
53
|
+
running = false;
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.options = options ?? {};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stop the consumer and cleanup all resources
|
|
59
|
+
*/
|
|
60
|
+
dispose() {
|
|
61
|
+
if (!this.running)
|
|
62
|
+
return;
|
|
63
|
+
this.running = false;
|
|
64
|
+
if (this.consumer) {
|
|
65
|
+
this.consumer.stop();
|
|
66
|
+
this.consumer = null;
|
|
67
|
+
}
|
|
68
|
+
closeAgentStorage();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the consumer ID (unique per session)
|
|
72
|
+
* Returns null if consumer hasn't started yet
|
|
73
|
+
*/
|
|
74
|
+
getConsumerId() {
|
|
75
|
+
return this.consumer?.getConsumerId() ?? null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if consumer is running
|
|
79
|
+
*/
|
|
80
|
+
isRunning() {
|
|
81
|
+
return this.running && this.consumer !== null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Start the consumer
|
|
85
|
+
*
|
|
86
|
+
* - Loads auth token from Keychain
|
|
87
|
+
* - Loads project config from .brv/config.json
|
|
88
|
+
* - Acquires consumer lock
|
|
89
|
+
* - Starts processing queue
|
|
90
|
+
*
|
|
91
|
+
* @throws Error if not authenticated
|
|
92
|
+
* @throws Error if another consumer is already running
|
|
93
|
+
*/
|
|
94
|
+
async start() {
|
|
95
|
+
if (this.running) {
|
|
96
|
+
throw new Error('Consumer already running');
|
|
97
|
+
}
|
|
98
|
+
// Load auth token
|
|
99
|
+
const tokenStore = new KeychainTokenStore();
|
|
100
|
+
const token = await tokenStore.load();
|
|
101
|
+
if (!token) {
|
|
102
|
+
throw new Error('Not authenticated. Please run "brv login" first.');
|
|
103
|
+
}
|
|
104
|
+
// Load project config (optional)
|
|
105
|
+
const configStore = new ProjectConfigStore();
|
|
106
|
+
const brvConfig = await configStore.read();
|
|
107
|
+
// Create consumer (auto-detects .brv/blobs from cwd)
|
|
108
|
+
this.consumer = createExecutionConsumer({
|
|
109
|
+
authToken: { accessToken: token.accessToken, sessionKey: token.sessionKey },
|
|
110
|
+
brvConfig: brvConfig ?? undefined,
|
|
111
|
+
maxConcurrency: this.options.concurrency ?? 5,
|
|
112
|
+
pollInterval: this.options.pollInterval ?? 1000,
|
|
113
|
+
});
|
|
114
|
+
// Start consumer
|
|
115
|
+
const started = await this.consumer.start();
|
|
116
|
+
if (!started) {
|
|
117
|
+
this.consumer = null;
|
|
118
|
+
throw new Error('Another consumer is already running in this directory');
|
|
119
|
+
}
|
|
120
|
+
this.running = true;
|
|
121
|
+
this.setupSignalHandlers();
|
|
122
|
+
}
|
|
123
|
+
// Alias for dispose
|
|
124
|
+
stop() {
|
|
125
|
+
this.dispose();
|
|
126
|
+
}
|
|
127
|
+
// ==================== PRIVATE ====================
|
|
128
|
+
setupSignalHandlers() {
|
|
129
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- needs 'this' context
|
|
130
|
+
const cleanup = () => {
|
|
131
|
+
this.dispose();
|
|
132
|
+
};
|
|
133
|
+
process.on('SIGTERM', cleanup);
|
|
134
|
+
process.on('SIGINT', cleanup);
|
|
135
|
+
process.on('exit', cleanup);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// ==================== SINGLETON HELPER ====================
|
|
139
|
+
let instance = null;
|
|
140
|
+
/**
|
|
141
|
+
* Get or create singleton ConsumerService
|
|
142
|
+
*
|
|
143
|
+
* Usage:
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const consumer = getConsumerService()
|
|
146
|
+
* await consumer.start()
|
|
147
|
+
* // later...
|
|
148
|
+
* consumer.dispose()
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export function getConsumerService(options) {
|
|
152
|
+
if (!instance) {
|
|
153
|
+
instance = new ConsumerService(options);
|
|
154
|
+
}
|
|
155
|
+
return instance;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Dispose singleton and clear reference
|
|
159
|
+
*/
|
|
160
|
+
export function disposeConsumerService() {
|
|
161
|
+
if (instance) {
|
|
162
|
+
instance.dispose();
|
|
163
|
+
instance = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { BrvConfig } from '../../../core/domain/entities/brv-config.js';
|
|
2
|
+
/**
|
|
3
|
+
* ExecutionConsumer - Polls queue and executes jobs in parallel
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - DB-based lock with heartbeat (detects dead consumers)
|
|
7
|
+
* - Poll loop every 1 second
|
|
8
|
+
* - Parallel processing with configurable concurrency (default 5)
|
|
9
|
+
* - Process curate executions
|
|
10
|
+
* - Track tool calls to database
|
|
11
|
+
* - Cleanup old executions periodically
|
|
12
|
+
*/
|
|
13
|
+
export declare class ExecutionConsumer {
|
|
14
|
+
private readonly activeJobs;
|
|
15
|
+
private authToken?;
|
|
16
|
+
private readonly brvConfig?;
|
|
17
|
+
private readonly consumerId;
|
|
18
|
+
private heartbeatInterval?;
|
|
19
|
+
private readonly maxConcurrency;
|
|
20
|
+
private readonly pollInterval;
|
|
21
|
+
private running;
|
|
22
|
+
constructor(options?: {
|
|
23
|
+
authToken?: {
|
|
24
|
+
accessToken: string;
|
|
25
|
+
sessionKey: string;
|
|
26
|
+
};
|
|
27
|
+
brvConfig?: BrvConfig;
|
|
28
|
+
maxConcurrency?: number;
|
|
29
|
+
pollInterval?: number;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Get the unique consumer ID for this instance
|
|
33
|
+
*/
|
|
34
|
+
getConsumerId(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Check if consumer is running
|
|
37
|
+
*/
|
|
38
|
+
isRunning(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Set auth token (can be set after construction)
|
|
41
|
+
*/
|
|
42
|
+
setAuthToken(token: {
|
|
43
|
+
accessToken: string;
|
|
44
|
+
sessionKey: string;
|
|
45
|
+
}): void;
|
|
46
|
+
/**
|
|
47
|
+
* Start the consumer
|
|
48
|
+
* @returns true if started successfully, false if another consumer is running
|
|
49
|
+
*/
|
|
50
|
+
start(): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Stop the consumer
|
|
53
|
+
* Idempotent - safe to call multiple times (only runs cleanup once)
|
|
54
|
+
*/
|
|
55
|
+
stop(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Execute a curate job
|
|
58
|
+
*/
|
|
59
|
+
private executeCurate;
|
|
60
|
+
/**
|
|
61
|
+
* Log execution start (extracted to reduce nesting depth)
|
|
62
|
+
*/
|
|
63
|
+
private logExecutionStart;
|
|
64
|
+
/**
|
|
65
|
+
* Main poll loop - dequeues and processes jobs in parallel up to maxConcurrency
|
|
66
|
+
*/
|
|
67
|
+
private poll;
|
|
68
|
+
/**
|
|
69
|
+
* Process a single execution
|
|
70
|
+
*/
|
|
71
|
+
private processExecution;
|
|
72
|
+
/**
|
|
73
|
+
* Process execution asynchronously (fire and forget with tracking)
|
|
74
|
+
*/
|
|
75
|
+
private processExecutionAsync;
|
|
76
|
+
/**
|
|
77
|
+
* Setup tool call tracking via event listeners
|
|
78
|
+
*/
|
|
79
|
+
private setupToolCallTracking;
|
|
80
|
+
/**
|
|
81
|
+
* Try to pick up queued jobs (called after job completion)
|
|
82
|
+
*/
|
|
83
|
+
private tryPickupJobs;
|
|
84
|
+
/**
|
|
85
|
+
* Try to recover lock after error (extracted to reduce nesting depth)
|
|
86
|
+
*/
|
|
87
|
+
private tryRecoverLock;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a new ExecutionConsumer instance
|
|
91
|
+
*/
|
|
92
|
+
export declare function createExecutionConsumer(options?: {
|
|
93
|
+
authToken?: {
|
|
94
|
+
accessToken: string;
|
|
95
|
+
sessionKey: string;
|
|
96
|
+
};
|
|
97
|
+
brvConfig?: BrvConfig;
|
|
98
|
+
maxConcurrency?: number;
|
|
99
|
+
pollInterval?: number;
|
|
100
|
+
}): ExecutionConsumer;
|
|
101
|
+
/**
|
|
102
|
+
* Try to start a consumer (singleton pattern)
|
|
103
|
+
* Returns the consumer instance if started, null if already running
|
|
104
|
+
*/
|
|
105
|
+
export declare function tryStartConsumer(options?: {
|
|
106
|
+
authToken?: {
|
|
107
|
+
accessToken: string;
|
|
108
|
+
sessionKey: string;
|
|
109
|
+
};
|
|
110
|
+
brvConfig?: BrvConfig;
|
|
111
|
+
maxConcurrency?: number;
|
|
112
|
+
pollInterval?: number;
|
|
113
|
+
}): Promise<ExecutionConsumer | null>;
|
|
114
|
+
/**
|
|
115
|
+
* Get the current consumer instance (if running)
|
|
116
|
+
*/
|
|
117
|
+
export declare function getConsumer(): ExecutionConsumer | null;
|
|
118
|
+
/**
|
|
119
|
+
* Stop the current consumer
|
|
120
|
+
*/
|
|
121
|
+
export declare function stopConsumer(): void;
|