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,404 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import Database from 'better-sqlite3';
|
|
54
|
+
import * as fs from 'node:fs/promises';
|
|
55
|
+
import { join } from 'node:path';
|
|
56
|
+
import { lockKeyFromStorageKey, RWLock } from '../llm/context/rw-lock.js';
|
|
57
|
+
/**
|
|
58
|
+
* SQLite-based key storage implementation.
|
|
59
|
+
*
|
|
60
|
+
* Stores key-value pairs where keys are hierarchical (StorageKey = string[])
|
|
61
|
+
* and values are JSON-serializable objects.
|
|
62
|
+
*
|
|
63
|
+
* Key path structure:
|
|
64
|
+
* - ["session", sessionId] → Session metadata
|
|
65
|
+
* - ["message", sessionId, messageId] → Individual message
|
|
66
|
+
* - ["part", messageId, partId] → Message part (tool output, file, etc.)
|
|
67
|
+
*
|
|
68
|
+
* Schema:
|
|
69
|
+
* - key_store: key_path (primary), value (JSON blob), created_at, updated_at
|
|
70
|
+
*
|
|
71
|
+
* Features:
|
|
72
|
+
* - Hierarchical key organization with prefix-based listing
|
|
73
|
+
* - Reader-writer locks for concurrent access
|
|
74
|
+
* - Atomic batch operations
|
|
75
|
+
* - ACID transactions via SQLite
|
|
76
|
+
*/
|
|
77
|
+
export class SqliteKeyStorage {
|
|
78
|
+
db = null;
|
|
79
|
+
dbPath;
|
|
80
|
+
initialized = false;
|
|
81
|
+
inMemory;
|
|
82
|
+
storageDir;
|
|
83
|
+
constructor(config) {
|
|
84
|
+
this.inMemory = config?.inMemory ?? false;
|
|
85
|
+
this.storageDir = config?.storageDir ?? join(process.cwd(), '.brv');
|
|
86
|
+
this.dbPath = this.inMemory ? ':memory:' : join(this.storageDir, config?.dbPath ?? 'context.db');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Execute batch operations atomically.
|
|
90
|
+
* All operations succeed or fail together.
|
|
91
|
+
*/
|
|
92
|
+
async batch(operations) {
|
|
93
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
94
|
+
try {
|
|
95
|
+
this.ensureInitialized();
|
|
96
|
+
if (operations.length === 0) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Acquire write lock for all affected keys
|
|
100
|
+
const lockKey = 'batch:global';
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
102
|
+
const _lock = __addDisposableResource(env_1, await RWLock.write(lockKey), false);
|
|
103
|
+
const runBatch = this.db.transaction(() => {
|
|
104
|
+
for (const op of operations) {
|
|
105
|
+
const keyPath = this.serializeKey(op.key);
|
|
106
|
+
if (op.type === 'set') {
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
const valueJson = JSON.stringify(op.value);
|
|
109
|
+
// Check if exists to preserve created_at
|
|
110
|
+
const existing = this.db.prepare('SELECT created_at FROM key_store WHERE key_path = ?').get(keyPath);
|
|
111
|
+
this.db.prepare(`
|
|
112
|
+
INSERT INTO key_store (key_path, value, created_at, updated_at)
|
|
113
|
+
VALUES (?, ?, ?, ?)
|
|
114
|
+
ON CONFLICT(key_path) DO UPDATE SET
|
|
115
|
+
value = excluded.value,
|
|
116
|
+
updated_at = excluded.updated_at
|
|
117
|
+
`).run(keyPath, Buffer.from(valueJson), existing?.created_at ?? now, now);
|
|
118
|
+
}
|
|
119
|
+
else if (op.type === 'delete') {
|
|
120
|
+
this.db.prepare('DELETE FROM key_store WHERE key_path = ?').run(keyPath);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
try {
|
|
125
|
+
runBatch();
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new Error(`Batch operation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e_1) {
|
|
132
|
+
env_1.error = e_1;
|
|
133
|
+
env_1.hasError = true;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
__disposeResources(env_1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Close the database connection.
|
|
141
|
+
*/
|
|
142
|
+
close() {
|
|
143
|
+
if (this.db) {
|
|
144
|
+
this.db.close();
|
|
145
|
+
this.db = null;
|
|
146
|
+
this.initialized = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Delete a value by its composite key.
|
|
151
|
+
*/
|
|
152
|
+
async delete(key) {
|
|
153
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
154
|
+
try {
|
|
155
|
+
this.ensureInitialized();
|
|
156
|
+
const keyPath = this.serializeKey(key);
|
|
157
|
+
const lockKey = lockKeyFromStorageKey(key);
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
|
+
const _lock = __addDisposableResource(env_2, await RWLock.write(lockKey), false);
|
|
160
|
+
try {
|
|
161
|
+
const result = this.db.prepare('DELETE FROM key_store WHERE key_path = ?').run(keyPath);
|
|
162
|
+
return result.changes > 0;
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new Error(`Failed to delete key ${keyPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (e_2) {
|
|
169
|
+
env_2.error = e_2;
|
|
170
|
+
env_2.hasError = true;
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
__disposeResources(env_2);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if a key exists.
|
|
178
|
+
*/
|
|
179
|
+
async exists(key) {
|
|
180
|
+
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
181
|
+
try {
|
|
182
|
+
this.ensureInitialized();
|
|
183
|
+
const keyPath = this.serializeKey(key);
|
|
184
|
+
const lockKey = lockKeyFromStorageKey(key);
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
186
|
+
const _lock = __addDisposableResource(env_3, await RWLock.read(lockKey), false);
|
|
187
|
+
const row = this.db.prepare('SELECT 1 FROM key_store WHERE key_path = ?').get(keyPath);
|
|
188
|
+
return row !== undefined;
|
|
189
|
+
}
|
|
190
|
+
catch (e_3) {
|
|
191
|
+
env_3.error = e_3;
|
|
192
|
+
env_3.hasError = true;
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
__disposeResources(env_3);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get a value by its composite key.
|
|
200
|
+
*/
|
|
201
|
+
async get(key) {
|
|
202
|
+
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
203
|
+
try {
|
|
204
|
+
this.ensureInitialized();
|
|
205
|
+
const keyPath = this.serializeKey(key);
|
|
206
|
+
const lockKey = lockKeyFromStorageKey(key);
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
208
|
+
const _lock = __addDisposableResource(env_4, await RWLock.read(lockKey), false);
|
|
209
|
+
try {
|
|
210
|
+
const row = this.db.prepare('SELECT value FROM key_store WHERE key_path = ?').get(keyPath);
|
|
211
|
+
if (!row) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
return JSON.parse(row.value.toString('utf8'));
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw new Error(`Failed to get key ${keyPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (e_4) {
|
|
221
|
+
env_4.error = e_4;
|
|
222
|
+
env_4.hasError = true;
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
__disposeResources(env_4);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Initialize the storage backend.
|
|
230
|
+
* Creates the database and runs migrations.
|
|
231
|
+
*/
|
|
232
|
+
async initialize() {
|
|
233
|
+
if (this.initialized) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
// Ensure storage directory exists (skip for in-memory)
|
|
238
|
+
if (!this.inMemory) {
|
|
239
|
+
await fs.mkdir(this.storageDir, { recursive: true });
|
|
240
|
+
}
|
|
241
|
+
// Open/create database
|
|
242
|
+
this.db = new Database(this.dbPath);
|
|
243
|
+
// Enable WAL mode for better concurrent performance
|
|
244
|
+
this.db.pragma('journal_mode = WAL');
|
|
245
|
+
// Create key_store table
|
|
246
|
+
this.db.exec(`
|
|
247
|
+
CREATE TABLE IF NOT EXISTS key_store (
|
|
248
|
+
key_path TEXT PRIMARY KEY,
|
|
249
|
+
value BLOB NOT NULL,
|
|
250
|
+
created_at INTEGER NOT NULL,
|
|
251
|
+
updated_at INTEGER NOT NULL
|
|
252
|
+
)
|
|
253
|
+
`);
|
|
254
|
+
// Create index for prefix-based listing
|
|
255
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_key_store_prefix ON key_store(key_path)`);
|
|
256
|
+
this.initialized = true;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
throw new Error(`Failed to initialize SQLite key storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* List all keys matching a prefix.
|
|
264
|
+
*/
|
|
265
|
+
async list(prefix) {
|
|
266
|
+
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
267
|
+
try {
|
|
268
|
+
this.ensureInitialized();
|
|
269
|
+
const prefixPath = this.serializeKey(prefix);
|
|
270
|
+
const lockKey = lockKeyFromStorageKey(prefix);
|
|
271
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
272
|
+
const _lock = __addDisposableResource(env_5, await RWLock.read(lockKey), false);
|
|
273
|
+
try {
|
|
274
|
+
// Use LIKE with prefix pattern for efficient prefix matching
|
|
275
|
+
const rows = this.db.prepare('SELECT key_path FROM key_store WHERE key_path LIKE ? ORDER BY key_path').all(`${prefixPath}%`);
|
|
276
|
+
return rows.map((row) => this.deserializeKey(row.key_path));
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
throw new Error(`Failed to list keys with prefix ${prefixPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (e_5) {
|
|
283
|
+
env_5.error = e_5;
|
|
284
|
+
env_5.hasError = true;
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
__disposeResources(env_5);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Set a value at a composite key.
|
|
292
|
+
*/
|
|
293
|
+
async set(key, value) {
|
|
294
|
+
const env_6 = { stack: [], error: void 0, hasError: false };
|
|
295
|
+
try {
|
|
296
|
+
this.ensureInitialized();
|
|
297
|
+
const keyPath = this.serializeKey(key);
|
|
298
|
+
const lockKey = lockKeyFromStorageKey(key);
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
300
|
+
const _lock = __addDisposableResource(env_6, await RWLock.write(lockKey), false);
|
|
301
|
+
const now = Date.now();
|
|
302
|
+
const valueJson = JSON.stringify(value);
|
|
303
|
+
try {
|
|
304
|
+
// Check if exists to preserve created_at
|
|
305
|
+
const existing = this.db.prepare('SELECT created_at FROM key_store WHERE key_path = ?').get(keyPath);
|
|
306
|
+
this.db.prepare(`
|
|
307
|
+
INSERT INTO key_store (key_path, value, created_at, updated_at)
|
|
308
|
+
VALUES (?, ?, ?, ?)
|
|
309
|
+
ON CONFLICT(key_path) DO UPDATE SET
|
|
310
|
+
value = excluded.value,
|
|
311
|
+
updated_at = excluded.updated_at
|
|
312
|
+
`).run(keyPath, Buffer.from(valueJson), existing?.created_at ?? now, now);
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
throw new Error(`Failed to set key ${keyPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch (e_6) {
|
|
319
|
+
env_6.error = e_6;
|
|
320
|
+
env_6.hasError = true;
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
__disposeResources(env_6);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Atomic update with optimistic locking.
|
|
328
|
+
*/
|
|
329
|
+
async update(key, updater) {
|
|
330
|
+
const env_7 = { stack: [], error: void 0, hasError: false };
|
|
331
|
+
try {
|
|
332
|
+
this.ensureInitialized();
|
|
333
|
+
const keyPath = this.serializeKey(key);
|
|
334
|
+
const lockKey = lockKeyFromStorageKey(key);
|
|
335
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
336
|
+
const _lock = __addDisposableResource(env_7, await RWLock.write(lockKey), false);
|
|
337
|
+
try {
|
|
338
|
+
// Read current value
|
|
339
|
+
const row = this.db.prepare('SELECT value, created_at FROM key_store WHERE key_path = ?').get(keyPath);
|
|
340
|
+
const currentValue = row ? JSON.parse(row.value.toString('utf8')) : undefined;
|
|
341
|
+
// Apply updater function
|
|
342
|
+
const newValue = updater(currentValue);
|
|
343
|
+
// Write new value
|
|
344
|
+
const now = Date.now();
|
|
345
|
+
const valueJson = JSON.stringify(newValue);
|
|
346
|
+
this.db.prepare(`
|
|
347
|
+
INSERT INTO key_store (key_path, value, created_at, updated_at)
|
|
348
|
+
VALUES (?, ?, ?, ?)
|
|
349
|
+
ON CONFLICT(key_path) DO UPDATE SET
|
|
350
|
+
value = excluded.value,
|
|
351
|
+
updated_at = excluded.updated_at
|
|
352
|
+
`).run(keyPath, Buffer.from(valueJson), row?.created_at ?? now, now);
|
|
353
|
+
return newValue;
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
throw new Error(`Failed to update key ${keyPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch (e_7) {
|
|
360
|
+
env_7.error = e_7;
|
|
361
|
+
env_7.hasError = true;
|
|
362
|
+
}
|
|
363
|
+
finally {
|
|
364
|
+
__disposeResources(env_7);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Deserialize a key path string back to StorageKey.
|
|
369
|
+
* Converts "message:session123:msg456" to ["message", "session123", "msg456"]
|
|
370
|
+
*/
|
|
371
|
+
deserializeKey(keyPath) {
|
|
372
|
+
return keyPath.split(':');
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Ensure storage has been initialized.
|
|
376
|
+
*/
|
|
377
|
+
ensureInitialized() {
|
|
378
|
+
if (!this.initialized || !this.db) {
|
|
379
|
+
throw new Error('SqliteKeyStorage not initialized. Call initialize() first.');
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Serialize a StorageKey to a string path.
|
|
384
|
+
* Converts ["message", "session123", "msg456"] to "message:session123:msg456"
|
|
385
|
+
*/
|
|
386
|
+
serializeKey(key) {
|
|
387
|
+
if (key.length === 0) {
|
|
388
|
+
throw new Error('Storage key cannot be empty');
|
|
389
|
+
}
|
|
390
|
+
// Validate key segments don't contain the separator
|
|
391
|
+
for (const segment of key) {
|
|
392
|
+
if (segment.includes(':')) {
|
|
393
|
+
throw new Error(`Key segment cannot contain ':': ${segment}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return key.join(':');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Factory function to create SqliteKeyStorage with common defaults.
|
|
401
|
+
*/
|
|
402
|
+
export function createKeyStorage(config) {
|
|
403
|
+
return new SqliteKeyStorage(config);
|
|
404
|
+
}
|
|
@@ -137,6 +137,13 @@ export class SimplePromptFactory {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
// Append file reference instructions after companion prompts (for curate command)
|
|
141
|
+
if (context.commandType === 'curate' && context.fileReferenceInstructions) {
|
|
142
|
+
finalPrompt = finalPrompt + '\n\n' + context.fileReferenceInstructions;
|
|
143
|
+
if (this.verbose) {
|
|
144
|
+
console.log(`[PromptDebug:SimpleFactory] Appended file reference instructions: ${context.fileReferenceInstructions.length} chars`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
140
147
|
}
|
|
141
148
|
if (this.verbose) {
|
|
142
149
|
console.log(`[PromptDebug:SimpleFactory] Final prompt: ${finalPrompt.length} chars`);
|
|
@@ -80,7 +80,7 @@ export const DEFAULT_POLICY_RULES = [
|
|
|
80
80
|
decision: 'ALLOW',
|
|
81
81
|
name: 'allow-write-tools',
|
|
82
82
|
reason: 'Write operations allowed in autonomous mode',
|
|
83
|
-
toolPattern: /^(write_file|edit_file|write_memory|edit_memory|delete_memory|create_knowledge_topic)$/,
|
|
83
|
+
toolPattern: /^(write_file|edit_file|write_memory|edit_memory|delete_memory|create_knowledge_topic |curate)$/,
|
|
84
84
|
},
|
|
85
85
|
/**
|
|
86
86
|
* Allow bash execution (autonomous mode, with DENY rules above as safety net).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Tool } from '../../../../core/domain/cipher/tools/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the curate tool.
|
|
4
|
+
*
|
|
5
|
+
* This tool manages knowledge topics with atomic operations (ADD, UPDATE, MERGE, DELETE).
|
|
6
|
+
* It applies patterns from the ACE Curator for intelligent knowledge curation.
|
|
7
|
+
*
|
|
8
|
+
* @returns Configured curate tool
|
|
9
|
+
*/
|
|
10
|
+
export declare function createCurateTool(): Tool;
|