codebuff 1.0.334 → 1.0.335
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/index.js +334 -0
- package/package.json +23 -72
- package/dist/__tests__/display.test.d.ts +0 -1
- package/dist/__tests__/display.test.js +0 -174
- package/dist/__tests__/display.test.js.map +0 -1
- package/dist/__tests__/rage-detectors.test.d.ts +0 -1
- package/dist/__tests__/rage-detectors.test.js +0 -127
- package/dist/__tests__/rage-detectors.test.js.map +0 -1
- package/dist/background-process-manager.d.ts +0 -50
- package/dist/background-process-manager.js +0 -364
- package/dist/background-process-manager.js.map +0 -1
- package/dist/browser-runner.d.ts +0 -35
- package/dist/browser-runner.js +0 -689
- package/dist/browser-runner.js.map +0 -1
- package/dist/chat-storage.d.ts +0 -2
- package/dist/chat-storage.js +0 -98
- package/dist/chat-storage.js.map +0 -1
- package/dist/checkpoints/checkpoint-manager.d.ts +0 -94
- package/dist/checkpoints/checkpoint-manager.js +0 -291
- package/dist/checkpoints/checkpoint-manager.js.map +0 -1
- package/dist/checkpoints/file-manager.d.ts +0 -72
- package/dist/checkpoints/file-manager.js +0 -498
- package/dist/checkpoints/file-manager.js.map +0 -1
- package/dist/cli-definitions.d.ts +0 -9
- package/dist/cli-definitions.js +0 -60
- package/dist/cli-definitions.js.map +0 -1
- package/dist/cli-handlers/api-key.d.ts +0 -25
- package/dist/cli-handlers/api-key.js +0 -66
- package/dist/cli-handlers/api-key.js.map +0 -1
- package/dist/cli-handlers/checkpoint.d.ts +0 -19
- package/dist/cli-handlers/checkpoint.js +0 -221
- package/dist/cli-handlers/checkpoint.js.map +0 -1
- package/dist/cli-handlers/diff.d.ts +0 -2
- package/dist/cli-handlers/diff.js +0 -31
- package/dist/cli-handlers/diff.js.map +0 -1
- package/dist/cli-handlers/easter-egg.d.ts +0 -1
- package/dist/cli-handlers/easter-egg.js +0 -126
- package/dist/cli-handlers/easter-egg.js.map +0 -1
- package/dist/cli-handlers/inititalization-flow.d.ts +0 -1
- package/dist/cli-handlers/inititalization-flow.js +0 -25
- package/dist/cli-handlers/inititalization-flow.js.map +0 -1
- package/dist/cli.d.ts +0 -67
- package/dist/cli.js +0 -812
- package/dist/cli.js.map +0 -1
- package/dist/client.d.ts +0 -91
- package/dist/client.js +0 -1112
- package/dist/client.js.map +0 -1
- package/dist/code-map/languages.d.ts +0 -12
- package/dist/code-map/languages.d.ts.map +0 -1
- package/dist/code-map/languages.js +0 -130
- package/dist/code-map/languages.js.map +0 -1
- package/dist/code-map/parse.d.ts +0 -22
- package/dist/code-map/parse.d.ts.map +0 -1
- package/dist/code-map/parse.js +0 -180
- package/dist/code-map/parse.js.map +0 -1
- package/dist/code-map/tree-sitter-queries/readme.md +0 -23
- package/dist/code-map/tree-sitter-queries/tree-sitter-c-tags.scm +0 -16
- package/dist/code-map/tree-sitter-queries/tree-sitter-c_sharp-tags.scm +0 -23
- package/dist/code-map/tree-sitter-queries/tree-sitter-cpp-tags.scm +0 -29
- package/dist/code-map/tree-sitter-queries/tree-sitter-go-tags.scm +0 -26
- package/dist/code-map/tree-sitter-queries/tree-sitter-java-tags.scm +0 -19
- package/dist/code-map/tree-sitter-queries/tree-sitter-javascript-tags.scm +0 -16
- package/dist/code-map/tree-sitter-queries/tree-sitter-php-tags.scm +0 -23
- package/dist/code-map/tree-sitter-queries/tree-sitter-python-tags.scm +0 -12
- package/dist/code-map/tree-sitter-queries/tree-sitter-ruby-tags.scm +0 -58
- package/dist/code-map/tree-sitter-queries/tree-sitter-rust-tags.scm +0 -26
- package/dist/code-map/tree-sitter-queries/tree-sitter-typescript-tags.scm +0 -22
- package/dist/code-map/tsconfig.tsbuildinfo +0 -1
- package/dist/common/actions.d.ts +0 -1809
- package/dist/common/actions.d.ts.map +0 -1
- package/dist/common/actions.js +0 -140
- package/dist/common/actions.js.map +0 -1
- package/dist/common/analytics.d.ts +0 -6
- package/dist/common/analytics.d.ts.map +0 -1
- package/dist/common/analytics.js +0 -60
- package/dist/common/analytics.js.map +0 -1
- package/dist/common/api-keys/constants.d.ts +0 -9
- package/dist/common/api-keys/constants.d.ts.map +0 -1
- package/dist/common/api-keys/constants.js +0 -26
- package/dist/common/api-keys/constants.js.map +0 -1
- package/dist/common/api-keys/crypto.d.ts +0 -25
- package/dist/common/api-keys/crypto.d.ts.map +0 -1
- package/dist/common/api-keys/crypto.js +0 -186
- package/dist/common/api-keys/crypto.js.map +0 -1
- package/dist/common/browser-actions.d.ts +0 -4416
- package/dist/common/browser-actions.d.ts.map +0 -1
- package/dist/common/browser-actions.js +0 -343
- package/dist/common/browser-actions.js.map +0 -1
- package/dist/common/constants/analytics-events.d.ts +0 -31
- package/dist/common/constants/analytics-events.d.ts.map +0 -1
- package/dist/common/constants/analytics-events.js +0 -39
- package/dist/common/constants/analytics-events.js.map +0 -1
- package/dist/common/constants/grant-priorities.d.ts +0 -3
- package/dist/common/constants/grant-priorities.d.ts.map +0 -1
- package/dist/common/constants/grant-priorities.js +0 -11
- package/dist/common/constants/grant-priorities.js.map +0 -1
- package/dist/common/constants/tools.d.ts +0 -19
- package/dist/common/constants/tools.d.ts.map +0 -1
- package/dist/common/constants/tools.js +0 -45
- package/dist/common/constants/tools.js.map +0 -1
- package/dist/common/constants.d.ts +0 -149
- package/dist/common/constants.d.ts.map +0 -1
- package/dist/common/constants.js +0 -234
- package/dist/common/constants.js.map +0 -1
- package/dist/common/db/drizzle.config.d.ts +0 -3
- package/dist/common/db/drizzle.config.d.ts.map +0 -1
- package/dist/common/db/drizzle.config.js +0 -17
- package/dist/common/db/drizzle.config.js.map +0 -1
- package/dist/common/db/index.d.ts +0 -7
- package/dist/common/db/index.d.ts.map +0 -1
- package/dist/common/db/index.js +0 -35
- package/dist/common/db/index.js.map +0 -1
- package/dist/common/db/schema.d.ts +0 -2449
- package/dist/common/db/schema.d.ts.map +0 -1
- package/dist/common/db/schema.js +0 -310
- package/dist/common/db/schema.js.map +0 -1
- package/dist/common/db/transaction.d.ts +0 -13
- package/dist/common/db/transaction.d.ts.map +0 -1
- package/dist/common/db/transaction.js +0 -36
- package/dist/common/db/transaction.js.map +0 -1
- package/dist/common/json-config/__tests__/__snapshots__/stringify-schema.test.js.snap +0 -144
- package/dist/common/json-config/__tests__/constants.test.d.ts +0 -2
- package/dist/common/json-config/__tests__/constants.test.d.ts.map +0 -1
- package/dist/common/json-config/__tests__/constants.test.js +0 -273
- package/dist/common/json-config/__tests__/constants.test.js.map +0 -1
- package/dist/common/json-config/__tests__/stringify-schema.test.d.ts +0 -2
- package/dist/common/json-config/__tests__/stringify-schema.test.d.ts.map +0 -1
- package/dist/common/json-config/__tests__/stringify-schema.test.js +0 -66
- package/dist/common/json-config/__tests__/stringify-schema.test.js.map +0 -1
- package/dist/common/json-config/constants.d.ts +0 -138
- package/dist/common/json-config/constants.d.ts.map +0 -1
- package/dist/common/json-config/constants.js +0 -78
- package/dist/common/json-config/constants.js.map +0 -1
- package/dist/common/json-config/default.d.ts +0 -3
- package/dist/common/json-config/default.d.ts.map +0 -1
- package/dist/common/json-config/default.js +0 -12
- package/dist/common/json-config/default.js.map +0 -1
- package/dist/common/json-config/stringify-schema.d.ts +0 -10
- package/dist/common/json-config/stringify-schema.d.ts.map +0 -1
- package/dist/common/json-config/stringify-schema.js +0 -131
- package/dist/common/json-config/stringify-schema.js.map +0 -1
- package/dist/common/project-file-tree.d.ts +0 -12
- package/dist/common/project-file-tree.d.ts.map +0 -1
- package/dist/common/project-file-tree.js +0 -212
- package/dist/common/project-file-tree.js.map +0 -1
- package/dist/common/types/agent-state.d.ts +0 -265
- package/dist/common/types/agent-state.d.ts.map +0 -1
- package/dist/common/types/agent-state.js +0 -48
- package/dist/common/types/agent-state.js.map +0 -1
- package/dist/common/types/grant.d.ts +0 -3
- package/dist/common/types/grant.d.ts.map +0 -1
- package/dist/common/types/grant.js +0 -11
- package/dist/common/types/grant.js.map +0 -1
- package/dist/common/types/message.d.ts +0 -320
- package/dist/common/types/message.d.ts.map +0 -1
- package/dist/common/types/message.js +0 -60
- package/dist/common/types/message.js.map +0 -1
- package/dist/common/types/organization.d.ts +0 -106
- package/dist/common/types/organization.d.ts.map +0 -1
- package/dist/common/types/organization.js +0 -3
- package/dist/common/types/organization.js.map +0 -1
- package/dist/common/types/referral.d.ts +0 -3
- package/dist/common/types/referral.d.ts.map +0 -1
- package/dist/common/types/referral.js +0 -5
- package/dist/common/types/referral.js.map +0 -1
- package/dist/common/types/tools.d.ts +0 -6
- package/dist/common/types/tools.d.ts.map +0 -1
- package/dist/common/types/tools.js +0 -3
- package/dist/common/types/tools.js.map +0 -1
- package/dist/common/types/usage.d.ts +0 -41
- package/dist/common/types/usage.d.ts.map +0 -1
- package/dist/common/types/usage.js +0 -16
- package/dist/common/types/usage.js.map +0 -1
- package/dist/common/util/__tests__/messages.test.d.ts +0 -2
- package/dist/common/util/__tests__/messages.test.d.ts.map +0 -1
- package/dist/common/util/__tests__/messages.test.js +0 -70
- package/dist/common/util/__tests__/messages.test.js.map +0 -1
- package/dist/common/util/__tests__/saxy.test.d.ts +0 -2
- package/dist/common/util/__tests__/saxy.test.d.ts.map +0 -1
- package/dist/common/util/__tests__/saxy.test.js +0 -906
- package/dist/common/util/__tests__/saxy.test.js.map +0 -1
- package/dist/common/util/__tests__/string.test.d.ts +0 -2
- package/dist/common/util/__tests__/string.test.d.ts.map +0 -1
- package/dist/common/util/__tests__/string.test.js +0 -82
- package/dist/common/util/__tests__/string.test.js.map +0 -1
- package/dist/common/util/array.d.ts +0 -7
- package/dist/common/util/array.d.ts.map +0 -1
- package/dist/common/util/array.js +0 -32
- package/dist/common/util/array.js.map +0 -1
- package/dist/common/util/changes.d.ts +0 -9
- package/dist/common/util/changes.d.ts.map +0 -1
- package/dist/common/util/changes.js +0 -87
- package/dist/common/util/changes.js.map +0 -1
- package/dist/common/util/credentials.d.ts +0 -26
- package/dist/common/util/credentials.d.ts.map +0 -1
- package/dist/common/util/credentials.js +0 -24
- package/dist/common/util/credentials.js.map +0 -1
- package/dist/common/util/currency.d.ts +0 -15
- package/dist/common/util/currency.d.ts.map +0 -1
- package/dist/common/util/currency.js +0 -23
- package/dist/common/util/currency.js.map +0 -1
- package/dist/common/util/dates.d.ts +0 -11
- package/dist/common/util/dates.d.ts.map +0 -1
- package/dist/common/util/dates.js +0 -22
- package/dist/common/util/dates.js.map +0 -1
- package/dist/common/util/file.d.ts +0 -171
- package/dist/common/util/file.d.ts.map +0 -1
- package/dist/common/util/file.js +0 -216
- package/dist/common/util/file.js.map +0 -1
- package/dist/common/util/git.d.ts +0 -7
- package/dist/common/util/git.d.ts.map +0 -1
- package/dist/common/util/git.js +0 -81
- package/dist/common/util/git.js.map +0 -1
- package/dist/common/util/logger.d.ts +0 -9
- package/dist/common/util/logger.d.ts.map +0 -1
- package/dist/common/util/logger.js +0 -52
- package/dist/common/util/logger.js.map +0 -1
- package/dist/common/util/lru-cache.d.ts +0 -31
- package/dist/common/util/lru-cache.d.ts.map +0 -1
- package/dist/common/util/lru-cache.js +0 -68
- package/dist/common/util/lru-cache.js.map +0 -1
- package/dist/common/util/messages.d.ts +0 -12
- package/dist/common/util/messages.d.ts.map +0 -1
- package/dist/common/util/messages.js +0 -81
- package/dist/common/util/messages.js.map +0 -1
- package/dist/common/util/min-heap.d.ts +0 -16
- package/dist/common/util/min-heap.d.ts.map +0 -1
- package/dist/common/util/min-heap.js +0 -73
- package/dist/common/util/min-heap.js.map +0 -1
- package/dist/common/util/object.d.ts +0 -19
- package/dist/common/util/object.d.ts.map +0 -1
- package/dist/common/util/object.js +0 -91
- package/dist/common/util/object.js.map +0 -1
- package/dist/common/util/patch.d.ts +0 -2
- package/dist/common/util/patch.d.ts.map +0 -1
- package/dist/common/util/patch.js +0 -215
- package/dist/common/util/patch.js.map +0 -1
- package/dist/common/util/promise.d.ts +0 -17
- package/dist/common/util/promise.d.ts.map +0 -1
- package/dist/common/util/promise.js +0 -51
- package/dist/common/util/promise.js.map +0 -1
- package/dist/common/util/random.d.ts +0 -2
- package/dist/common/util/random.d.ts.map +0 -1
- package/dist/common/util/random.js +0 -17
- package/dist/common/util/random.js.map +0 -1
- package/dist/common/util/referral.d.ts +0 -2
- package/dist/common/util/referral.d.ts.map +0 -1
- package/dist/common/util/referral.js +0 -6
- package/dist/common/util/referral.js.map +0 -1
- package/dist/common/util/saxy.d.ts +0 -179
- package/dist/common/util/saxy.d.ts.map +0 -1
- package/dist/common/util/saxy.js +0 -548
- package/dist/common/util/saxy.js.map +0 -1
- package/dist/common/util/string.d.ts +0 -80
- package/dist/common/util/string.d.ts.map +0 -1
- package/dist/common/util/string.js +0 -275
- package/dist/common/util/string.js.map +0 -1
- package/dist/common/util/stripe.d.ts +0 -4
- package/dist/common/util/stripe.d.ts.map +0 -1
- package/dist/common/util/stripe.js +0 -22
- package/dist/common/util/stripe.js.map +0 -1
- package/dist/common/util/sync-failure.d.ts +0 -2
- package/dist/common/util/sync-failure.d.ts.map +0 -1
- package/dist/common/util/sync-failure.js +0 -57
- package/dist/common/util/sync-failure.js.map +0 -1
- package/dist/common/websockets/websocket-client.d.ts +0 -43
- package/dist/common/websockets/websocket-client.d.ts.map +0 -1
- package/dist/common/websockets/websocket-client.js +0 -216
- package/dist/common/websockets/websocket-client.js.map +0 -1
- package/dist/common/websockets/websocket-schema.d.ts +0 -3679
- package/dist/common/websockets/websocket-schema.d.ts.map +0 -1
- package/dist/common/websockets/websocket-schema.js +0 -55
- package/dist/common/websockets/websocket-schema.js.map +0 -1
- package/dist/config.d.ts +0 -4
- package/dist/config.js +0 -12
- package/dist/config.js.map +0 -1
- package/dist/create-template-project.d.ts +0 -1
- package/dist/create-template-project.js +0 -131
- package/dist/create-template-project.js.map +0 -1
- package/dist/credentials.d.ts +0 -4
- package/dist/credentials.js +0 -44
- package/dist/credentials.js.map +0 -1
- package/dist/dev-process-manager.d.ts +0 -10
- package/dist/dev-process-manager.js +0 -56
- package/dist/dev-process-manager.js.map +0 -1
- package/dist/display.d.ts +0 -9
- package/dist/display.js +0 -137
- package/dist/display.js.map +0 -1
- package/dist/fingerprint.d.ts +0 -1
- package/dist/fingerprint.js +0 -48
- package/dist/fingerprint.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -128
- package/dist/index.js.map +0 -1
- package/dist/json-config/hooks.d.ts +0 -9
- package/dist/json-config/hooks.js +0 -60
- package/dist/json-config/hooks.js.map +0 -1
- package/dist/json-config/parser.d.ts +0 -7
- package/dist/json-config/parser.js +0 -54
- package/dist/json-config/parser.js.map +0 -1
- package/dist/menu.d.ts +0 -14
- package/dist/menu.js +0 -344
- package/dist/menu.js.map +0 -1
- package/dist/project-files.d.ts +0 -104
- package/dist/project-files.js +0 -621
- package/dist/project-files.js.map +0 -1
- package/dist/rage-detectors.d.ts +0 -15
- package/dist/rage-detectors.js +0 -55
- package/dist/rage-detectors.js.map +0 -1
- package/dist/startup-process-handler.d.ts +0 -1
- package/dist/startup-process-handler.js +0 -25
- package/dist/startup-process-handler.js.map +0 -1
- package/dist/terminal/background.d.ts +0 -12
- package/dist/terminal/background.js +0 -148
- package/dist/terminal/background.js.map +0 -1
- package/dist/terminal/base.d.ts +0 -41
- package/dist/terminal/base.js +0 -553
- package/dist/terminal/base.js.map +0 -1
- package/dist/tool-handlers.d.ts +0 -31
- package/dist/tool-handlers.js +0 -275
- package/dist/tool-handlers.js.map +0 -1
- package/dist/types.d.ts +0 -15
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/update-codebuff.d.ts +0 -1
- package/dist/update-codebuff.js +0 -169
- package/dist/update-codebuff.js.map +0 -1
- package/dist/utils/__tests__/background-process-manager.test.d.ts +0 -1
- package/dist/utils/__tests__/background-process-manager.test.js +0 -326
- package/dist/utils/__tests__/background-process-manager.test.js.map +0 -1
- package/dist/utils/__tests__/rage-detector.test.d.ts +0 -1
- package/dist/utils/__tests__/rage-detector.test.js +0 -450
- package/dist/utils/__tests__/rage-detector.test.js.map +0 -1
- package/dist/utils/__tests__/response-example-4-files.txt +0 -621
- package/dist/utils/__tests__/tool-renderers.test.d.ts +0 -1
- package/dist/utils/__tests__/tool-renderers.test.js +0 -83
- package/dist/utils/__tests__/tool-renderers.test.js.map +0 -1
- package/dist/utils/__tests__/xml-stream-parser.test.d.ts +0 -1
- package/dist/utils/__tests__/xml-stream-parser.test.js +0 -255
- package/dist/utils/__tests__/xml-stream-parser.test.js.map +0 -1
- package/dist/utils/analytics.d.ts +0 -7
- package/dist/utils/analytics.js +0 -132
- package/dist/utils/analytics.js.map +0 -1
- package/dist/utils/detect-shell.d.ts +0 -1
- package/dist/utils/detect-shell.js +0 -65
- package/dist/utils/detect-shell.js.map +0 -1
- package/dist/utils/git.d.ts +0 -13
- package/dist/utils/git.js +0 -143
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -21
- package/dist/utils/logger.js +0 -109
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/rage-detector.d.ts +0 -32
- package/dist/utils/rage-detector.js +0 -143
- package/dist/utils/rage-detector.js.map +0 -1
- package/dist/utils/spinner.d.ts +0 -13
- package/dist/utils/spinner.js +0 -94
- package/dist/utils/spinner.js.map +0 -1
- package/dist/utils/system-info.d.ts +0 -8
- package/dist/utils/system-info.js +0 -22
- package/dist/utils/system-info.js.map +0 -1
- package/dist/utils/tool-renderers.d.ts +0 -16
- package/dist/utils/tool-renderers.js +0 -216
- package/dist/utils/tool-renderers.js.map +0 -1
- package/dist/utils/with-hang-detection.d.ts +0 -1
- package/dist/utils/with-hang-detection.js +0 -18
- package/dist/utils/with-hang-detection.js.map +0 -1
- package/dist/utils/xml-stream-parser.d.ts +0 -9
- package/dist/utils/xml-stream-parser.js +0 -143
- package/dist/utils/xml-stream-parser.js.map +0 -1
- package/dist/web-scraper.d.ts +0 -3
- package/dist/web-scraper.js +0 -59
- package/dist/web-scraper.js.map +0 -1
- package/dist/workers/checkpoint-worker.d.ts +0 -1
- package/dist/workers/checkpoint-worker.js +0 -51
- package/dist/workers/checkpoint-worker.js.map +0 -1
- package/dist/workers/project-context.d.ts +0 -1
- package/dist/workers/project-context.js +0 -27
- package/dist/workers/project-context.js.map +0 -1
package/dist/cli.js
DELETED
|
@@ -1,812 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.CLI = void 0;
|
|
27
|
-
const fs_1 = __importStar(require("fs"));
|
|
28
|
-
const os = __importStar(require("os"));
|
|
29
|
-
const os_1 = require("os");
|
|
30
|
-
const path_1 = __importStar(require("path"));
|
|
31
|
-
const readline = __importStar(require("readline"));
|
|
32
|
-
const analytics_events_1 = require("./common/constants/analytics-events");
|
|
33
|
-
const file_1 = require("./common/util/file");
|
|
34
|
-
const string_1 = require("./common/util/string");
|
|
35
|
-
const picocolors_1 = require("picocolors");
|
|
36
|
-
const background_process_manager_1 = require("./background-process-manager");
|
|
37
|
-
const checkpoint_manager_1 = require("./checkpoints/checkpoint-manager");
|
|
38
|
-
const api_key_1 = require("./cli-handlers/api-key");
|
|
39
|
-
const checkpoint_1 = require("./cli-handlers/checkpoint");
|
|
40
|
-
const diff_1 = require("./cli-handlers/diff");
|
|
41
|
-
const easter_egg_1 = require("./cli-handlers/easter-egg");
|
|
42
|
-
const inititalization_flow_1 = require("./cli-handlers/inititalization-flow");
|
|
43
|
-
const client_1 = require("./client");
|
|
44
|
-
const config_1 = require("./config");
|
|
45
|
-
const credentials_1 = require("./credentials");
|
|
46
|
-
const display_1 = require("./display");
|
|
47
|
-
const parser_1 = require("./json-config/parser");
|
|
48
|
-
const menu_1 = require("./menu");
|
|
49
|
-
const project_files_1 = require("./project-files");
|
|
50
|
-
const rage_detectors_1 = require("./rage-detectors");
|
|
51
|
-
const startup_process_handler_1 = require("./startup-process-handler");
|
|
52
|
-
const base_1 = require("./terminal/base");
|
|
53
|
-
const analytics_1 = require("./utils/analytics");
|
|
54
|
-
const logger_1 = require("./utils/logger");
|
|
55
|
-
const spinner_1 = require("./utils/spinner");
|
|
56
|
-
const with_hang_detection_1 = require("./utils/with-hang-detection");
|
|
57
|
-
const PROMPT_HISTORY_PATH = path_1.default.join(credentials_1.CONFIG_DIR, 'prompt_history.json');
|
|
58
|
-
class CLI {
|
|
59
|
-
static instance = null;
|
|
60
|
-
readyPromise;
|
|
61
|
-
git;
|
|
62
|
-
costMode;
|
|
63
|
-
isReceivingResponse = false;
|
|
64
|
-
stopResponse = null;
|
|
65
|
-
lastSigintTime = 0;
|
|
66
|
-
lastInputTime = 0;
|
|
67
|
-
consecutiveFastInputs = 0;
|
|
68
|
-
pastedContent = '';
|
|
69
|
-
isPasting = false;
|
|
70
|
-
shouldReconnectWhenIdle = false;
|
|
71
|
-
rl;
|
|
72
|
-
constructor(readyPromise, { git, costMode, model }) {
|
|
73
|
-
this.git = git;
|
|
74
|
-
this.costMode = costMode;
|
|
75
|
-
this.setupSignalHandlers();
|
|
76
|
-
this.initReadlineInterface();
|
|
77
|
-
client_1.Client.createInstance({
|
|
78
|
-
websocketUrl: config_1.websocketUrl,
|
|
79
|
-
onWebSocketError: this.onWebSocketError.bind(this),
|
|
80
|
-
onWebSocketReconnect: this.onWebSocketReconnect.bind(this),
|
|
81
|
-
freshPrompt: this.freshPrompt.bind(this),
|
|
82
|
-
reconnectWhenNextIdle: this.reconnectWhenNextIdle.bind(this),
|
|
83
|
-
costMode: this.costMode,
|
|
84
|
-
git: this.git,
|
|
85
|
-
model,
|
|
86
|
-
});
|
|
87
|
-
this.readyPromise = Promise.all([
|
|
88
|
-
readyPromise.then((results) => {
|
|
89
|
-
const [fileContext, ,] = results;
|
|
90
|
-
client_1.Client.getInstance().initAgentState(fileContext);
|
|
91
|
-
return client_1.Client.getInstance().warmContextCache();
|
|
92
|
-
}),
|
|
93
|
-
client_1.Client.getInstance().connect(),
|
|
94
|
-
]);
|
|
95
|
-
this.setPrompt();
|
|
96
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
97
|
-
rage_detectors_1.rageDetectors.exitAfterErrorDetector.start();
|
|
98
|
-
console.error('\nUnhandled Rejection at:', promise, 'reason:', reason);
|
|
99
|
-
logger_1.logger.error({
|
|
100
|
-
errorMessage: reason instanceof Error ? reason.message : String(reason),
|
|
101
|
-
errorStack: reason instanceof Error ? reason.stack : undefined,
|
|
102
|
-
}, 'Unhandled Rejection');
|
|
103
|
-
this.freshPrompt();
|
|
104
|
-
});
|
|
105
|
-
process.on('uncaughtException', (err, origin) => {
|
|
106
|
-
rage_detectors_1.rageDetectors.exitAfterErrorDetector.start();
|
|
107
|
-
console.error(`\nCaught exception: ${err}\n` + `Exception origin: ${origin}`);
|
|
108
|
-
console.error(err.stack);
|
|
109
|
-
logger_1.logger.error({
|
|
110
|
-
errorMessage: err.message,
|
|
111
|
-
errorStack: err.stack,
|
|
112
|
-
origin,
|
|
113
|
-
}, 'Uncaught Exception');
|
|
114
|
-
this.freshPrompt();
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
static initialize(readyPromise, options) {
|
|
118
|
-
if (CLI.instance) {
|
|
119
|
-
throw new Error('CLI is already initialized');
|
|
120
|
-
}
|
|
121
|
-
CLI.instance = new CLI(readyPromise, options);
|
|
122
|
-
}
|
|
123
|
-
static getInstance() {
|
|
124
|
-
if (!CLI.instance) {
|
|
125
|
-
throw new Error('CLI must be initialized before getting an instance');
|
|
126
|
-
}
|
|
127
|
-
return CLI.instance;
|
|
128
|
-
}
|
|
129
|
-
setupSignalHandlers() {
|
|
130
|
-
process.on('exit', () => {
|
|
131
|
-
spinner_1.Spinner.get().restoreCursor();
|
|
132
|
-
// Kill the persistent PTY process first
|
|
133
|
-
if (base_1.persistentProcess?.type === 'pty') {
|
|
134
|
-
base_1.persistentProcess.pty.kill();
|
|
135
|
-
}
|
|
136
|
-
(0, background_process_manager_1.sendKillSignalToAllBackgroundProcesses)();
|
|
137
|
-
const isHomeDir = (0, project_files_1.getProjectRoot)() === os.homedir();
|
|
138
|
-
if (!isHomeDir) {
|
|
139
|
-
console.log((0, picocolors_1.green)('Codebuff out!'));
|
|
140
|
-
}
|
|
141
|
-
if (process.env.NEXT_PUBLIC_CB_ENVIRONMENT === 'dev') {
|
|
142
|
-
logger_1.logger.info('[dev] active handles on close', process._getActiveHandles());
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
for (const signal of ['SIGTERM', 'SIGHUP']) {
|
|
146
|
-
process.on(signal, async () => {
|
|
147
|
-
process.removeAllListeners('unhandledRejection');
|
|
148
|
-
process.removeAllListeners('uncaughtException');
|
|
149
|
-
spinner_1.Spinner.get().restoreCursor();
|
|
150
|
-
await (0, background_process_manager_1.killAllBackgroundProcesses)();
|
|
151
|
-
client_1.Client.getInstance().close();
|
|
152
|
-
await (0, analytics_1.flushAnalytics)();
|
|
153
|
-
process.exit(0);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
process.on('SIGTSTP', async () => await this.handleExit());
|
|
157
|
-
// Doesn't catch SIGKILL (e.g. `kill -9`)
|
|
158
|
-
}
|
|
159
|
-
_loadHistory() {
|
|
160
|
-
try {
|
|
161
|
-
if (fs_1.default.existsSync(PROMPT_HISTORY_PATH)) {
|
|
162
|
-
const content = fs_1.default.readFileSync(PROMPT_HISTORY_PATH, 'utf8');
|
|
163
|
-
const history = JSON.parse(content);
|
|
164
|
-
// Filter out empty lines and reverse for readline
|
|
165
|
-
return history.filter((line) => line.trim()).reverse();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.error('Error loading prompt history:', error);
|
|
170
|
-
logger_1.logger.error({
|
|
171
|
-
errorMessage: error instanceof Error ? error.message : String(error),
|
|
172
|
-
errorStack: error instanceof Error ? error.stack : undefined,
|
|
173
|
-
}, 'Error loading prompt history');
|
|
174
|
-
// If file doesn't exist or is invalid JSON, create empty history file
|
|
175
|
-
fs_1.default.writeFileSync(PROMPT_HISTORY_PATH, '[]');
|
|
176
|
-
}
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
_appendToHistory(line) {
|
|
180
|
-
try {
|
|
181
|
-
let history = [];
|
|
182
|
-
if (fs_1.default.existsSync(PROMPT_HISTORY_PATH)) {
|
|
183
|
-
const content = fs_1.default.readFileSync(PROMPT_HISTORY_PATH, 'utf8');
|
|
184
|
-
history = JSON.parse(content);
|
|
185
|
-
}
|
|
186
|
-
const trimmedLine = line.trim();
|
|
187
|
-
if (trimmedLine) {
|
|
188
|
-
// Remove all previous occurrences of the line
|
|
189
|
-
history = history.filter((h) => h !== trimmedLine);
|
|
190
|
-
// Add the new line to the end
|
|
191
|
-
history.push(trimmedLine);
|
|
192
|
-
fs_1.default.writeFileSync(PROMPT_HISTORY_PATH, JSON.stringify(history, null, 2));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
console.error('Error appending to prompt history:', error);
|
|
197
|
-
logger_1.logger.error({
|
|
198
|
-
errorMessage: error instanceof Error ? error.message : String(error),
|
|
199
|
-
errorStack: error instanceof Error ? error.stack : undefined,
|
|
200
|
-
}, 'Error appending to prompt history');
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
initReadlineInterface() {
|
|
204
|
-
this.rl = readline.createInterface({
|
|
205
|
-
input: process.stdin,
|
|
206
|
-
output: process.stdout,
|
|
207
|
-
historySize: 1000,
|
|
208
|
-
terminal: true,
|
|
209
|
-
completer: this.inputCompleter.bind(this),
|
|
210
|
-
});
|
|
211
|
-
// Load and populate history
|
|
212
|
-
const history = this._loadHistory();
|
|
213
|
-
this.rl.history.push(...history);
|
|
214
|
-
this.rl.on('line', (line) => this.handleLine(line));
|
|
215
|
-
this.rl.on('SIGINT', async () => await this.handleSigint());
|
|
216
|
-
this.rl.on('close', async () => await this.handleExit());
|
|
217
|
-
process.stdin.on('keypress', (str, key) => this.handleKeyPress(str, key));
|
|
218
|
-
}
|
|
219
|
-
inputCompleter(line) {
|
|
220
|
-
const lastWord = line.split(' ').pop() || '';
|
|
221
|
-
if (line.startsWith('/')) {
|
|
222
|
-
const slashCommands = (0, menu_1.getSlashCommands)();
|
|
223
|
-
const currentInput = line.substring(1); // Text after '/'
|
|
224
|
-
const matches = slashCommands
|
|
225
|
-
.map((cmd) => cmd.baseCommand) // Get base command strings
|
|
226
|
-
.filter((cmdName) => cmdName && cmdName.startsWith(currentInput))
|
|
227
|
-
.map((cmdName) => `/${cmdName}`); // Add back the slash for display
|
|
228
|
-
if (matches.length > 0) {
|
|
229
|
-
return [matches, line]; // Return all matches and the full line typed so far
|
|
230
|
-
}
|
|
231
|
-
return [[], line]; // No slash command matches
|
|
232
|
-
}
|
|
233
|
-
// Handle @ prefix for token and file completion
|
|
234
|
-
if (lastWord.startsWith('@')) {
|
|
235
|
-
const client = client_1.Client.getInstance();
|
|
236
|
-
if (!client.fileContext?.fileTree)
|
|
237
|
-
return [[], line];
|
|
238
|
-
const searchTerm = lastWord.substring(1); // Remove @ prefix
|
|
239
|
-
const searchTermLower = searchTerm.toLowerCase();
|
|
240
|
-
// Get token names from fileTokenScores
|
|
241
|
-
const tokenNames = Object.values(client.fileContext.fileTokenScores).flatMap((o) => Object.keys(o));
|
|
242
|
-
// Get all file paths
|
|
243
|
-
const paths = this.getAllFilePaths(client.fileContext.fileTree);
|
|
244
|
-
// Combine tokens and paths for matching
|
|
245
|
-
const allCandidates = [...tokenNames, ...paths];
|
|
246
|
-
const matchingItems = allCandidates.filter((item) => item.toLowerCase().startsWith(searchTermLower) ||
|
|
247
|
-
item.toLowerCase().includes('/' + searchTermLower));
|
|
248
|
-
// Limit the number of results to keep completion manageable
|
|
249
|
-
const MAX_COMPLETION_RESULTS = 20;
|
|
250
|
-
const limitedMatches = matchingItems.slice(0, MAX_COMPLETION_RESULTS);
|
|
251
|
-
if (limitedMatches.length > 1) {
|
|
252
|
-
// Find common prefix among matches
|
|
253
|
-
const suffixes = limitedMatches.map((item) => {
|
|
254
|
-
const index = item.toLowerCase().indexOf(searchTermLower);
|
|
255
|
-
return item.slice(index + searchTerm.length);
|
|
256
|
-
});
|
|
257
|
-
let commonPrefix = '';
|
|
258
|
-
const firstSuffix = suffixes[0];
|
|
259
|
-
for (let i = 0; i < firstSuffix.length; i++) {
|
|
260
|
-
const char = firstSuffix[i];
|
|
261
|
-
if (suffixes.every((suffix) => suffix[i] === char)) {
|
|
262
|
-
commonPrefix += char;
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (commonPrefix) {
|
|
269
|
-
// Return the completion with @ prefix preserved
|
|
270
|
-
return [['@' + searchTerm + commonPrefix], lastWord];
|
|
271
|
-
}
|
|
272
|
-
// Multiple matches but no common prefix - show matches WITHOUT @ prefix but keep @ in input
|
|
273
|
-
return [limitedMatches, lastWord];
|
|
274
|
-
}
|
|
275
|
-
// Single match or no matches - remove @ prefix from completion
|
|
276
|
-
return [limitedMatches, lastWord];
|
|
277
|
-
}
|
|
278
|
-
// Original file path completion logic (unchanged)
|
|
279
|
-
const input = lastWord.startsWith('~')
|
|
280
|
-
? (0, os_1.homedir)() + lastWord.slice(1)
|
|
281
|
-
: lastWord;
|
|
282
|
-
const directorySuffix = process.platform === 'win32' ? '\\' : '/';
|
|
283
|
-
const dir = input.endsWith(directorySuffix)
|
|
284
|
-
? input.slice(0, input.length - 1)
|
|
285
|
-
: (0, path_1.dirname)(input);
|
|
286
|
-
const partial = input.endsWith(directorySuffix) ? '' : (0, path_1.basename)(input);
|
|
287
|
-
let baseDir = (0, path_1.isAbsolute)(dir) ? dir : path_1.default.join((0, project_files_1.getWorkingDirectory)(), dir);
|
|
288
|
-
try {
|
|
289
|
-
const files = (0, fs_1.readdirSync)(baseDir);
|
|
290
|
-
const fsMatches = files
|
|
291
|
-
.filter((file) => file.startsWith(partial))
|
|
292
|
-
.map((file) => file + ((0, file_1.isDir)(path_1.default.join(baseDir, file)) ? directorySuffix : ''));
|
|
293
|
-
return [fsMatches, partial];
|
|
294
|
-
}
|
|
295
|
-
catch {
|
|
296
|
-
return [[], line];
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
getAllFilePaths(nodes, basePath = '') {
|
|
300
|
-
return nodes.flatMap((node) => {
|
|
301
|
-
if (node.type === 'file') {
|
|
302
|
-
return [path_1.default.join(basePath, node.name)];
|
|
303
|
-
}
|
|
304
|
-
return this.getAllFilePaths(node.children || [], path_1.default.join(basePath, node.name));
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
getModeIndicator() {
|
|
308
|
-
const costModeIndicator = this.costMode !== 'normal' ? ` (${this.costMode})` : '';
|
|
309
|
-
return costModeIndicator;
|
|
310
|
-
}
|
|
311
|
-
setPrompt() {
|
|
312
|
-
const projectRoot = (0, project_files_1.getProjectRoot)();
|
|
313
|
-
const cwd = (0, project_files_1.getWorkingDirectory)();
|
|
314
|
-
const projectDirName = (0, path_1.parse)(projectRoot).base;
|
|
315
|
-
const ps1Dir = projectDirName +
|
|
316
|
-
(cwd === projectRoot
|
|
317
|
-
? ''
|
|
318
|
-
: (os.platform() === 'win32' ? '\\' : '/') +
|
|
319
|
-
path_1.default.relative(projectRoot, cwd));
|
|
320
|
-
const modeIndicator = this.getModeIndicator();
|
|
321
|
-
this.rl.setPrompt((0, picocolors_1.green)(`${ps1Dir}${modeIndicator} > `));
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Prompts the user with a clean prompt state
|
|
325
|
-
*/
|
|
326
|
-
freshPrompt(userInput = '') {
|
|
327
|
-
spinner_1.Spinner.get().stop();
|
|
328
|
-
this.isReceivingResponse = false;
|
|
329
|
-
if (this.shouldReconnectWhenIdle) {
|
|
330
|
-
client_1.Client.getInstance().reconnect();
|
|
331
|
-
this.shouldReconnectWhenIdle = false;
|
|
332
|
-
}
|
|
333
|
-
readline.cursorTo(process.stdout, 0);
|
|
334
|
-
const rlAny = this.rl;
|
|
335
|
-
// Check for pending auto-topup message before showing prompt
|
|
336
|
-
if (client_1.Client.getInstance().pendingTopUpMessageAmount > 0) {
|
|
337
|
-
console.log('\n\n' +
|
|
338
|
-
(0, picocolors_1.green)(`Auto top-up successful! ${client_1.Client.getInstance().pendingTopUpMessageAmount.toLocaleString()} credits added.`) +
|
|
339
|
-
'\n');
|
|
340
|
-
client_1.Client.getInstance().pendingTopUpMessageAmount = 0;
|
|
341
|
-
}
|
|
342
|
-
// clear line first
|
|
343
|
-
rlAny.line = '';
|
|
344
|
-
this.pastedContent = '';
|
|
345
|
-
this.setPrompt();
|
|
346
|
-
// then prompt
|
|
347
|
-
this.rl.prompt();
|
|
348
|
-
(0, display_1.disableSquashNewlines)();
|
|
349
|
-
if (!userInput) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
// then rewrite new prompt
|
|
353
|
-
this.rl.write(' '.repeat(userInput.length)); // hacky way to move cursor
|
|
354
|
-
rlAny.line = userInput;
|
|
355
|
-
rlAny._refreshLine();
|
|
356
|
-
}
|
|
357
|
-
async printInitialPrompt({ initialInput, runInitFlow, }) {
|
|
358
|
-
const client = client_1.Client.getInstance();
|
|
359
|
-
if (client.user) {
|
|
360
|
-
(0, menu_1.displayGreeting)(this.costMode, client.user.name);
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
console.log(`Welcome to Codebuff! Give us a sec to get your account set up...`);
|
|
364
|
-
await client_1.Client.getInstance().login();
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
this.freshPrompt();
|
|
368
|
-
if (runInitFlow) {
|
|
369
|
-
process.stdout.write('init\n');
|
|
370
|
-
await this.handleUserInput('init');
|
|
371
|
-
}
|
|
372
|
-
if (initialInput) {
|
|
373
|
-
process.stdout.write(initialInput + '\n');
|
|
374
|
-
await this.handleUserInput(initialInput);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
async printDiff() {
|
|
378
|
-
(0, diff_1.handleDiff)(client_1.Client.getInstance().lastChanges);
|
|
379
|
-
this.freshPrompt();
|
|
380
|
-
}
|
|
381
|
-
async handleLine(line) {
|
|
382
|
-
this.detectPasting();
|
|
383
|
-
if (this.isPasting) {
|
|
384
|
-
this.pastedContent += line + '\n';
|
|
385
|
-
}
|
|
386
|
-
else if (!this.isReceivingResponse) {
|
|
387
|
-
const input = (this.pastedContent + line).trim();
|
|
388
|
-
this.pastedContent = '';
|
|
389
|
-
await this.handleUserInput(input);
|
|
390
|
-
this._appendToHistory(input);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
async handleUserInput(userInput) {
|
|
394
|
-
(0, display_1.enableSquashNewlines)();
|
|
395
|
-
this.rl.setPrompt('');
|
|
396
|
-
if (!userInput) {
|
|
397
|
-
this.freshPrompt();
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
userInput = userInput.trim();
|
|
401
|
-
// Record input for frustration detection before processing
|
|
402
|
-
const cleanedInput = this.cleanCommandInput(userInput);
|
|
403
|
-
rage_detectors_1.rageDetectors.repeatInputDetector.recordEvent(cleanedInput.toLowerCase().trim());
|
|
404
|
-
const processedResult = await (0, with_hang_detection_1.withHangDetection)(userInput, () => this.processCommand(userInput));
|
|
405
|
-
if (processedResult === null) {
|
|
406
|
-
// Command was fully handled by processCommand
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
// processedResult is the string to be forwarded as a prompt
|
|
410
|
-
await this.forwardUserInput(processedResult);
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Cleans command input by removing leading slash while preserving special command syntax
|
|
414
|
-
* @param input The raw user input
|
|
415
|
-
* @returns The cleaned command string
|
|
416
|
-
*/
|
|
417
|
-
cleanCommandInput(input) {
|
|
418
|
-
return input.startsWith('/') ? input.substring(1) : input;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Checks if a command is a known slash command
|
|
422
|
-
* @param command The command to check (without leading slash)
|
|
423
|
-
*/
|
|
424
|
-
isKnownSlashCommand(command) {
|
|
425
|
-
return (0, menu_1.getSlashCommands)().some((cmd) => cmd.baseCommand === command);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Handles an unknown slash command by displaying an error message
|
|
429
|
-
* @param command The unknown command that was entered
|
|
430
|
-
*/
|
|
431
|
-
handleUnknownCommand(command) {
|
|
432
|
-
console.log((0, picocolors_1.yellow)(`Unknown slash command: ${command}`) +
|
|
433
|
-
`\nType / to see available commands`);
|
|
434
|
-
this.freshPrompt();
|
|
435
|
-
}
|
|
436
|
-
async processCommand(userInput) {
|
|
437
|
-
// Handle cost mode commands with optional message: /lite, /lite message, /normal, /normal message, etc.
|
|
438
|
-
const costModeMatch = userInput.match(/^\/?(lite|normal|max|experimental|ask)(?:\s+(.*))?$/i);
|
|
439
|
-
if (costModeMatch) {
|
|
440
|
-
const mode = costModeMatch[1].toLowerCase();
|
|
441
|
-
const message = costModeMatch[2]?.trim() || '';
|
|
442
|
-
// Track the cost mode command usage
|
|
443
|
-
(0, analytics_1.trackEvent)(analytics_events_1.AnalyticsEvent.SLASH_COMMAND_USED, {
|
|
444
|
-
userId: client_1.Client.getInstance().user?.id || 'unknown',
|
|
445
|
-
command: mode,
|
|
446
|
-
});
|
|
447
|
-
this.costMode = mode;
|
|
448
|
-
client_1.Client.getInstance().setCostMode(mode);
|
|
449
|
-
if (mode === 'lite') {
|
|
450
|
-
console.log((0, picocolors_1.yellow)('✨ Switched to lite mode (faster, cheaper)'));
|
|
451
|
-
}
|
|
452
|
-
else if (mode === 'normal') {
|
|
453
|
-
console.log((0, picocolors_1.green)('⚖️ Switched to normal mode (balanced)'));
|
|
454
|
-
}
|
|
455
|
-
else if (mode === 'max') {
|
|
456
|
-
console.log((0, picocolors_1.blueBright)('⚡ Switched to max mode (slower, more thorough)'));
|
|
457
|
-
}
|
|
458
|
-
else if (mode === 'experimental') {
|
|
459
|
-
console.log((0, picocolors_1.magenta)('🧪 Switched to experimental mode (cutting-edge)'));
|
|
460
|
-
}
|
|
461
|
-
else if (mode === 'ask') {
|
|
462
|
-
console.log((0, picocolors_1.cyan)('💬 Switched to ask mode (questions & planning only, no code changes)'));
|
|
463
|
-
console.log((0, picocolors_1.gray)('Tip: Use /export to save conversation summary to a file after fleshing out a plan'));
|
|
464
|
-
}
|
|
465
|
-
if (!message) {
|
|
466
|
-
this.freshPrompt();
|
|
467
|
-
return null; // Fully handled, no message to forward
|
|
468
|
-
}
|
|
469
|
-
// Return the message part to be processed as user input
|
|
470
|
-
return message;
|
|
471
|
-
}
|
|
472
|
-
const cleanInput = this.cleanCommandInput(userInput);
|
|
473
|
-
// Handle empty slash command
|
|
474
|
-
if (userInput === '/') {
|
|
475
|
-
return userInput; // Let it be processed as a prompt
|
|
476
|
-
}
|
|
477
|
-
// Track slash command usage if it starts with '/'
|
|
478
|
-
if (userInput.startsWith('/') && !userInput.startsWith('/!')) {
|
|
479
|
-
const commandBase = cleanInput.split(' ')[0];
|
|
480
|
-
if (!this.isKnownSlashCommand(commandBase)) {
|
|
481
|
-
(0, analytics_1.trackEvent)(analytics_events_1.AnalyticsEvent.INVALID_COMMAND, {
|
|
482
|
-
userId: client_1.Client.getInstance().user?.id || 'unknown',
|
|
483
|
-
command: cleanInput,
|
|
484
|
-
});
|
|
485
|
-
this.handleUnknownCommand(userInput);
|
|
486
|
-
return null;
|
|
487
|
-
}
|
|
488
|
-
// Track successful slash command usage
|
|
489
|
-
(0, analytics_1.trackEvent)(analytics_events_1.AnalyticsEvent.SLASH_COMMAND_USED, {
|
|
490
|
-
userId: client_1.Client.getInstance().user?.id || 'unknown',
|
|
491
|
-
command: commandBase,
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
if (cleanInput === 'help' || cleanInput === 'h') {
|
|
495
|
-
(0, menu_1.displayMenu)();
|
|
496
|
-
this.freshPrompt();
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
if (cleanInput === 'login' || cleanInput === 'signin') {
|
|
500
|
-
await client_1.Client.getInstance().login();
|
|
501
|
-
checkpoint_manager_1.checkpointManager.clearCheckpoints();
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
if (cleanInput === 'logout' || cleanInput === 'signout') {
|
|
505
|
-
await client_1.Client.getInstance().logout();
|
|
506
|
-
this.freshPrompt();
|
|
507
|
-
return null;
|
|
508
|
-
}
|
|
509
|
-
if (cleanInput.startsWith('ref-')) {
|
|
510
|
-
// Referral codes can be entered with or without a leading slash.
|
|
511
|
-
// Pass the cleaned input (without slash) to the handler.
|
|
512
|
-
await client_1.Client.getInstance().handleReferralCode(cleanInput.trim());
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
// Detect potential API key input first
|
|
516
|
-
// API keys are not slash commands, so use userInput
|
|
517
|
-
const detectionResult = (0, api_key_1.detectApiKey)(userInput);
|
|
518
|
-
if (detectionResult.status !== 'not_found') {
|
|
519
|
-
await (0, api_key_1.handleApiKeyInput)(client_1.Client.getInstance(), detectionResult, this.readyPromise, this.freshPrompt.bind(this));
|
|
520
|
-
return null;
|
|
521
|
-
}
|
|
522
|
-
if (cleanInput === 'usage' || cleanInput === 'credits') {
|
|
523
|
-
await client_1.Client.getInstance().getUsage();
|
|
524
|
-
return null;
|
|
525
|
-
}
|
|
526
|
-
if (cleanInput === 'quit' || cleanInput === 'exit' || cleanInput === 'q') {
|
|
527
|
-
await this.handleExit();
|
|
528
|
-
return null;
|
|
529
|
-
}
|
|
530
|
-
if (cleanInput === 'reset') {
|
|
531
|
-
await this.readyPromise;
|
|
532
|
-
await client_1.Client.getInstance().resetContext();
|
|
533
|
-
const projectRoot = (0, project_files_1.getProjectRoot)();
|
|
534
|
-
(0, base_1.clearScreen)();
|
|
535
|
-
// from index.ts
|
|
536
|
-
const config = (0, parser_1.loadCodebuffConfig)();
|
|
537
|
-
await (0, background_process_manager_1.killAllBackgroundProcesses)();
|
|
538
|
-
const processStartPromise = (0, startup_process_handler_1.logAndHandleStartup)();
|
|
539
|
-
const initFileContextPromise = (0, project_files_1.initProjectFileContextWithWorker)(projectRoot, true);
|
|
540
|
-
this.readyPromise = Promise.all([
|
|
541
|
-
initFileContextPromise,
|
|
542
|
-
processStartPromise,
|
|
543
|
-
]);
|
|
544
|
-
(0, menu_1.displayGreeting)(this.costMode, client_1.Client.getInstance().user?.name ?? null);
|
|
545
|
-
this.freshPrompt();
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
if (['diff', 'doff', 'dif', 'iff', 'd'].includes(cleanInput)) {
|
|
549
|
-
(0, diff_1.handleDiff)(client_1.Client.getInstance().lastChanges);
|
|
550
|
-
this.freshPrompt();
|
|
551
|
-
return null;
|
|
552
|
-
}
|
|
553
|
-
if (cleanInput === 'uuddlrlrba' ||
|
|
554
|
-
cleanInput === 'konami' ||
|
|
555
|
-
cleanInput === 'codebuffy') {
|
|
556
|
-
(0, easter_egg_1.showEasterEgg)(this.freshPrompt.bind(this));
|
|
557
|
-
return null;
|
|
558
|
-
}
|
|
559
|
-
// Checkpoint commands
|
|
560
|
-
if ((0, checkpoint_1.isCheckpointCommand)(cleanInput)) {
|
|
561
|
-
(0, analytics_1.trackEvent)(analytics_events_1.AnalyticsEvent.CHECKPOINT_COMMAND_USED, {
|
|
562
|
-
command: cleanInput, // Log the cleaned command
|
|
563
|
-
});
|
|
564
|
-
if ((0, checkpoint_1.isCheckpointCommand)(cleanInput, 'undo')) {
|
|
565
|
-
await (0, checkpoint_1.saveCheckpoint)(userInput, client_1.Client.getInstance(), this.readyPromise);
|
|
566
|
-
const toRestore = await (0, checkpoint_1.handleUndo)(client_1.Client.getInstance(), this.rl);
|
|
567
|
-
this.freshPrompt(toRestore);
|
|
568
|
-
return null;
|
|
569
|
-
}
|
|
570
|
-
if ((0, checkpoint_1.isCheckpointCommand)(cleanInput, 'redo')) {
|
|
571
|
-
await (0, checkpoint_1.saveCheckpoint)(userInput, client_1.Client.getInstance(), this.readyPromise);
|
|
572
|
-
const toRestore = await (0, checkpoint_1.handleRedo)(client_1.Client.getInstance(), this.rl);
|
|
573
|
-
this.freshPrompt(toRestore);
|
|
574
|
-
return null;
|
|
575
|
-
}
|
|
576
|
-
if ((0, checkpoint_1.isCheckpointCommand)(cleanInput, 'list')) {
|
|
577
|
-
await (0, checkpoint_1.saveCheckpoint)(userInput, client_1.Client.getInstance(), this.readyPromise);
|
|
578
|
-
await (0, checkpoint_1.listCheckpoints)();
|
|
579
|
-
this.freshPrompt();
|
|
580
|
-
return null;
|
|
581
|
-
}
|
|
582
|
-
const restoreMatch = (0, checkpoint_1.isCheckpointCommand)(cleanInput, 'restore');
|
|
583
|
-
if (restoreMatch) {
|
|
584
|
-
const id = parseInt(restoreMatch[1], 10);
|
|
585
|
-
await (0, checkpoint_1.saveCheckpoint)(userInput, client_1.Client.getInstance(), this.readyPromise);
|
|
586
|
-
const toRestore = await (0, checkpoint_1.handleRestoreCheckpoint)(id, client_1.Client.getInstance(), this.rl);
|
|
587
|
-
this.freshPrompt(toRestore);
|
|
588
|
-
return null;
|
|
589
|
-
}
|
|
590
|
-
if ((0, checkpoint_1.isCheckpointCommand)(cleanInput, 'clear')) {
|
|
591
|
-
(0, checkpoint_1.handleClearCheckpoints)();
|
|
592
|
-
this.freshPrompt();
|
|
593
|
-
return null;
|
|
594
|
-
}
|
|
595
|
-
if ((0, checkpoint_1.isCheckpointCommand)(cleanInput, 'save')) {
|
|
596
|
-
await (0, checkpoint_1.saveCheckpoint)(userInput, client_1.Client.getInstance(), this.readyPromise, true);
|
|
597
|
-
(0, checkpoint_1.displayCheckpointMenu)();
|
|
598
|
-
this.freshPrompt();
|
|
599
|
-
return null;
|
|
600
|
-
}
|
|
601
|
-
// Default checkpoint action (if just "checkpoint" or "/checkpoint" is typed)
|
|
602
|
-
(0, checkpoint_1.displayCheckpointMenu)();
|
|
603
|
-
this.freshPrompt();
|
|
604
|
-
return null;
|
|
605
|
-
}
|
|
606
|
-
if (cleanInput === 'init') {
|
|
607
|
-
(0, inititalization_flow_1.handleInitializationFlowLocally)();
|
|
608
|
-
// Also forward user input (original with / if present, or cleanInput) to the backend
|
|
609
|
-
// The original forwardUserInput takes the raw userInput.
|
|
610
|
-
return userInput; // Let it fall through to forwardUserInput
|
|
611
|
-
}
|
|
612
|
-
if (cleanInput === 'export') {
|
|
613
|
-
console.log((0, picocolors_1.yellow)('Exporting conversation to a file...'));
|
|
614
|
-
// Forward to backend like init command
|
|
615
|
-
return userInput; // Let it fall through to forwardUserInput
|
|
616
|
-
}
|
|
617
|
-
if (cleanInput === 'compact') {
|
|
618
|
-
console.log((0, picocolors_1.yellow)('Compacting conversation...'));
|
|
619
|
-
// Forward to backend
|
|
620
|
-
return userInput;
|
|
621
|
-
}
|
|
622
|
-
// If no command was matched, return the original userInput to be processed as a prompt
|
|
623
|
-
return userInput;
|
|
624
|
-
}
|
|
625
|
-
async forwardUserInput(promptContent) {
|
|
626
|
-
const cleanedInput = this.cleanCommandInput(promptContent);
|
|
627
|
-
await (0, checkpoint_1.saveCheckpoint)(cleanedInput, client_1.Client.getInstance(), this.readyPromise);
|
|
628
|
-
spinner_1.Spinner.get().start('Thinking...');
|
|
629
|
-
this.isReceivingResponse = true;
|
|
630
|
-
const { responsePromise, stopResponse } = await client_1.Client.getInstance().sendUserInput(cleanedInput);
|
|
631
|
-
this.stopResponse = stopResponse;
|
|
632
|
-
await responsePromise;
|
|
633
|
-
this.stopResponse = null;
|
|
634
|
-
this.isReceivingResponse = false;
|
|
635
|
-
spinner_1.Spinner.get().stop();
|
|
636
|
-
this.freshPrompt();
|
|
637
|
-
}
|
|
638
|
-
reconnectWhenNextIdle() {
|
|
639
|
-
if (!this.isReceivingResponse) {
|
|
640
|
-
client_1.Client.getInstance().reconnect();
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
this.shouldReconnectWhenIdle = true;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
onWebSocketError() {
|
|
647
|
-
rage_detectors_1.rageDetectors.exitAfterErrorDetector.start();
|
|
648
|
-
spinner_1.Spinner.get().stop();
|
|
649
|
-
this.isReceivingResponse = false;
|
|
650
|
-
if (this.stopResponse) {
|
|
651
|
-
this.stopResponse();
|
|
652
|
-
this.stopResponse = null;
|
|
653
|
-
}
|
|
654
|
-
console.error('\n' + (0, picocolors_1.yellow)('Could not connect. Retrying...'));
|
|
655
|
-
logger_1.logger.error({
|
|
656
|
-
errorMessage: 'Could not connect. Retrying...',
|
|
657
|
-
}, 'WebSocket connection error');
|
|
658
|
-
// Start hang detection for persistent connection issues
|
|
659
|
-
rage_detectors_1.rageDetectors.webSocketHangDetector.start({
|
|
660
|
-
connectionIssue: 'websocket_persistent_failure',
|
|
661
|
-
url: config_1.websocketUrl,
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
onWebSocketReconnect() {
|
|
665
|
-
// Stop hang detection on successful reconnection
|
|
666
|
-
rage_detectors_1.rageDetectors.webSocketHangDetector.stop();
|
|
667
|
-
console.log('\n' + (0, picocolors_1.green)('Reconnected!'));
|
|
668
|
-
this.freshPrompt();
|
|
669
|
-
}
|
|
670
|
-
handleKeyPress(str, key) {
|
|
671
|
-
// Track key mashing on repeated normal keys
|
|
672
|
-
const isModifier = key?.meta || key?.alt || key?.shift;
|
|
673
|
-
const isSpecialKey = key?.name === 'backspace' ||
|
|
674
|
-
key?.name === 'space' ||
|
|
675
|
-
key?.name === 'enter' ||
|
|
676
|
-
key?.name === 'tab';
|
|
677
|
-
// Control-C is a key mashing pattern we want to detect
|
|
678
|
-
const isControlC = key?.ctrl && key?.name === 'c';
|
|
679
|
-
if (isControlC) {
|
|
680
|
-
rage_detectors_1.rageDetectors.keyMashingDetector.recordEvent('ctrl-c');
|
|
681
|
-
}
|
|
682
|
-
else if (!isModifier && !isSpecialKey && key?.name) {
|
|
683
|
-
rage_detectors_1.rageDetectors.keyMashingDetector.recordEvent(key.name);
|
|
684
|
-
}
|
|
685
|
-
if (key.name === 'escape') {
|
|
686
|
-
this.handleEscKey();
|
|
687
|
-
}
|
|
688
|
-
if (str === '/') {
|
|
689
|
-
const currentLine = this.pastedContent + this.rl.line;
|
|
690
|
-
// Only track and show menu if '/' is the first character typed
|
|
691
|
-
if (currentLine === '/') {
|
|
692
|
-
(0, analytics_1.trackEvent)(analytics_events_1.AnalyticsEvent.SLASH_MENU_ACTIVATED, {
|
|
693
|
-
userId: client_1.Client.getInstance().user?.id || 'unknown',
|
|
694
|
-
});
|
|
695
|
-
(0, menu_1.displaySlashCommandHelperMenu)();
|
|
696
|
-
// Call freshPrompt and pre-fill the line with the slash
|
|
697
|
-
// so the user can continue typing their command.
|
|
698
|
-
this.freshPrompt('/');
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
if (!this.isPasting &&
|
|
702
|
-
str === ' ' &&
|
|
703
|
-
'_refreshLine' in this.rl &&
|
|
704
|
-
'line' in this.rl &&
|
|
705
|
-
'cursor' in this.rl) {
|
|
706
|
-
const rlAny = this.rl;
|
|
707
|
-
const { cursor, line } = rlAny;
|
|
708
|
-
const prevTwoChars = cursor > 1 ? line.slice(cursor - 2, cursor) : '';
|
|
709
|
-
if (prevTwoChars === ' ') {
|
|
710
|
-
rlAny.line = line.slice(0, cursor - 2) + '\n\n' + line.slice(cursor);
|
|
711
|
-
rlAny._refreshLine();
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
this.detectPasting();
|
|
715
|
-
}
|
|
716
|
-
async handleSigint() {
|
|
717
|
-
if ((0, base_1.isCommandRunning)()) {
|
|
718
|
-
(0, base_1.resetShell)((0, project_files_1.getProjectRoot)());
|
|
719
|
-
}
|
|
720
|
-
if (this.isReceivingResponse) {
|
|
721
|
-
this.handleStopResponse();
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
const now = Date.now();
|
|
725
|
-
if (now - this.lastSigintTime < 5000 && !this.rl.line) {
|
|
726
|
-
await this.handleExit();
|
|
727
|
-
}
|
|
728
|
-
else {
|
|
729
|
-
this.lastSigintTime = now;
|
|
730
|
-
console.log('\nPress Ctrl-C again to exit');
|
|
731
|
-
this.freshPrompt();
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
handleEscKey() {
|
|
736
|
-
if (this.isReceivingResponse) {
|
|
737
|
-
this.handleStopResponse();
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
handleStopResponse() {
|
|
741
|
-
console.log((0, picocolors_1.yellow)('\n[Response stopped by user]'));
|
|
742
|
-
this.isReceivingResponse = false;
|
|
743
|
-
if (this.stopResponse) {
|
|
744
|
-
this.stopResponse();
|
|
745
|
-
}
|
|
746
|
-
spinner_1.Spinner.get().stop();
|
|
747
|
-
}
|
|
748
|
-
async handleExit() {
|
|
749
|
-
// Start exit time detector
|
|
750
|
-
rage_detectors_1.rageDetectors.exitTimeDetector.start();
|
|
751
|
-
// Call end() on the exit detector to check if user is exiting quickly after an error
|
|
752
|
-
rage_detectors_1.rageDetectors.exitAfterErrorDetector.end();
|
|
753
|
-
spinner_1.Spinner.get().restoreCursor();
|
|
754
|
-
process.removeAllListeners('unhandledRejection');
|
|
755
|
-
process.removeAllListeners('uncaughtException');
|
|
756
|
-
console.log('\n');
|
|
757
|
-
// Kill the persistent PTY process first
|
|
758
|
-
(0, base_1.killAndResetPersistentProcess)();
|
|
759
|
-
await (0, background_process_manager_1.killAllBackgroundProcesses)();
|
|
760
|
-
client_1.Client.getInstance().close(); // Close WebSocket
|
|
761
|
-
const client = client_1.Client.getInstance();
|
|
762
|
-
// Check for organization coverage first
|
|
763
|
-
const coverage = await client.checkRepositoryCoverage();
|
|
764
|
-
// Calculate session usage and total for display
|
|
765
|
-
const totalCreditsUsedThisSession = Object.values(client.creditsByPromptId)
|
|
766
|
-
.flat()
|
|
767
|
-
.reduce((sum, credits) => sum + credits, 0);
|
|
768
|
-
let exitUsageMessage = `${(0, string_1.pluralize)(totalCreditsUsedThisSession, 'credit')} used this session`;
|
|
769
|
-
if (client.usageData.remainingBalance !== null) {
|
|
770
|
-
exitUsageMessage += `, ${client.usageData.remainingBalance.toLocaleString()} credits left.`;
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
exitUsageMessage += '.';
|
|
774
|
-
}
|
|
775
|
-
console.log(exitUsageMessage);
|
|
776
|
-
if (coverage.isCovered && coverage.organizationName) {
|
|
777
|
-
// When covered by an organization, show organization information
|
|
778
|
-
console.log((0, picocolors_1.green)(`Your usage in this repository was covered by the ${(0, picocolors_1.bold)(coverage.organizationName)} organization.`));
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
// Only show personal credit renewal when not covered by an organization
|
|
782
|
-
if (client.usageData.next_quota_reset) {
|
|
783
|
-
const daysUntilReset = Math.ceil((new Date(client.usageData.next_quota_reset).getTime() - Date.now()) /
|
|
784
|
-
(1000 * 60 * 60 * 24));
|
|
785
|
-
console.log(`Your free credits will reset in ${(0, string_1.pluralize)(daysUntilReset, 'day')}.`);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
// End exit time detector right before process.exit
|
|
789
|
-
rage_detectors_1.rageDetectors.exitTimeDetector.end();
|
|
790
|
-
await (0, analytics_1.flushAnalytics)();
|
|
791
|
-
process.exit(0);
|
|
792
|
-
}
|
|
793
|
-
detectPasting() {
|
|
794
|
-
const currentTime = Date.now();
|
|
795
|
-
const timeDiff = currentTime - this.lastInputTime;
|
|
796
|
-
if (timeDiff < 10) {
|
|
797
|
-
this.consecutiveFastInputs++;
|
|
798
|
-
if (this.consecutiveFastInputs >= 2) {
|
|
799
|
-
this.isPasting = true;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
this.consecutiveFastInputs = 0;
|
|
804
|
-
if (this.isPasting) {
|
|
805
|
-
this.isPasting = false;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
this.lastInputTime = currentTime;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
exports.CLI = CLI;
|
|
812
|
-
//# sourceMappingURL=cli.js.map
|