cloving 0.3.19 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +1 -1
- package/README.md +475 -182
- package/dist/src/authority/budgets.d.ts +12 -0
- package/dist/src/authority/budgets.js +42 -0
- package/dist/src/authority/commands.d.ts +7 -0
- package/dist/src/authority/commands.js +263 -0
- package/dist/src/authority/details.d.ts +28 -0
- package/dist/src/authority/details.js +33 -0
- package/dist/src/authority/dispatch-decision.d.ts +40 -0
- package/dist/src/authority/dispatch-decision.js +47 -0
- package/dist/src/authority/effect-requests.d.ts +2 -0
- package/dist/src/authority/effect-requests.js +139 -0
- package/dist/src/authority/effect-results.d.ts +4 -0
- package/dist/src/authority/effect-results.js +236 -0
- package/dist/src/authority/events.d.ts +2 -0
- package/dist/src/authority/events.js +45 -0
- package/dist/src/authority/gate-reduction.d.ts +8 -0
- package/dist/src/authority/gate-reduction.js +109 -0
- package/dist/src/authority/gates.d.ts +48 -0
- package/dist/src/authority/gates.js +77 -0
- package/dist/src/authority/history-state.d.ts +15 -0
- package/dist/src/authority/history-state.js +61 -0
- package/dist/src/authority/history.d.ts +13 -0
- package/dist/src/authority/history.js +37 -0
- package/dist/src/authority/instants.d.ts +3 -0
- package/dist/src/authority/instants.js +38 -0
- package/dist/src/authority/leases.d.ts +15 -0
- package/dist/src/authority/leases.js +113 -0
- package/dist/src/authority/operations.d.ts +101 -0
- package/dist/src/authority/operations.js +75 -0
- package/dist/src/authority/reconciliation.d.ts +27 -0
- package/dist/src/authority/reconciliation.js +147 -0
- package/dist/src/authority/reducer.d.ts +41 -0
- package/dist/src/authority/reducer.js +139 -0
- package/dist/src/authority/reduction-state.d.ts +36 -0
- package/dist/src/authority/reduction-state.js +68 -0
- package/dist/src/authority/reduction.d.ts +6 -0
- package/dist/src/authority/reduction.js +160 -0
- package/dist/src/authority/status-closure.d.ts +4 -0
- package/dist/src/authority/status-closure.js +57 -0
- package/dist/src/authority/status-effects.d.ts +17 -0
- package/dist/src/authority/status-effects.js +43 -0
- package/dist/src/authority/status-input.d.ts +45 -0
- package/dist/src/authority/status-input.js +9 -0
- package/dist/src/authority/status.d.ts +32 -0
- package/dist/src/authority/status.js +256 -0
- package/dist/src/authority/stop-sequence.d.ts +37 -0
- package/dist/src/authority/stop-sequence.js +91 -0
- package/dist/src/authority/transitions.d.ts +63 -0
- package/dist/src/authority/transitions.js +122 -0
- package/dist/src/broker/actor/adapter-calls.d.ts +13 -0
- package/dist/src/broker/actor/adapter-calls.js +34 -0
- package/dist/src/broker/actor/adapter-outcomes.d.ts +28 -0
- package/dist/src/broker/actor/adapter-outcomes.js +80 -0
- package/dist/src/broker/actor/authority-actor.d.ts +25 -0
- package/dist/src/broker/actor/authority-actor.js +169 -0
- package/dist/src/broker/actor/authority-changes.d.ts +31 -0
- package/dist/src/broker/actor/authority-changes.js +46 -0
- package/dist/src/broker/actor/authority-connection.d.ts +15 -0
- package/dist/src/broker/actor/authority-connection.js +44 -0
- package/dist/src/broker/actor/authority-conversion.d.ts +10 -0
- package/dist/src/broker/actor/authority-conversion.js +72 -0
- package/dist/src/broker/actor/authority-delivery.d.ts +13 -0
- package/dist/src/broker/actor/authority-delivery.js +162 -0
- package/dist/src/broker/actor/authority-logger.d.ts +2 -0
- package/dist/src/broker/actor/authority-logger.js +19 -0
- package/dist/src/broker/actor/authority-policy.d.ts +9 -0
- package/dist/src/broker/actor/authority-policy.js +11 -0
- package/dist/src/broker/actor/authority-queries.d.ts +45 -0
- package/dist/src/broker/actor/authority-queries.js +85 -0
- package/dist/src/broker/actor/authority-receipts.d.ts +28 -0
- package/dist/src/broker/actor/authority-receipts.js +84 -0
- package/dist/src/broker/actor/authority-release.d.ts +13 -0
- package/dist/src/broker/actor/authority-release.js +69 -0
- package/dist/src/broker/actor/authority-runtime.d.ts +60 -0
- package/dist/src/broker/actor/authority-runtime.js +204 -0
- package/dist/src/broker/actor/authority-session.d.ts +65 -0
- package/dist/src/broker/actor/authority-session.js +252 -0
- package/dist/src/broker/actor/authority-settings.d.ts +33 -0
- package/dist/src/broker/actor/authority-settings.js +63 -0
- package/dist/src/broker/actor/authority-upgrades.d.ts +16 -0
- package/dist/src/broker/actor/authority-upgrades.js +12 -0
- package/dist/src/broker/actor/authority-watchdog.d.ts +14 -0
- package/dist/src/broker/actor/authority-watchdog.js +41 -0
- package/dist/src/broker/actor/authority.d.ts +14 -0
- package/dist/src/broker/actor/authority.js +115 -0
- package/dist/src/broker/actor/delivery-intents.d.ts +68 -0
- package/dist/src/broker/actor/delivery-intents.js +77 -0
- package/dist/src/broker/actor/delivery-plan.d.ts +2 -0
- package/dist/src/broker/actor/delivery-plan.js +109 -0
- package/dist/src/broker/actor/delivery-results.d.ts +11 -0
- package/dist/src/broker/actor/delivery-results.js +63 -0
- package/dist/src/broker/actor/effect-delivery.d.ts +19 -0
- package/dist/src/broker/actor/effect-delivery.js +118 -0
- package/dist/src/broker/actor/effect-plan.d.ts +41 -0
- package/dist/src/broker/actor/effect-plan.js +173 -0
- package/dist/src/broker/actor/effect-queries.d.ts +27 -0
- package/dist/src/broker/actor/effect-queries.js +80 -0
- package/dist/src/broker/actor/effect-turn.d.ts +25 -0
- package/dist/src/broker/actor/effect-turn.js +84 -0
- package/dist/src/broker/actor/pin-check.d.ts +6 -0
- package/dist/src/broker/actor/pin-check.js +12 -0
- package/dist/src/broker/actor/runtime-parts.d.ts +23 -0
- package/dist/src/broker/actor/runtime-parts.js +34 -0
- package/dist/src/broker/actor/stop-plan.d.ts +20 -0
- package/dist/src/broker/actor/stop-plan.js +46 -0
- package/dist/src/broker/actor/stop-turn.d.ts +17 -0
- package/dist/src/broker/actor/stop-turn.js +42 -0
- package/dist/src/broker/actor/turn-draft.d.ts +31 -0
- package/dist/src/broker/actor/turn-draft.js +138 -0
- package/dist/src/broker/actor/turn-plan.d.ts +17 -0
- package/dist/src/broker/actor/turn-plan.js +136 -0
- package/dist/src/broker/actor/turn-refusals.d.ts +8 -0
- package/dist/src/broker/actor/turn-refusals.js +35 -0
- package/dist/src/broker/actor/turn-staging.d.ts +78 -0
- package/dist/src/broker/actor/turn-staging.js +34 -0
- package/dist/src/broker/actor/turn-state.d.ts +34 -0
- package/dist/src/broker/actor/turn-state.js +208 -0
- package/dist/src/broker/authority-admission.d.ts +21 -0
- package/dist/src/broker/authority-admission.js +70 -0
- package/dist/src/broker/authority-restore.d.ts +30 -0
- package/dist/src/broker/authority-restore.js +165 -0
- package/dist/src/broker/decision-restore.d.ts +16 -0
- package/dist/src/broker/decision-restore.js +158 -0
- package/dist/src/broker/decision-upgrade.d.ts +3 -0
- package/dist/src/broker/decision-upgrade.js +12 -0
- package/dist/src/broker/effect-restore.d.ts +20 -0
- package/dist/src/broker/effect-restore.js +111 -0
- package/dist/src/broker/effect-upgrade.d.ts +3 -0
- package/dist/src/broker/effect-upgrade.js +9 -0
- package/dist/src/broker/operation-digest.d.ts +1 -0
- package/dist/src/broker/operation-digest.js +4 -0
- package/dist/src/broker/socket-address.d.ts +9 -0
- package/dist/src/broker/socket-address.js +14 -0
- package/dist/src/broker/workflow-pin.d.ts +2 -0
- package/dist/src/broker/workflow-pin.js +5 -0
- package/dist/src/chats/destination.d.ts +4 -0
- package/dist/src/chats/destination.js +94 -0
- package/dist/src/chats/import.d.ts +13 -0
- package/dist/src/chats/import.js +71 -0
- package/dist/src/chats/normalize.d.ts +20 -0
- package/dist/src/chats/normalize.js +139 -0
- package/dist/src/chats/reader.d.ts +15 -0
- package/dist/src/chats/reader.js +87 -0
- package/dist/src/cli/arguments.d.ts +23 -0
- package/dist/src/cli/arguments.js +154 -0
- package/dist/src/cli/client.d.ts +15 -0
- package/dist/src/cli/client.js +122 -0
- package/dist/src/cli/commands.d.ts +14 -0
- package/dist/src/cli/commands.js +253 -0
- package/dist/src/cli/main.d.ts +1 -0
- package/dist/src/cli/main.js +80 -0
- package/dist/src/cli/render.d.ts +8 -0
- package/dist/src/cli/render.js +186 -0
- package/dist/src/cli/runtime-arguments.d.ts +73 -0
- package/dist/src/cli/runtime-arguments.js +248 -0
- package/dist/src/cli/runtime-directory.d.ts +4 -0
- package/dist/src/cli/runtime-directory.js +25 -0
- package/dist/src/cli/toolchain.d.ts +3 -0
- package/dist/src/cli/toolchain.js +74 -0
- package/dist/src/cli/usage.d.ts +4 -0
- package/dist/src/cli/usage.js +124 -0
- package/dist/src/cli/validate.d.ts +38 -0
- package/dist/src/cli/validate.js +116 -0
- package/dist/src/cli/watch-board-view.d.ts +22 -0
- package/dist/src/cli/watch-board-view.js +128 -0
- package/dist/src/cli/watch-board.d.ts +15 -0
- package/dist/src/cli/watch-board.js +174 -0
- package/dist/src/cli/watch-element.d.ts +11 -0
- package/dist/src/cli/watch-element.js +6 -0
- package/dist/src/cli/watch-model.d.ts +29 -0
- package/dist/src/cli/watch-model.js +261 -0
- package/dist/src/cli/watch-navigation.d.ts +9 -0
- package/dist/src/cli/watch-navigation.js +40 -0
- package/dist/src/cli/watch-page.d.ts +1 -0
- package/dist/src/cli/watch-page.js +272 -0
- package/dist/src/cli/watch-paths.d.ts +2 -0
- package/dist/src/cli/watch-paths.js +52 -0
- package/dist/src/cli/watch-phases.d.ts +7 -0
- package/dist/src/cli/watch-phases.js +148 -0
- package/dist/src/cli/watch-reads.d.ts +28 -0
- package/dist/src/cli/watch-reads.js +244 -0
- package/dist/src/cli/watch-render.d.ts +139 -0
- package/dist/src/cli/watch-render.js +95 -0
- package/dist/src/cli/watch-server.d.ts +10 -0
- package/dist/src/cli/watch-server.js +176 -0
- package/dist/src/cli/watch-stream.d.ts +11 -0
- package/dist/src/cli/watch-stream.js +128 -0
- package/dist/src/cli/watch-turn.d.ts +29 -0
- package/dist/src/cli/watch-turn.js +130 -0
- package/dist/src/cli/watch-view.d.ts +39 -0
- package/dist/src/cli/watch-view.js +223 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +62 -0
- package/dist/src/daemon/claude-turn.d.ts +28 -0
- package/dist/src/daemon/claude-turn.js +135 -0
- package/dist/src/daemon/claude-worker.d.ts +26 -0
- package/dist/src/daemon/claude-worker.js +224 -0
- package/dist/src/daemon/codex-stream.d.ts +4 -0
- package/dist/src/daemon/codex-stream.js +113 -0
- package/dist/src/daemon/daemon.d.ts +46 -0
- package/dist/src/daemon/daemon.js +186 -0
- package/dist/src/daemon/delivery-router.d.ts +10 -0
- package/dist/src/daemon/delivery-router.js +34 -0
- package/dist/src/daemon/github-calls.d.ts +29 -0
- package/dist/src/daemon/github-calls.js +127 -0
- package/dist/src/daemon/github-issue-methods.d.ts +3 -0
- package/dist/src/daemon/github-issue-methods.js +99 -0
- package/dist/src/daemon/github-issue-privacy.d.ts +6 -0
- package/dist/src/daemon/github-issue-privacy.js +131 -0
- package/dist/src/daemon/github-merge.d.ts +18 -0
- package/dist/src/daemon/github-merge.js +259 -0
- package/dist/src/daemon/github-methods.d.ts +5 -0
- package/dist/src/daemon/github-methods.js +198 -0
- package/dist/src/daemon/github-operation.d.ts +38 -0
- package/dist/src/daemon/github-operation.js +57 -0
- package/dist/src/daemon/github-worker.d.ts +17 -0
- package/dist/src/daemon/github-worker.js +281 -0
- package/dist/src/daemon/host-environment.d.ts +8 -0
- package/dist/src/daemon/host-environment.js +14 -0
- package/dist/src/daemon/issue-queue.d.ts +9 -0
- package/dist/src/daemon/issue-queue.js +163 -0
- package/dist/src/daemon/notify-message.d.ts +14 -0
- package/dist/src/daemon/notify-message.js +48 -0
- package/dist/src/daemon/notify.d.ts +12 -0
- package/dist/src/daemon/notify.js +161 -0
- package/dist/src/daemon/operation-journal.d.ts +42 -0
- package/dist/src/daemon/operation-journal.js +53 -0
- package/dist/src/daemon/ticket-registration.d.ts +33 -0
- package/dist/src/daemon/ticket-registration.js +177 -0
- package/dist/src/daemon/ticket-source.d.ts +17 -0
- package/dist/src/daemon/ticket-source.js +36 -0
- package/dist/src/daemon/work-tree.d.ts +26 -0
- package/dist/src/daemon/work-tree.js +206 -0
- package/dist/src/effect-authorization.d.ts +21 -0
- package/dist/src/effect-authorization.js +14 -0
- package/dist/src/execution-pin.d.ts +4 -0
- package/dist/src/execution-pin.js +68 -0
- package/dist/src/host/start-delivery.d.ts +41 -0
- package/dist/src/host/start-delivery.js +68 -0
- package/dist/src/host/step-bridge-host.d.ts +79 -0
- package/dist/src/host/step-bridge-host.js +205 -0
- package/dist/src/host/step-claims.d.ts +31 -0
- package/dist/src/host/step-claims.js +85 -0
- package/dist/src/host/world-host.d.ts +21 -0
- package/dist/src/host/world-host.js +51 -0
- package/dist/src/host/world-reconciliation.d.ts +37 -0
- package/dist/src/host/world-reconciliation.js +75 -0
- package/dist/src/host/world-runs.d.ts +14 -0
- package/dist/src/host/world-runs.js +61 -0
- package/dist/src/operation-identity.d.ts +7 -0
- package/dist/src/operation-identity.js +59 -0
- package/dist/src/protocol.d.ts +35 -0
- package/dist/src/protocol.js +64 -0
- package/dist/src/resource-files.d.ts +1 -0
- package/dist/src/resource-files.js +29 -0
- package/dist/src/service/changes.d.ts +11 -0
- package/dist/src/service/changes.js +32 -0
- package/dist/src/service/decision-handler.d.ts +9 -0
- package/dist/src/service/decision-handler.js +233 -0
- package/dist/src/service/event-handler.d.ts +10 -0
- package/dist/src/service/event-handler.js +70 -0
- package/dist/src/service/expiry.d.ts +13 -0
- package/dist/src/service/expiry.js +53 -0
- package/dist/src/service/gateway.d.ts +21 -0
- package/dist/src/service/gateway.js +120 -0
- package/dist/src/service/registry.d.ts +40 -0
- package/dist/src/service/registry.js +13 -0
- package/dist/src/service/replies.d.ts +26 -0
- package/dist/src/service/replies.js +56 -0
- package/dist/src/service/run-handlers.d.ts +4 -0
- package/dist/src/service/run-handlers.js +271 -0
- package/dist/src/service/service.d.ts +58 -0
- package/dist/src/service/service.js +212 -0
- package/dist/src/service/submission-handler.d.ts +4 -0
- package/dist/src/service/submission-handler.js +206 -0
- package/dist/src/service/transport.d.ts +16 -0
- package/dist/src/service/transport.js +141 -0
- package/dist/src/service/worker-port.d.ts +85 -0
- package/dist/src/service/worker-port.js +126 -0
- package/dist/src/step-bridge.d.ts +57 -0
- package/dist/src/step-bridge.js +4 -0
- package/dist/src/steps/decision-gate.d.ts +2 -0
- package/dist/src/steps/decision-gate.js +8 -0
- package/dist/src/steps/load-cycle.d.ts +10 -0
- package/dist/src/steps/load-cycle.js +11 -0
- package/dist/src/steps/protected-effect.d.ts +2 -0
- package/dist/src/steps/protected-effect.js +8 -0
- package/dist/src/storage/decision-rows.d.ts +54 -0
- package/dist/src/storage/decision-rows.js +72 -0
- package/dist/src/storage/decision-snapshots.d.ts +17 -0
- package/dist/src/storage/decision-snapshots.js +25 -0
- package/dist/src/storage/domain-changes.d.ts +48 -0
- package/dist/src/storage/domain-changes.js +213 -0
- package/dist/src/storage/domain-rows.d.ts +85 -0
- package/dist/src/storage/domain-rows.js +129 -0
- package/dist/src/storage/domain-schema.d.ts +32 -0
- package/dist/src/storage/domain-schema.js +193 -0
- package/dist/src/storage/effect-changes.d.ts +5 -0
- package/dist/src/storage/effect-changes.js +105 -0
- package/dist/src/storage/effect-rows.d.ts +67 -0
- package/dist/src/storage/effect-rows.js +74 -0
- package/dist/src/storage/effect-schema.d.ts +1 -0
- package/dist/src/storage/effect-schema.js +59 -0
- package/dist/src/storage/statements.d.ts +9 -0
- package/dist/src/storage/statements.js +8 -0
- package/dist/src/submission.d.ts +42 -0
- package/dist/src/submission.js +71 -0
- package/dist/src/turn-profile.d.ts +13 -0
- package/dist/src/turn-profile.js +100 -0
- package/dist/src/workflow-admission.d.ts +45 -0
- package/dist/src/workflow-admission.js +151 -0
- package/dist/src/workflow-contracts.d.ts +27 -0
- package/dist/src/workflow-contracts.js +88 -0
- package/dist/src/workflow-declaration.d.ts +11 -0
- package/dist/src/workflow-declaration.js +57 -0
- package/dist/src/workflow-resources.d.ts +8 -0
- package/dist/src/workflow-resources.js +14 -0
- package/dist/src/workflows.d.ts +5 -0
- package/dist/src/workflows.js +3 -0
- package/dist/tools/compile-workflows.d.ts +1 -0
- package/dist/tools/compile-workflows.js +33 -0
- package/dist/tools/self-host-processes.d.ts +10 -0
- package/dist/tools/self-host-processes.js +151 -0
- package/dist/tools/self-host-workflows.d.ts +15 -0
- package/dist/tools/self-host-workflows.js +78 -0
- package/dist/tools/self-host.d.ts +1 -0
- package/dist/tools/self-host.js +261 -0
- package/dist/tools/self-update-host.d.ts +6 -0
- package/dist/tools/self-update-host.js +41 -0
- package/dist/tools/self-update.d.ts +10 -0
- package/dist/tools/self-update.js +105 -0
- package/dist/tools/workflow-manifest.d.ts +3 -0
- package/dist/tools/workflow-manifest.js +34 -0
- package/dist/workflows/develop-prd.d.ts +7 -0
- package/dist/workflows/develop-prd.js +97 -0
- package/dist/workflows/develop-ticket.d.ts +15 -0
- package/dist/workflows/develop-ticket.js +301 -0
- package/dist/workflows/issue-labels.d.ts +14 -0
- package/dist/workflows/issue-labels.js +36 -0
- package/package.json +82 -75
- package/.DS_Store +0 -0
- package/.aider.chat.history.md +0 -16978
- package/.aider.input.history +0 -15
- package/.aider.tags.cache.v3/cache.db +0 -0
- package/.aider.tags.cache.v3/cache.db-shm +0 -0
- package/.aider.tags.cache.v3/cache.db-wal +0 -0
- package/.cursorrules +0 -77
- package/.github/workflows/auto-release.yml +0 -83
- package/.github/workflows/ci.yml +0 -32
- package/.github/workflows/npm-publish.yml +0 -34
- package/.gitignore +0 -67
- package/.husky/_/.gitignore +0 -1
- package/.husky/_/applypatch-msg +0 -2
- package/.husky/_/commit-msg +0 -2
- package/.husky/_/h +0 -22
- package/.husky/_/husky.sh +0 -9
- package/.husky/_/post-applypatch +0 -2
- package/.husky/_/post-checkout +0 -2
- package/.husky/_/post-commit +0 -2
- package/.husky/_/post-merge +0 -2
- package/.husky/_/post-rewrite +0 -2
- package/.husky/_/pre-applypatch +0 -2
- package/.husky/_/pre-auto-gc +0 -2
- package/.husky/_/pre-commit +0 -2
- package/.husky/_/pre-merge-commit +0 -2
- package/.husky/_/pre-push +0 -2
- package/.husky/_/pre-rebase +0 -2
- package/.husky/_/prepare-commit-msg +0 -2
- package/.husky/pre-commit +0 -1
- package/.husky/pre-push +0 -1
- package/.prettierrc.json +0 -7
- package/.tool-versions +0 -2
- package/SECURITY.md +0 -15
- package/cloving.json +0 -67
- package/dist/abstract_gpt/index.js +0 -55
- package/dist/cloving_gpt/adapters/Adapter.js +0 -2
- package/dist/cloving_gpt/adapters/azureopenai.js +0 -69
- package/dist/cloving_gpt/adapters/claude.js +0 -128
- package/dist/cloving_gpt/adapters/gemini.js +0 -135
- package/dist/cloving_gpt/adapters/gpt4all.js +0 -29
- package/dist/cloving_gpt/adapters/index.js +0 -2
- package/dist/cloving_gpt/adapters/mistral.js +0 -128
- package/dist/cloving_gpt/adapters/ollama.js +0 -128
- package/dist/cloving_gpt/adapters/openai.js +0 -100
- package/dist/cloving_gpt/index.js +0 -192
- package/dist/commands/analyze.js +0 -47
- package/dist/commands/chat.js +0 -14
- package/dist/commands/check.js +0 -7
- package/dist/commands/commit.js +0 -44
- package/dist/commands/config.js +0 -167
- package/dist/commands/describe.js +0 -235
- package/dist/commands/generate/code.js +0 -21
- package/dist/commands/generate/commit.js +0 -11
- package/dist/commands/generate/context.js +0 -82
- package/dist/commands/generate/docs.js +0 -11
- package/dist/commands/generate/documentation.js +0 -11
- package/dist/commands/generate/fizzbuzz.js +0 -35
- package/dist/commands/generate/init.js +0 -15
- package/dist/commands/generate/review.js +0 -11
- package/dist/commands/generate/sh.js +0 -95
- package/dist/commands/generate/shell.js +0 -11
- package/dist/commands/generate/unit_tests.js +0 -11
- package/dist/commands/init.js +0 -13
- package/dist/commands/models.js +0 -22
- package/dist/commands/project/build.js +0 -88
- package/dist/commands/project/complete.js +0 -12
- package/dist/commands/project/init.js +0 -82
- package/dist/commands/project/plan.js +0 -108
- package/dist/commands/proxy.js +0 -11
- package/dist/commands/review.js +0 -50
- package/dist/commands/tokens.js +0 -75
- package/dist/commands/unit_tests.js +0 -150
- package/dist/commands/update.js +0 -7
- package/dist/file2.js +0 -4
- package/dist/index.js +0 -134
- package/dist/managers/BlockManager.js +0 -120
- package/dist/managers/ChatManager.js +0 -653
- package/dist/managers/ChunkManager.js +0 -32
- package/dist/managers/CodeManager.js +0 -185
- package/dist/managers/CommitManager.js +0 -64
- package/dist/managers/DocsManager.js +0 -88
- package/dist/managers/DocumentationManager.js +0 -114
- package/dist/managers/InitManager.js +0 -230
- package/dist/managers/ProxyManager.js +0 -210
- package/dist/managers/ReviewManager.js +0 -131
- package/dist/managers/ShellManager.js +0 -163
- package/dist/managers/StreamManager.js +0 -308
- package/dist/managers/UnitTestManager.js +0 -243
- package/dist/managers/src/managers/ProxyManager.js +0 -1
- package/dist/newfile.js +0 -2
- package/dist/package.json +0 -86
- package/dist/utils/command_utils.js +0 -384
- package/dist/utils/config_utils.js +0 -249
- package/dist/utils/gitUtils.js +0 -42
- package/dist/utils/git_utils.js +0 -217
- package/dist/utils/modelUtils.js +0 -7
- package/dist/utils/model_utils.js +0 -7
- package/dist/utils/prompt_utils.js +0 -333
- package/dist/utils/prompts/CODEGEN_COULDNT_APPLY.md +0 -5
- package/dist/utils/prompts/CODEGEN_EXAMPLES.md +0 -82
- package/dist/utils/prompts/CODEGEN_INSTRUCTIONS.md +0 -43
- package/dist/utils/prompts/DOCS_INSTRUCTIONS.md +0 -9
- package/dist/utils/prompts/INIT_INSTRUCTIONS.md +0 -132
- package/dist/utils/prompts/REVIEW_INSTRUCTIONS.md +0 -49
- package/dist/utils/prompts/SHELL_INSTRUCTIONS.md +0 -15
- package/dist/utils/prompts/SPECIAL_FILES.md +0 -66
- package/dist/utils/prompts/index.js +0 -27
- package/dist/utils/string_utils.js +0 -505
- package/dist/utils/types.js +0 -2
- package/jest.config.js +0 -11
- package/src/cloving_gpt/adapters/azureopenai.ts +0 -83
- package/src/cloving_gpt/adapters/claude.ts +0 -140
- package/src/cloving_gpt/adapters/gemini.ts +0 -146
- package/src/cloving_gpt/adapters/index.ts +0 -43
- package/src/cloving_gpt/adapters/mistral.ts +0 -142
- package/src/cloving_gpt/adapters/ollama.ts +0 -136
- package/src/cloving_gpt/adapters/openai.ts +0 -113
- package/src/cloving_gpt/index.ts +0 -229
- package/src/commands/chat.ts +0 -12
- package/src/commands/config.ts +0 -192
- package/src/commands/generate/code.ts +0 -18
- package/src/commands/generate/commit.ts +0 -9
- package/src/commands/generate/context.ts +0 -93
- package/src/commands/generate/docs.ts +0 -9
- package/src/commands/generate/review.ts +0 -9
- package/src/commands/generate/shell.ts +0 -9
- package/src/commands/generate/unit_tests.ts +0 -9
- package/src/commands/init.ts +0 -9
- package/src/commands/models.ts +0 -21
- package/src/commands/proxy.ts +0 -9
- package/src/commands/tokens.ts +0 -82
- package/src/index.ts +0 -197
- package/src/managers/BlockManager.ts +0 -126
- package/src/managers/ChatManager.ts +0 -755
- package/src/managers/ChunkManager.ts +0 -31
- package/src/managers/CodeManager.ts +0 -226
- package/src/managers/CommitManager.ts +0 -71
- package/src/managers/DocsManager.ts +0 -101
- package/src/managers/InitManager.ts +0 -263
- package/src/managers/ProxyManager.ts +0 -240
- package/src/managers/ReviewManager.ts +0 -154
- package/src/managers/ShellManager.ts +0 -172
- package/src/managers/StreamManager.ts +0 -353
- package/src/managers/UnitTestManager.ts +0 -293
- package/src/utils/config_utils.ts +0 -271
- package/src/utils/git_utils.ts +0 -230
- package/src/utils/model_utils.ts +0 -3
- package/src/utils/prompt_utils.ts +0 -375
- package/src/utils/prompts/CODEGEN_COULDNT_APPLY.md +0 -5
- package/src/utils/prompts/CODEGEN_EXAMPLES.md +0 -82
- package/src/utils/prompts/CODEGEN_INSTRUCTIONS.md +0 -43
- package/src/utils/prompts/DOCS_INSTRUCTIONS.md +0 -9
- package/src/utils/prompts/INIT_INSTRUCTIONS.md +0 -132
- package/src/utils/prompts/REVIEW_INSTRUCTIONS.md +0 -49
- package/src/utils/prompts/SHELL_INSTRUCTIONS.md +0 -15
- package/src/utils/prompts/SPECIAL_FILES.md +0 -66
- package/src/utils/prompts/index.ts +0 -37
- package/src/utils/string_utils.ts +0 -552
- package/src/utils/types.ts +0 -127
- package/tests/commands/generate/unit_tests.test.ts +0 -27
- package/tests/utils/git_utils.test.ts +0 -116
- package/tests/utils/model_utils.test.ts +0 -27
- package/tests/utils/prompt_utils.test.ts +0 -33
- package/tests/utils/string_utils.test.ts +0 -560
- package/tsconfig.json +0 -14
- package/yarn.lock +0 -5823
|
@@ -1,755 +0,0 @@
|
|
|
1
|
-
import ncp from 'copy-paste'
|
|
2
|
-
import colors from 'colors'
|
|
3
|
-
import highlight from 'cli-highlight'
|
|
4
|
-
import readline from 'readline'
|
|
5
|
-
import { execSync } from 'child_process'
|
|
6
|
-
import type { AxiosError } from 'axios'
|
|
7
|
-
|
|
8
|
-
import CommitManager from './CommitManager'
|
|
9
|
-
import ReviewManager from './ReviewManager'
|
|
10
|
-
import {
|
|
11
|
-
extractCurrentNewBlocks,
|
|
12
|
-
applyAndSaveCurrentNewBlocks,
|
|
13
|
-
checkBlocksApplicability,
|
|
14
|
-
} from '../utils/string_utils'
|
|
15
|
-
import { getConfig } from '../utils/config_utils'
|
|
16
|
-
import { addFileOrDirectoryToContext } from '../utils/prompt_utils'
|
|
17
|
-
import { CODEGEN_COULDNT_APPLY } from '../utils/prompts'
|
|
18
|
-
import type { ClovingGPTOptions } from '../utils/types'
|
|
19
|
-
import StreamManager from './StreamManager'
|
|
20
|
-
|
|
21
|
-
const specialCommands = [
|
|
22
|
-
'save',
|
|
23
|
-
'commit',
|
|
24
|
-
'copy',
|
|
25
|
-
'review',
|
|
26
|
-
'add <file-path>',
|
|
27
|
-
'find <file-name>',
|
|
28
|
-
'rm <pattern>',
|
|
29
|
-
'ls <pattern>',
|
|
30
|
-
'git <command>',
|
|
31
|
-
'help',
|
|
32
|
-
'exit',
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
class ChatManager extends StreamManager {
|
|
36
|
-
private commandHistory: string[] = []
|
|
37
|
-
private historyIndex: number = -1
|
|
38
|
-
private multilineInput: string = ''
|
|
39
|
-
private isMultilineMode: boolean = false
|
|
40
|
-
private isSilent = false
|
|
41
|
-
private rl: readline.Interface
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Creates an instance of ChatManager.
|
|
45
|
-
* @param {ClovingGPTOptions} options - Configuration options for the ChatManager.
|
|
46
|
-
*/
|
|
47
|
-
constructor(options: ClovingGPTOptions) {
|
|
48
|
-
super(options)
|
|
49
|
-
this.isSilent = options.silent || getConfig(options).globalSilent || false
|
|
50
|
-
options.stream = true
|
|
51
|
-
options.silent = true
|
|
52
|
-
this.rl = readline.createInterface({
|
|
53
|
-
input: process.stdin,
|
|
54
|
-
output: process.stdout,
|
|
55
|
-
prompt: colors.green.bold('cloving> '),
|
|
56
|
-
historySize: 1000,
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Initializes the ChatManager by loading context files, displaying a welcome message,
|
|
62
|
-
* and setting up event listeners.
|
|
63
|
-
* @returns {Promise<void>}
|
|
64
|
-
*/
|
|
65
|
-
async initialize(): Promise<void> {
|
|
66
|
-
await this.checkForLatestVersion()
|
|
67
|
-
await this.loadContextFiles()
|
|
68
|
-
console.log(`\n🍀 🍀 🍀 ${colors.bold('Welcome to Cloving REPL')} 🍀 🍀 🍀\n`)
|
|
69
|
-
this.displayAvailableCommands()
|
|
70
|
-
console.log('\nWhat would you like to do?')
|
|
71
|
-
this.setupReadline()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private displayAvailableCommands(): void {
|
|
75
|
-
console.log(
|
|
76
|
-
`Type a freeform request or question to interact with your Cloving AI pair programmer.\n`,
|
|
77
|
-
)
|
|
78
|
-
console.log('Available special commands:')
|
|
79
|
-
console.log(
|
|
80
|
-
` - ${colors.yellow(colors.bold('save'))} Save all the changes from the last response to files`,
|
|
81
|
-
)
|
|
82
|
-
console.log(
|
|
83
|
-
` - ${colors.yellow(colors.bold('commit'))} Commit the changes to git with an AI-generated message that you can edit`,
|
|
84
|
-
)
|
|
85
|
-
console.log(
|
|
86
|
-
` - ${colors.yellow(colors.bold('copy'))} Copy the last response to clipboard`,
|
|
87
|
-
)
|
|
88
|
-
console.log(` - ${colors.yellow(colors.bold('review'))} Start a code review`)
|
|
89
|
-
console.log(
|
|
90
|
-
` - ${colors.yellow(colors.bold('find <file-name>'))} Find and add files matching the name to the chat context (supports * for glob matching)`,
|
|
91
|
-
)
|
|
92
|
-
console.log(
|
|
93
|
-
` - ${colors.yellow(colors.bold('add <file-path>'))} Add a file to the chat context (supports * for glob matching)`,
|
|
94
|
-
)
|
|
95
|
-
console.log(
|
|
96
|
-
` - ${colors.yellow(colors.bold('rm <pattern>'))} Remove files from the chat context (supports * for glob matching)`,
|
|
97
|
-
)
|
|
98
|
-
console.log(
|
|
99
|
-
` - ${colors.yellow(colors.bold('ls <pattern>'))} List files in the chat context (supports * for glob matching)`,
|
|
100
|
-
)
|
|
101
|
-
console.log(` - ${colors.yellow(colors.bold('git <command>'))} Run a git command`)
|
|
102
|
-
console.log(` - ${colors.yellow(colors.bold('help'))} Display this help message`)
|
|
103
|
-
console.log(` - ${colors.yellow(colors.bold('exit'))} Quit this session`)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Sets up readline and event listeners for the readline interface and process input.
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
private setupReadline(): void {
|
|
111
|
-
this.rl.prompt()
|
|
112
|
-
this.rl.on('line', this.handleLine.bind(this))
|
|
113
|
-
this.rl.on('close', this.handleClose.bind(this))
|
|
114
|
-
process.stdin.on('keypress', this.handleKeypress.bind(this))
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Handles each line of input from the user.
|
|
119
|
-
* @private
|
|
120
|
-
* @param {string} line - The input line from the user.
|
|
121
|
-
* @returns {Promise<void>}
|
|
122
|
-
*/
|
|
123
|
-
private async handleLine(line: string): Promise<void> {
|
|
124
|
-
if (this.isProcessing) {
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const trimmedLine = line.trim()
|
|
129
|
-
|
|
130
|
-
if (this.isPastedCode(trimmedLine)) {
|
|
131
|
-
this.multilineInput = trimmedLine
|
|
132
|
-
this.isMultilineMode = true
|
|
133
|
-
await this.handleCommand(this.multilineInput)
|
|
134
|
-
this.multilineInput = ''
|
|
135
|
-
this.isMultilineMode = false
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (this.handleMultilineInput(trimmedLine)) {
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (trimmedLine === '') {
|
|
144
|
-
this.displayPrompt()
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
this.updateCommandHistory(trimmedLine)
|
|
149
|
-
|
|
150
|
-
if (this.handleExitCommand(trimmedLine)) {
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
await this.handleCommand(trimmedLine)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private handleMultilineInput(line: string): boolean {
|
|
158
|
-
if (this.isMultilineMode) {
|
|
159
|
-
if (line === '```') {
|
|
160
|
-
this.isMultilineMode = false
|
|
161
|
-
this.handleCommand(this.multilineInput)
|
|
162
|
-
this.multilineInput = ''
|
|
163
|
-
} else {
|
|
164
|
-
this.multilineInput += line + '\n'
|
|
165
|
-
this.rl.prompt()
|
|
166
|
-
}
|
|
167
|
-
return true
|
|
168
|
-
} else if (line === '```') {
|
|
169
|
-
this.isMultilineMode = true
|
|
170
|
-
this.multilineInput = ''
|
|
171
|
-
console.log('Entering multiline mode. Type ``` on a new line to end.\n')
|
|
172
|
-
this.rl.prompt()
|
|
173
|
-
return true
|
|
174
|
-
}
|
|
175
|
-
return false
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private isPastedCode(line: string): boolean {
|
|
179
|
-
// Check if the line contains multiple lines (indicating a paste)
|
|
180
|
-
return line.includes('\n') || line.length > 100
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
private handleExitCommand(command: string): boolean {
|
|
184
|
-
if (command.toLowerCase() === 'exit') {
|
|
185
|
-
this.rl.close()
|
|
186
|
-
return true
|
|
187
|
-
}
|
|
188
|
-
return false
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private updateCommandHistory(command: string) {
|
|
192
|
-
if (this.commandHistory[0] !== command) {
|
|
193
|
-
this.commandHistory.unshift(command)
|
|
194
|
-
if (this.commandHistory.length > 1000) {
|
|
195
|
-
this.commandHistory.pop()
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
this.historyIndex = -1
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Handles various commands entered by the user.
|
|
203
|
-
* This function acts as a command router, delegating to specific handlers based on the input.
|
|
204
|
-
*
|
|
205
|
-
* @private
|
|
206
|
-
* @param {string} command - The command entered by the user.
|
|
207
|
-
* @returns {Promise<void>}
|
|
208
|
-
*
|
|
209
|
-
* @description
|
|
210
|
-
* Supported commands:
|
|
211
|
-
* - 'copy': Copies the last response to clipboard.
|
|
212
|
-
* - 'save': Saves changes to files.
|
|
213
|
-
* - 'commit': Commits changes to git with an AI-generated message.
|
|
214
|
-
* - 'ls': Lists files in the context (equivalent to 'ls *').
|
|
215
|
-
* - 'rm': Removes all files from the context (equivalent to 'rm *').
|
|
216
|
-
* - 'review': Starts a code review.
|
|
217
|
-
* - 'add <file-path>': Adds a file to the context.
|
|
218
|
-
* - 'rm <pattern>': Removes files matching the pattern from the context.
|
|
219
|
-
* - 'ls <pattern>': Lists files in the context matching the pattern.
|
|
220
|
-
* - 'git <command>': Executes a git command.
|
|
221
|
-
* - Any other input is processed as a user query to the AI.
|
|
222
|
-
*/
|
|
223
|
-
private async handleCommand(command: string): Promise<void> {
|
|
224
|
-
// Check if the command is a single character and map it to the first matching special command
|
|
225
|
-
if (command.length === 1) {
|
|
226
|
-
const matchingCommand = specialCommands.find((cmd) => cmd.startsWith(command))
|
|
227
|
-
if (matchingCommand) {
|
|
228
|
-
command = matchingCommand.split(' ')[0] // Use only the command part without arguments
|
|
229
|
-
} else {
|
|
230
|
-
console.log(`No matching command found for '${command}'. Processing as user input.`)
|
|
231
|
-
await this.processUserInput(command)
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
switch (command) {
|
|
237
|
-
case 'help':
|
|
238
|
-
this.displayHelp()
|
|
239
|
-
break
|
|
240
|
-
case 'copy':
|
|
241
|
-
await this.handleCopy()
|
|
242
|
-
break
|
|
243
|
-
case 'save':
|
|
244
|
-
await this.handleSave()
|
|
245
|
-
break
|
|
246
|
-
case 'commit':
|
|
247
|
-
await this.handleCommit()
|
|
248
|
-
break
|
|
249
|
-
case 'ls':
|
|
250
|
-
this.handleList('ls *')
|
|
251
|
-
break
|
|
252
|
-
case 'rm':
|
|
253
|
-
await this.handleRemove('rm *')
|
|
254
|
-
break
|
|
255
|
-
case 'review':
|
|
256
|
-
await this.handleReview()
|
|
257
|
-
break
|
|
258
|
-
default:
|
|
259
|
-
if (this.isAddCommand(command)) {
|
|
260
|
-
await this.handleAdd(command)
|
|
261
|
-
} else if (this.isFindCommand(command)) {
|
|
262
|
-
await this.handleFind(command)
|
|
263
|
-
} else if (this.isRemoveCommand(command)) {
|
|
264
|
-
await this.handleRemove(command)
|
|
265
|
-
} else if (this.isListCommand(command)) {
|
|
266
|
-
this.handleList(command)
|
|
267
|
-
} else if (this.isGitCommand(command)) {
|
|
268
|
-
this.executeGitCommand(command)
|
|
269
|
-
} else {
|
|
270
|
-
await this.processUserInput(command)
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
private isFindCommand(command: string): boolean {
|
|
276
|
-
const parts = command.trim().split(/\s+/)
|
|
277
|
-
return parts.length === 2 && parts[0] === 'find'
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private async handleFind(command: string) {
|
|
281
|
-
const fileName = command.slice(5).trim()
|
|
282
|
-
|
|
283
|
-
if (fileName) {
|
|
284
|
-
try {
|
|
285
|
-
const foundFiles = await this.findFiles(fileName)
|
|
286
|
-
if (foundFiles.length === 0) {
|
|
287
|
-
console.log(`No files found matching ${colors.bold(colors.red(fileName))}.`)
|
|
288
|
-
} else {
|
|
289
|
-
for (const filePath of foundFiles) {
|
|
290
|
-
this.contextFiles = await addFileOrDirectoryToContext(
|
|
291
|
-
filePath,
|
|
292
|
-
this.contextFiles,
|
|
293
|
-
this.options,
|
|
294
|
-
)
|
|
295
|
-
const content = this.contextFiles[filePath]
|
|
296
|
-
const tokenEstimate = this.estimateTokens(content)
|
|
297
|
-
console.log(
|
|
298
|
-
`\nAdded ${colors.bold(colors.green(filePath))} to this chat session's context (${colors.yellow(`~${tokenEstimate.toLocaleString()} tokens`)})`,
|
|
299
|
-
)
|
|
300
|
-
}
|
|
301
|
-
const totalTokens = this.calculateTotalTokens()
|
|
302
|
-
console.log(
|
|
303
|
-
colors.yellow(`\n📊 Total tokens in context now: ${totalTokens.toLocaleString()}\n`),
|
|
304
|
-
)
|
|
305
|
-
}
|
|
306
|
-
} catch (error) {
|
|
307
|
-
console.error(
|
|
308
|
-
`Failed to find and add files matching ${colors.bold(colors.red(fileName))}:`,
|
|
309
|
-
error,
|
|
310
|
-
)
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
console.log('No file name provided.')
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
this.rl.prompt()
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
private async findFiles(fileName: string): Promise<string[]> {
|
|
320
|
-
const { exec } = require('child_process')
|
|
321
|
-
return new Promise((resolve, reject) => {
|
|
322
|
-
exec(`find . -name "${fileName}"`, (error: Error | null, stdout: string) => {
|
|
323
|
-
if (error) {
|
|
324
|
-
return reject(error)
|
|
325
|
-
}
|
|
326
|
-
const files = stdout
|
|
327
|
-
.split('\n')
|
|
328
|
-
.filter((filePath) => filePath.trim() !== '')
|
|
329
|
-
.map((filePath) => (filePath.startsWith('./') ? filePath.slice(2) : filePath))
|
|
330
|
-
resolve(files)
|
|
331
|
-
})
|
|
332
|
-
})
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
private displayHelp(): void {
|
|
336
|
-
console.log('')
|
|
337
|
-
this.displayAvailableCommands()
|
|
338
|
-
console.log('\nFor any other input, I will process it as a request or question.\n')
|
|
339
|
-
this.rl.prompt()
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
private isAddCommand(command: string): boolean {
|
|
343
|
-
const parts = command.trim().split(/\s+/)
|
|
344
|
-
return parts.length === 2 && parts[0] === 'add'
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
private async handleAdd(command: string) {
|
|
348
|
-
const filePath = command.slice(4).trim()
|
|
349
|
-
|
|
350
|
-
if (filePath) {
|
|
351
|
-
try {
|
|
352
|
-
this.contextFiles = await addFileOrDirectoryToContext(
|
|
353
|
-
filePath,
|
|
354
|
-
this.contextFiles,
|
|
355
|
-
this.options,
|
|
356
|
-
)
|
|
357
|
-
console.log(`\nAdded ${colors.bold(colors.green(filePath))} to this chat session's context`)
|
|
358
|
-
this.refreshContext()
|
|
359
|
-
} catch (error) {
|
|
360
|
-
console.error(
|
|
361
|
-
`Failed to add ${colors.bold(colors.red(filePath))} to this chat session's context:`,
|
|
362
|
-
error,
|
|
363
|
-
)
|
|
364
|
-
}
|
|
365
|
-
} else {
|
|
366
|
-
console.log('No file path provided.')
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
this.rl.prompt()
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
private isRemoveCommand(command: string): boolean {
|
|
373
|
-
return command.startsWith('rm ')
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// Function to convert glob-like pattern to a regular expression
|
|
377
|
-
private globToRegExp(glob: string): RegExp {
|
|
378
|
-
const escapedGlob = glob.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&')
|
|
379
|
-
const regexString = escapedGlob.replace(/\*/g, '.*')
|
|
380
|
-
return new RegExp(`^${regexString}$`)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Function to filter paths using the pattern
|
|
384
|
-
private filterPaths(paths: string[], pattern: string): string[] {
|
|
385
|
-
const regex = this.globToRegExp(pattern)
|
|
386
|
-
return paths.filter((path) => regex.test(path))
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
private async handleRemove(command: string) {
|
|
390
|
-
const pattern = command.slice(3).trim()
|
|
391
|
-
|
|
392
|
-
if (pattern) {
|
|
393
|
-
const matchedFiles = this.filterPaths(Object.keys(this.contextFiles), pattern)
|
|
394
|
-
|
|
395
|
-
if (matchedFiles.length > 0) {
|
|
396
|
-
matchedFiles.forEach((filePath) => {
|
|
397
|
-
delete this.contextFiles[filePath]
|
|
398
|
-
console.log(
|
|
399
|
-
`Removed ${colors.bold(colors.green(filePath))} from this chat session's context files`,
|
|
400
|
-
)
|
|
401
|
-
})
|
|
402
|
-
} else {
|
|
403
|
-
console.log(
|
|
404
|
-
`No files matching pattern "${colors.bold(pattern)}" found in this chat session's context files, try running ${colors.yellow('ls')} to see the list of files.`,
|
|
405
|
-
)
|
|
406
|
-
}
|
|
407
|
-
} else {
|
|
408
|
-
console.log('No pattern provided.')
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
this.rl.prompt()
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
private isListCommand(command: string): boolean {
|
|
415
|
-
return command.startsWith('ls ')
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
private estimateTokens(text: string): number {
|
|
419
|
-
// A simple estimation: 1 token ≈ 4 characters
|
|
420
|
-
return Math.ceil(text.length / 4)
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
private handleList(command: string) {
|
|
424
|
-
const pattern = command.slice(3).trim()
|
|
425
|
-
const fileNames = Object.keys(this.contextFiles)
|
|
426
|
-
|
|
427
|
-
const matchedFiles = pattern ? this.filterPaths(fileNames, pattern) : fileNames
|
|
428
|
-
|
|
429
|
-
if (matchedFiles.length > 0) {
|
|
430
|
-
console.log(`\nFiles in the current chat session context:`)
|
|
431
|
-
let totalTokens = 0
|
|
432
|
-
matchedFiles.forEach((fileName) => {
|
|
433
|
-
const content = this.contextFiles[fileName]
|
|
434
|
-
const tokenEstimate = this.estimateTokens(content)
|
|
435
|
-
totalTokens += tokenEstimate
|
|
436
|
-
console.log(
|
|
437
|
-
` - ${colors.bold(colors.green(fileName))} (${colors.yellow(`~${tokenEstimate.toLocaleString()} tokens`)})`,
|
|
438
|
-
)
|
|
439
|
-
})
|
|
440
|
-
console.log(`\nTotal files: ${matchedFiles.length}`)
|
|
441
|
-
console.log(`Total estimated tokens: ${colors.yellow(totalTokens.toLocaleString())}\n`)
|
|
442
|
-
} else {
|
|
443
|
-
console.log('No files currently in context.')
|
|
444
|
-
}
|
|
445
|
-
this.rl.prompt()
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
private async handleCopy() {
|
|
449
|
-
const lastResponse = this.chatHistory.filter((msg) => msg.role === 'assistant').pop()
|
|
450
|
-
if (lastResponse) {
|
|
451
|
-
ncp.copy(lastResponse.content, () => {
|
|
452
|
-
console.info('Last response copied to clipboard.')
|
|
453
|
-
this.rl.prompt()
|
|
454
|
-
})
|
|
455
|
-
} else {
|
|
456
|
-
console.error('No response to copy.')
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
private async handleReview() {
|
|
461
|
-
this.options.stream = false
|
|
462
|
-
const reviewManager = new ReviewManager(this.options)
|
|
463
|
-
await reviewManager.generateReview()
|
|
464
|
-
this.options.stream = true
|
|
465
|
-
this.rl.prompt()
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
private async handleCommit() {
|
|
469
|
-
this.options.stream = false
|
|
470
|
-
const commitManager = new CommitManager(this.options)
|
|
471
|
-
await commitManager.generateCommit()
|
|
472
|
-
this.options.stream = true
|
|
473
|
-
this.rl.prompt()
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
private async handleSave() {
|
|
477
|
-
const lastResponse = this.chatHistory
|
|
478
|
-
.slice()
|
|
479
|
-
.reverse()
|
|
480
|
-
.find((msg) => msg.role === 'assistant')
|
|
481
|
-
|
|
482
|
-
if (lastResponse) {
|
|
483
|
-
const currentNewBlocks = extractCurrentNewBlocks(lastResponse.content)
|
|
484
|
-
if (Object.keys(currentNewBlocks).length > 0) {
|
|
485
|
-
await applyAndSaveCurrentNewBlocks(currentNewBlocks)
|
|
486
|
-
console.info(`\n${colors.bold('save')} has finished\n`)
|
|
487
|
-
this.rl.prompt()
|
|
488
|
-
} else {
|
|
489
|
-
console.info('No changes found to save in the last response.')
|
|
490
|
-
this.rl.prompt()
|
|
491
|
-
}
|
|
492
|
-
} else {
|
|
493
|
-
console.error('No response to save files from.')
|
|
494
|
-
this.rl.prompt()
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
private isGitCommand(command: string): boolean {
|
|
499
|
-
return command.split(' ').length <= 3 && command.startsWith('git ')
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
private executeGitCommand(command: string) {
|
|
503
|
-
try {
|
|
504
|
-
execSync(command, { stdio: 'inherit' })
|
|
505
|
-
} catch (error) {
|
|
506
|
-
console.error('Error running command:', error)
|
|
507
|
-
}
|
|
508
|
-
this.rl.prompt()
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Processes user input by sending it to the AI model and handling the response.
|
|
513
|
-
*
|
|
514
|
-
* This method manages the interaction with the AI model by:
|
|
515
|
-
* 1. Checking if a request is already being processed.
|
|
516
|
-
* 2. Initializing the chat history and generating a prompt.
|
|
517
|
-
* 3. Streaming the response from the AI model.
|
|
518
|
-
* 4. Handling the response stream and updating the chat history.
|
|
519
|
-
*
|
|
520
|
-
* @param {string} input - The user's input or request to be processed.
|
|
521
|
-
* @returns {Promise<void>} - A promise that resolves when the processing is complete.
|
|
522
|
-
*/
|
|
523
|
-
private async processUserInput(input: string): Promise<void> {
|
|
524
|
-
if (this.isProcessing) {
|
|
525
|
-
console.log('Please wait for the current request to complete.')
|
|
526
|
-
return
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
this.isProcessing = true
|
|
530
|
-
|
|
531
|
-
try {
|
|
532
|
-
await this.refreshContext()
|
|
533
|
-
this.addUserPrompt(this.generatePrompt(input))
|
|
534
|
-
|
|
535
|
-
if (!this.gpt.silent) {
|
|
536
|
-
const fullPrompt = this.chatHistory
|
|
537
|
-
.map((m) => {
|
|
538
|
-
const content = m.content
|
|
539
|
-
.split('\n')
|
|
540
|
-
.map((line) => {
|
|
541
|
-
if (line.startsWith('###')) {
|
|
542
|
-
return colors.red.bold(line)
|
|
543
|
-
} else if (line.startsWith('##')) {
|
|
544
|
-
return colors.yellow.bold(line)
|
|
545
|
-
}
|
|
546
|
-
return line
|
|
547
|
-
})
|
|
548
|
-
.join('\n')
|
|
549
|
-
return m.role === 'user'
|
|
550
|
-
? `${colors.yellow.bold('## User Prompt')}\n\n${content}`
|
|
551
|
-
: `${colors.green.bold("## 🍀 Cloving's Response 🍀")}\n\n${content}`
|
|
552
|
-
})
|
|
553
|
-
.join('\n\n')
|
|
554
|
-
|
|
555
|
-
// Review the prompt using the REPL
|
|
556
|
-
const tokenCount = Math.ceil(fullPrompt.length / 4).toLocaleString()
|
|
557
|
-
console.log(
|
|
558
|
-
`${colors.yellow.bold('INFORMATION')} The generated prompt is approximately ${tokenCount} tokens long. Would you like to review the prompt before sending it? ${colors.gray('(Y/n)')}`,
|
|
559
|
-
)
|
|
560
|
-
|
|
561
|
-
const reviewPrompt = await this.askQuestion('cloving> ')
|
|
562
|
-
|
|
563
|
-
if (reviewPrompt.startsWith('y') || reviewPrompt === '') {
|
|
564
|
-
this.reviewPrompt(fullPrompt)
|
|
565
|
-
console.log(`Do you want to proceed with this prompt? ${colors.gray('(Y/n)')}`)
|
|
566
|
-
|
|
567
|
-
const confirmPrompt = await this.askQuestion('cloving> ')
|
|
568
|
-
|
|
569
|
-
if (!confirmPrompt.startsWith('y') && confirmPrompt !== '') {
|
|
570
|
-
console.log('Operation cancelled by user.')
|
|
571
|
-
this.isProcessing = false
|
|
572
|
-
this.rl.prompt()
|
|
573
|
-
return
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const responseStream = await this.gpt.streamText({
|
|
579
|
-
prompt: this.prompt,
|
|
580
|
-
messages: this.chatHistory,
|
|
581
|
-
})
|
|
582
|
-
|
|
583
|
-
this.handleResponseStream(responseStream)
|
|
584
|
-
} catch (err) {
|
|
585
|
-
this.handleError(err as AxiosError)
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
private askQuestion(prompt: string): Promise<string> {
|
|
590
|
-
return new Promise<string>((resolve) => {
|
|
591
|
-
this.rl.question(colors.green.bold(prompt), (answer) => {
|
|
592
|
-
resolve(answer.trim().toLowerCase())
|
|
593
|
-
})
|
|
594
|
-
})
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
private reviewPrompt(fullPrompt: string) {
|
|
598
|
-
console.log(colors.gray.bold('\n---------------------- PROMPT START ----------------------\n'))
|
|
599
|
-
const promptParts = fullPrompt.split('\n```')
|
|
600
|
-
const highlightedPrompt = promptParts
|
|
601
|
-
.map((part, index) => (index % 2 === 1 ? highlight(part, { language: 'typescript' }) : part))
|
|
602
|
-
.join('\n```')
|
|
603
|
-
console.log(highlightedPrompt)
|
|
604
|
-
console.log(colors.gray.bold('\n---------------------- PROMPT END ----------------------\n'))
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
protected async finalizeResponse(): Promise<void> {
|
|
608
|
-
this.addAssistantResponse(this.responseString)
|
|
609
|
-
this.isProcessing = false
|
|
610
|
-
process.stdout.write('\b'.repeat(100))
|
|
611
|
-
|
|
612
|
-
if (this.responseString !== '') {
|
|
613
|
-
const currentNewBlocks = extractCurrentNewBlocks(this.responseString)
|
|
614
|
-
const [canApply, summary] = await checkBlocksApplicability(currentNewBlocks)
|
|
615
|
-
if (!canApply) {
|
|
616
|
-
if (this.retryCount < this.maxRetries) {
|
|
617
|
-
console.log(
|
|
618
|
-
`\n\n${summary}\n\n${colors.yellow.bold('WARNING')} Some of the provided code blocks could not be automatically applied. Retrying (Attempt ${this.retryCount + 1}/${this.maxRetries})...\n`,
|
|
619
|
-
)
|
|
620
|
-
|
|
621
|
-
this.retryCount++
|
|
622
|
-
this.processUserInput(`${CODEGEN_COULDNT_APPLY}\n\n${summary}`)
|
|
623
|
-
|
|
624
|
-
return
|
|
625
|
-
} else {
|
|
626
|
-
console.log(
|
|
627
|
-
`\n\n${colors.red.bold('ERROR')} Failed to generate a diff that could be cleanly applied after ${this.maxRetries} attempts. Please review the changes manually and try again.\n`,
|
|
628
|
-
)
|
|
629
|
-
this.retryCount = 0 // Reset the retry count for future attempts
|
|
630
|
-
}
|
|
631
|
-
} else {
|
|
632
|
-
this.retryCount = 0 // Reset the retry count on successful application
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
process.stdout.write(`
|
|
637
|
-
|
|
638
|
-
You can follow up with another request or:
|
|
639
|
-
- type ${colors.yellow(colors.bold('"save"'))} to save all the changes to files
|
|
640
|
-
- type ${colors.yellow(colors.bold('"commit"'))} to commit the changes to git with a AI - generated message
|
|
641
|
-
- type ${colors.yellow(colors.bold('"copy"'))} to copy the last response to clipboard
|
|
642
|
-
- type ${colors.yellow(colors.bold('"review"'))} to start a code review
|
|
643
|
-
- type ${colors.yellow(colors.bold('"add <file-path>"'))} to add a file to the chat context
|
|
644
|
-
- type ${colors.yellow(colors.bold('"rm <pattern>"'))} to remove files from the chat context
|
|
645
|
-
- type ${colors.yellow(colors.bold('"ls <pattern>"'))} to list files in the chat context
|
|
646
|
-
- type ${colors.yellow(colors.bold('"git <command>"'))} to run a git command
|
|
647
|
-
- type ${colors.yellow(colors.bold('"exit"'))} to quit this session
|
|
648
|
-
`)
|
|
649
|
-
this.rl.prompt()
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
private handleError(error: AxiosError) {
|
|
653
|
-
let errorMessage = error.message || 'An error occurred.'
|
|
654
|
-
const errorNumber = error.response?.status || 'unknown'
|
|
655
|
-
|
|
656
|
-
switch (errorNumber) {
|
|
657
|
-
case 400:
|
|
658
|
-
errorMessage = 'Invalid model or prompt size too large. Try specifying fewer files.'
|
|
659
|
-
break
|
|
660
|
-
case 403:
|
|
661
|
-
errorMessage = 'Inactive subscription or usage limit reached'
|
|
662
|
-
break
|
|
663
|
-
case 429:
|
|
664
|
-
errorMessage = 'Rate limit error'
|
|
665
|
-
break
|
|
666
|
-
case 500:
|
|
667
|
-
errorMessage = 'Internal server error'
|
|
668
|
-
break
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
const statusMessage = (error.response?.data as any)?.statusMessage
|
|
672
|
-
console.error(
|
|
673
|
-
colors.red(
|
|
674
|
-
`\nError (${errorNumber}) while submitting the prompt to the AI API\n\n${statusMessage}\n`,
|
|
675
|
-
),
|
|
676
|
-
)
|
|
677
|
-
this.isProcessing = false
|
|
678
|
-
this.rl.prompt()
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Generates a comprehensive prompt for the AI model.
|
|
683
|
-
*
|
|
684
|
-
* This function constructs a detailed prompt that includes:
|
|
685
|
-
* 1. The user's current request
|
|
686
|
-
* 2. Contents of all context files
|
|
687
|
-
* 3. Full chat history (excluding the current request)
|
|
688
|
-
* 4. The current request repeated at the end
|
|
689
|
-
*
|
|
690
|
-
* @private
|
|
691
|
-
* @param {string} prompt - The user's current request or input.
|
|
692
|
-
* @returns {string} A formatted string containing the complete prompt for the AI.
|
|
693
|
-
*
|
|
694
|
-
* @description
|
|
695
|
-
* The generated prompt follows this structure:
|
|
696
|
-
* 1. "### Request" section with the current prompt
|
|
697
|
-
* 2. Contents of all context files, each prefixed with its file name
|
|
698
|
-
* 3. "### Full Chat History Context" section with all previous messages
|
|
699
|
-
* 4. "### Current Request" section repeating the current prompt
|
|
700
|
-
*
|
|
701
|
-
* This structure provides the AI with comprehensive context for generating
|
|
702
|
-
* accurate and relevant responses.
|
|
703
|
-
*/
|
|
704
|
-
private generatePrompt(prompt: string): string {
|
|
705
|
-
return `### Request
|
|
706
|
-
|
|
707
|
-
${prompt}
|
|
708
|
-
|
|
709
|
-
### Note
|
|
710
|
-
|
|
711
|
-
Whenever possible, break up the changes into pieces and make sure every change is in its own *CURRENT/NEW* Blocks.
|
|
712
|
-
Do not allow empty CURRENT blocks in *CURRENT/NEW* Blocks and if you add content to the CURRENT block, you also have to add the same content to the NEW block.`
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
private handleClose() {
|
|
716
|
-
console.log('Goodbye!')
|
|
717
|
-
process.exit(0)
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* Displays the prompt in green and bold.
|
|
722
|
-
* This method should be used instead of directly calling this.rl.prompt().
|
|
723
|
-
* @private
|
|
724
|
-
*/
|
|
725
|
-
private displayPrompt() {
|
|
726
|
-
this.rl.setPrompt(colors.green.bold('cloving> '))
|
|
727
|
-
this.rl.prompt()
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
private handleKeypress(_: any, key: { name: string }) {
|
|
731
|
-
if (key && (key.name === 'up' || key.name === 'down')) {
|
|
732
|
-
if (key.name === 'up' && this.historyIndex < this.commandHistory.length - 1) {
|
|
733
|
-
this.historyIndex++
|
|
734
|
-
} else if (key.name === 'down' && this.historyIndex > -1) {
|
|
735
|
-
this.historyIndex--
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
if (this.historyIndex >= 0) {
|
|
739
|
-
this.rl.write(null, { ctrl: true, name: 'u' })
|
|
740
|
-
this.rl.write(this.commandHistory[this.historyIndex])
|
|
741
|
-
} else if (this.historyIndex === -1) {
|
|
742
|
-
this.rl.write(null, { ctrl: true, name: 'u' })
|
|
743
|
-
}
|
|
744
|
-
} else if (key && key.name === 'tab') {
|
|
745
|
-
const line = this.rl.line.trim()
|
|
746
|
-
const hits = specialCommands.filter((command) => command.startsWith(line))
|
|
747
|
-
if (hits.length > 0) {
|
|
748
|
-
this.rl.write(null, { ctrl: true, name: 'u' })
|
|
749
|
-
this.rl.write(hits[0])
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
export default ChatManager
|