From ed536d3505167cd15e46ec4dee49847eb87b63a8 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:02:56 -0700 Subject: [PATCH 01/18] feat: basic ink tui --- README.md | 11 +- package-lock.json | 600 ++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 + src/args.ts | 11 +- src/index.ts | 7 + src/ui/TUIChat.tsx | 201 +++++++++++++++ src/ui/index.ts | 51 ++++ tsconfig.json | 3 +- 8 files changed, 875 insertions(+), 12 deletions(-) create mode 100644 src/ui/TUIChat.tsx create mode 100644 src/ui/index.ts diff --git a/README.md b/README.md index 7fc05a0f5..df8eb7a0e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ A command-line interface for Continue Dev that provides an interactive AI-assist ## Features - 🤖 Interactive AI Assistant Chat +- 🎨 Beautiful Terminal User Interface (TUI) - 🔐 Secure Authentication via WorkOS - 🛠️ Built-in Development Tools - ⚡ Real-time Response Streaming @@ -25,6 +26,12 @@ npm install @continuedev/cli -g continue-cli ``` +### Terminal User Interface Mode + +```bash +continue-cli --tui +``` + ### With Custom Assistant ```bash @@ -87,6 +94,7 @@ npm test src/ ├── auth/ # Authentication implementation ├── tools/ # CLI tools and utilities +├── ui/ # Terminal User Interface components ├── index.ts # Main entry point ├── args.ts # Command line argument parsing ├── client.ts # Client implementation @@ -99,6 +107,7 @@ src/ - `@continuedev/*` packages for core functionality - `@workos-inc/node` for authentication - `openai` for AI capabilities +- `ink` and `react` for Terminal UI - Various utility packages (chalk, axios, etc.) ## License @@ -111,4 +120,4 @@ Contributions are welcome! Please feel free to submit a Pull Request. ## Support -For issues and feature requests, please use the GitHub issue tracker. +For issues and feature requests, please use the GitHub issue tracker. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8ae32b198..154705eb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,12 +12,15 @@ "@continuedev/openai-adapters": "^1.0.18", "@continuedev/sdk": "^0.0.12", "@modelcontextprotocol/sdk": "^1.9.0", + "@types/react": "^19.1.8", "@workos-inc/node": "^7.45.0", "axios": "^1.8.4", "chalk": "^5.4.1", "diff": "^7.0.0", "dotenv": "^16.5.0", + "ink": "^6.0.1", "open": "^10.1.0", + "react": "^19.1.0", "readline-sync": "^1.4.10", "uuid": "^9.0.1" }, @@ -35,6 +38,40 @@ "ts-node": "^10.9.2" } }, + "node_modules/@alcalzone/ansi-tokenize": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@alcalzone/ansi-tokenize/-/ansi-tokenize-0.1.3.tgz", + "integrity": "sha512-3yWxPTq3UQ/FY9p1ErPxIyfT64elWaMvM9lIHnaqpyft63tkxodF5aUElYHrdisWve5cETkh1+KBw1yJuW0aRw==", + "dependencies": { + "ansi-styles": "^6.2.1", + "is-fullwidth-code-point": "^4.0.0" + }, + "engines": { + "node": ">=14.13.1" + } + }, + "node_modules/@alcalzone/ansi-tokenize/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@alcalzone/ansi-tokenize/node_modules/is-fullwidth-code-point": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-4.0.0.tgz", + "integrity": "sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1674,6 +1711,14 @@ "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", "license": "MIT" }, + "node_modules/@types/react": { + "version": "19.1.8", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.8.tgz", + "integrity": "sha512-AwAfQ2Wa5bCx9WP8nZL2uMZWod7J7/JSplxbTmBQ5ms6QpqNYm672H0Vu9ZVKVngQ+ii4R/byguVEUZQyeg44g==", + "dependencies": { + "csstype": "^3.0.2" + } + }, "node_modules/@types/readline-sync": { "version": "1.4.8", "resolved": "https://registry.npmjs.org/@types/readline-sync/-/readline-sync-1.4.8.tgz", @@ -1931,6 +1976,17 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "license": "MIT" }, + "node_modules/auto-bind": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/auto-bind/-/auto-bind-5.0.1.tgz", + "integrity": "sha512-ooviqdwwgfIfNmDwo94wlshcdzfO64XV0Cg6oDsDYBJfITDz1EngD2z7DkbvCWn+XIMsIqW27sEVF6qcpJrRcg==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/axios": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz", @@ -2388,6 +2444,129 @@ "dev": true, "license": "MIT" }, + "node_modules/cli-boxes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-3.0.0.tgz", + "integrity": "sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-cursor": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", + "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", + "dependencies": { + "restore-cursor": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-truncate": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-4.0.0.tgz", + "integrity": "sha512-nPdaFdQ0h/GEigbPClz11D0v/ZJEwxmeVZGeMo3Z5StPtUTkA9o1lD6QwoirYiSDzbcwn2XcjwmCp68W1IS4TA==", + "dependencies": { + "slice-ansi": "^5.0.0", + "string-width": "^7.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-truncate/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/cli-truncate/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/cli-truncate/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==" + }, + "node_modules/cli-truncate/node_modules/is-fullwidth-code-point": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-4.0.0.tgz", + "integrity": "sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-truncate/node_modules/slice-ansi": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-5.0.0.tgz", + "integrity": "sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==", + "dependencies": { + "ansi-styles": "^6.0.0", + "is-fullwidth-code-point": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/slice-ansi?sponsor=1" + } + }, + "node_modules/cli-truncate/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-truncate/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -2414,6 +2593,17 @@ "node": ">= 0.12.0" } }, + "node_modules/code-excerpt": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/code-excerpt/-/code-excerpt-4.0.0.tgz", + "integrity": "sha512-xxodCmBen3iy2i0WtAK8FlFNrRzjUqjRsMfho58xT/wvZU1YTM3fCnRjcy1gJPMepaRlgm/0e6w8SpWHpn3/cA==", + "dependencies": { + "convert-to-spaces": "^2.0.1" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, "node_modules/collect-v8-coverage": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", @@ -2488,6 +2678,14 @@ "dev": true, "license": "MIT" }, + "node_modules/convert-to-spaces": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/convert-to-spaces/-/convert-to-spaces-2.0.1.tgz", + "integrity": "sha512-rcQ1bsQO9799wq24uE5AM2tAILy4gXGIK/njFWcVQkGNZ96edlpY+A7bjwvzjYvLDyzmG1MmMLZhpcsb+klNMQ==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, "node_modules/cookie": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", @@ -2614,6 +2812,11 @@ "node": ">= 8" } }, + "node_modules/csstype": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", + "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" + }, "node_modules/data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", @@ -2836,6 +3039,17 @@ "node": ">= 0.8" } }, + "node_modules/environment": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz", + "integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -2891,6 +3105,11 @@ "node": ">= 0.4" } }, + "node_modules/es-toolkit": { + "version": "1.39.7", + "resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.39.7.tgz", + "integrity": "sha512-ek/wWryKouBrZIjkwW2BFf91CWOIMvoy2AE5YYgUrfWsJQM2Su1LoLtrw8uusEpN9RfqLlV/0FVNjT0WMv8Bxw==" + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -2911,7 +3130,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -3359,6 +3577,17 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/get-east-asian-width": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.3.0.tgz", + "integrity": "sha512-vpeMIQKxczTD/0s2CdEWHcb0eeJe6TFjxb+J5xgX7hScxqrGuyjmv4c1D4A/gelKfyox0gJJwIHF+fLjeaM8kQ==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/get-intrinsic": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", @@ -3649,6 +3878,17 @@ "node": ">=0.8.19" } }, + "node_modules/indent-string": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-5.0.0.tgz", + "integrity": "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -3667,6 +3907,151 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "license": "ISC" }, + "node_modules/ink": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ink/-/ink-6.0.1.tgz", + "integrity": "sha512-vhhFrCodTHZAPPSdMYzLEbeI0Ug37R9j6yA0kLKok9kSK53lQtj/RJhEQJUjq6OwT4N33nxqSRd/7yXhEhVPIw==", + "dependencies": { + "@alcalzone/ansi-tokenize": "^0.1.3", + "ansi-escapes": "^7.0.0", + "ansi-styles": "^6.2.1", + "auto-bind": "^5.0.1", + "chalk": "^5.3.0", + "cli-boxes": "^3.0.0", + "cli-cursor": "^4.0.0", + "cli-truncate": "^4.0.0", + "code-excerpt": "^4.0.0", + "es-toolkit": "^1.22.0", + "indent-string": "^5.0.0", + "is-in-ci": "^1.0.0", + "patch-console": "^2.0.0", + "react-reconciler": "^0.32.0", + "scheduler": "^0.23.0", + "signal-exit": "^3.0.7", + "slice-ansi": "^7.1.0", + "stack-utils": "^2.0.6", + "string-width": "^7.2.0", + "type-fest": "^4.27.0", + "widest-line": "^5.0.0", + "wrap-ansi": "^9.0.0", + "ws": "^8.18.0", + "yoga-layout": "~3.2.1" + }, + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "@types/react": ">=19.0.0", + "react": ">=19.0.0", + "react-devtools-core": "^4.19.1" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "react-devtools-core": { + "optional": true + } + } + }, + "node_modules/ink/node_modules/ansi-escapes": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.0.0.tgz", + "integrity": "sha512-GdYO7a61mR0fOlAsvC9/rIHf7L96sBc6dEWzeOu+KAea5bZyQRPIpojrVoI4AXGJS/ycu/fBTdLrUkA4ODrvjw==", + "dependencies": { + "environment": "^1.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ink/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ink/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/ink/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==" + }, + "node_modules/ink/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ink/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/ink/node_modules/type-fest": { + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ink/node_modules/wrap-ansi": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz", + "integrity": "sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==", + "dependencies": { + "ansi-styles": "^6.2.1", + "string-width": "^7.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -3795,6 +4180,20 @@ "node": ">=6" } }, + "node_modules/is-in-ci": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-in-ci/-/is-in-ci-1.0.0.tgz", + "integrity": "sha512-eUuAjybVTHMYWm/U+vBO1sY/JOCgoPCXRxzdju0K+K0BiGW0SChEL1MLC0PoCIR1OlPo5YAp8HuQoUlsWEICwg==", + "bin": { + "is-in-ci": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-inside-container": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", @@ -5070,7 +5469,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true, "license": "MIT" }, "node_modules/js-yaml": { @@ -5179,6 +5577,17 @@ "dev": true, "license": "MIT" }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -5311,7 +5720,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -5473,7 +5881,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", - "dev": true, "license": "MIT", "dependencies": { "mimic-fn": "^2.1.0" @@ -5651,6 +6058,14 @@ "node": ">= 0.8" } }, + "node_modules/patch-console": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/patch-console/-/patch-console-2.0.0.tgz", + "integrity": "sha512-0YNdUceMdaQwoKce1gatDScmMo5pu/tfABfnzEqeG0gtTmd7mh/WcwgUjtAeOU7N8nFFlbQBnFK2gXW5fGvmMA==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -5879,6 +6294,14 @@ "node": ">= 0.8" } }, + "node_modules/react": { + "version": "19.1.0", + "resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz", + "integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/react-is": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", @@ -5886,6 +6309,25 @@ "dev": true, "license": "MIT" }, + "node_modules/react-reconciler": { + "version": "0.32.0", + "resolved": "https://registry.npmjs.org/react-reconciler/-/react-reconciler-0.32.0.tgz", + "integrity": "sha512-2NPMOzgTlG0ZWdIf3qG+dcbLSoAc/uLfOwckc3ofy5sSK0pLJqnQLpUFxvGcN2rlXSjnVtGeeFLNimCQEj5gOQ==", + "dependencies": { + "scheduler": "^0.26.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "peerDependencies": { + "react": "^19.1.0" + } + }, + "node_modules/react-reconciler/node_modules/scheduler": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.26.0.tgz", + "integrity": "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA==" + }, "node_modules/readline-sync": { "version": "1.4.10", "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", @@ -5959,6 +6401,21 @@ "node": ">=10" } }, + "node_modules/restore-cursor": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", + "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", + "dependencies": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/router": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", @@ -6013,6 +6470,14 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/scheduler": { + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", @@ -6163,7 +6628,6 @@ "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true, "license": "ISC" }, "node_modules/sisteransi": { @@ -6183,6 +6647,46 @@ "node": ">=8" } }, + "node_modules/slice-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-7.1.0.tgz", + "integrity": "sha512-bSiSngZ/jWeX93BqeIAbImyTbEihizcwNjFoRUIY/T1wWQsfsm2Vw1agPKylXvQTU7iASGdHhyqRlqQzfz+Htg==", + "dependencies": { + "ansi-styles": "^6.2.1", + "is-fullwidth-code-point": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/slice-ansi?sponsor=1" + } + }, + "node_modules/slice-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/slice-ansi/node_modules/is-fullwidth-code-point": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-5.0.0.tgz", + "integrity": "sha512-OVa3u9kkBbw7b8Xw5F9P+D/T9X+Z4+JruYVNapTjPYZYUznQ5YfWeFkOj606XYYW8yugTfC8Pj0hYqvi4ryAhA==", + "dependencies": { + "get-east-asian-width": "^1.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -6215,7 +6719,6 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", "integrity": "sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==", - "dev": true, "license": "MIT", "dependencies": { "escape-string-regexp": "^2.0.0" @@ -6725,6 +7228,66 @@ "node": ">= 8" } }, + "node_modules/widest-line": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-5.0.0.tgz", + "integrity": "sha512-c9bZp7b5YtRj2wOe6dlj32MK+Bx/M/d+9VB2SHM1OtsUHR0aV0tdP6DWh/iMt0kWi1t5g1Iudu6hQRNd1A4PVA==", + "dependencies": { + "string-width": "^7.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/widest-line/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/widest-line/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==" + }, + "node_modules/widest-line/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/widest-line/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -6779,6 +7342,26 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -6860,6 +7443,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yoga-layout": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/yoga-layout/-/yoga-layout-3.2.1.tgz", + "integrity": "sha512-0LPOt3AxKqMdFBZA3HBAt/t/8vIKq7VaQYbuA8WxCgung+p9TVyKRYdpvCb80HcdTN2NkbIKbhNwKUfm3tQywQ==" + }, "node_modules/zod": { "version": "3.24.4", "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.4.tgz", diff --git a/package.json b/package.json index 789046cf2..516d8da07 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,15 @@ "@continuedev/openai-adapters": "^1.0.18", "@continuedev/sdk": "^0.0.12", "@modelcontextprotocol/sdk": "^1.9.0", + "@types/react": "^19.1.8", "@workos-inc/node": "^7.45.0", "axios": "^1.8.4", "chalk": "^5.4.1", "diff": "^7.0.0", "dotenv": "^16.5.0", + "ink": "^6.0.1", "open": "^10.1.0", + "react": "^19.1.0", "readline-sync": "^1.4.10", "uuid": "^9.0.1" }, diff --git a/src/args.ts b/src/args.ts index deaad7121..bc17b7027 100644 --- a/src/args.ts +++ b/src/args.ts @@ -1,10 +1,8 @@ -import * as os from "os"; -import * as path from "path"; - export interface CommandLineArgs { isHeadless: boolean; configPath: string; prompt?: string; // Optional prompt argument + useTUI: boolean; // New flag for TUI mode } /** @@ -17,7 +15,8 @@ export function parseArgs(): CommandLineArgs { // Default values const result: CommandLineArgs = { isHeadless: false, - configPath: path.join(os.homedir(), ".continue", "config.yaml"), + configPath: "nate/default-assistant", + useTUI: false, }; // Parse flags @@ -25,6 +24,10 @@ export function parseArgs(): CommandLineArgs { result.isHeadless = true; } + if (args.includes("--tui")) { + result.useTUI = true; + } + // Get config path from --config flag const configIndex = args.indexOf("--config"); if (configIndex !== -1 && configIndex + 1 < args.length) { diff --git a/src/index.ts b/src/index.ts index 1fde7d898..2fb842254 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ import { configureLogger } from "./logger.js"; import { MCPService } from "./mcp.js"; import { handleSlashCommands } from "./slashCommands.js"; import { streamChatResponse } from "./streamChatResponse.js"; +import { startTUIChat } from "./ui/index.js"; // Parse command line arguments const args = parseArgs(); @@ -28,6 +29,12 @@ async function chat() { process.exit(1); } + // If TUI mode is requested, start the TUI chat + if (args.useTUI) { + await startTUIChat(args.configPath, args.prompt); + return; + } + const authConfig = loadAuthConfig(); // Check if the assistant path is a file or a slug diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx new file mode 100644 index 000000000..b9eb38642 --- /dev/null +++ b/src/ui/TUIChat.tsx @@ -0,0 +1,201 @@ +import React, { useState, useEffect } from 'react'; +import { Box, Text, useInput, useApp } from 'ink'; +import { ChatCompletionMessageParam } from 'openai/resources.mjs'; +import { ContinueClient } from '@continuedev/sdk'; +import { streamChatResponse } from '../streamChatResponse.js'; +import { handleSlashCommands } from '../slashCommands.js'; + +interface TUIChatProps { + assistant: ContinueClient['assistant']; + client: ContinueClient['client']; + initialPrompt?: string; +} + +interface DisplayMessage { + role: string; + content: string; + isStreaming?: boolean; +} + +const TUIChat: React.FC = ({ assistant, client, initialPrompt }) => { + const [chatHistory, setChatHistory] = useState(() => { + const history: ChatCompletionMessageParam[] = []; + const systemMessage = assistant.systemMessage; + if (systemMessage) { + history.push({ role: 'system', content: systemMessage }); + } + return history; + }); + + const [userInput, setUserInput] = useState(''); + const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); + const [currentAssistantMessage, setCurrentAssistantMessage] = useState(''); + const [messages, setMessages] = useState([]); + const { exit } = useApp(); + + // Handle initial prompt + useEffect(() => { + if (initialPrompt) { + handleUserMessage(initialPrompt); + } + }, [initialPrompt]); + + const handleUserMessage = async (message: string) => { + // Handle slash commands + const commandResult = handleSlashCommands(message, assistant.config); + if (commandResult) { + if (commandResult.exit) { + exit(); + return; + } + + // Add command output to messages + if (commandResult.output) { + setMessages(prev => [...prev, { role: 'system', content: commandResult.output! }]); + } + + if (commandResult.newInput) { + message = commandResult.newInput; + } else { + return; + } + } + + // Add user message to history and display + const newUserMessage: ChatCompletionMessageParam = { role: 'user', content: message }; + setChatHistory(prev => [...prev, newUserMessage]); + setMessages(prev => [...prev, { role: 'user', content: message }]); + + // Start streaming response + setIsWaitingForResponse(true); + setCurrentAssistantMessage(''); + + // Add placeholder for streaming message + setMessages(prev => [...prev, { role: 'assistant', content: '', isStreaming: true }]); + + try { + const newHistory = [...chatHistory, newUserMessage]; + + // Create a custom stream handler that updates our UI + const originalWrite = process.stdout.write; + let assistantResponse = ''; + + process.stdout.write = function(chunk: any, encoding?: any, callback?: any) { + const text = chunk.toString(); + assistantResponse += text; + setCurrentAssistantMessage(assistantResponse); + + // Update the streaming message + setMessages(prev => { + const newMessages = [...prev]; + const lastMessage = newMessages[newMessages.length - 1]; + if (lastMessage.isStreaming) { + lastMessage.content = assistantResponse; + } + return newMessages; + }); + + // Call original write for logging purposes + return originalWrite.call(this, chunk, encoding, callback); + }; + + await streamChatResponse(newHistory, assistant, client); + + // Restore original write + process.stdout.write = originalWrite; + + // Finalize the assistant message + const finalAssistantMessage: ChatCompletionMessageParam = { role: 'assistant', content: assistantResponse }; + setChatHistory(prev => [...prev, finalAssistantMessage]); + + // Update messages to remove streaming flag + setMessages(prev => { + const newMessages = [...prev]; + const lastMessage = newMessages[newMessages.length - 1]; + if (lastMessage.isStreaming) { + lastMessage.isStreaming = false; + } + return newMessages; + }); + + } catch (error: any) { + const errorMessage = `Error: ${error.message}`; + setMessages(prev => [...prev, { role: 'system', content: errorMessage }]); + } finally { + setIsWaitingForResponse(false); + setCurrentAssistantMessage(''); + } + }; + + useInput((input, key) => { + if (key.ctrl && input === 'c') { + exit(); + return; + } + + if (key.return) { + if (userInput.trim() && !isWaitingForResponse) { + handleUserMessage(userInput.trim()); + setUserInput(''); + } + return; + } + + if (key.backspace) { + setUserInput(prev => prev.slice(0, -1)); + return; + } + + if (!key.ctrl && !key.meta && input) { + setUserInput(prev => prev + input); + } + }); + + const renderMessage = (message: DisplayMessage, index: number) => { + const isUser = message.role === 'user'; + const isSystem = message.role === 'system'; + + if (isSystem) { + return ( + + {message.content} + + ); + } + + return ( + + + {isUser ? "You:" : "Assistant:"} + + {message.content} + {message.isStreaming && ▋} + + ); + }; + + return ( + + {/* Chat history */} + + {messages.map(renderMessage)} + + + {/* Input area */} + + You: + {userInput} + {!isWaitingForResponse && ▋} + + + {/* Status */} + {isWaitingForResponse && ( + + Waiting for response... + + )} + + ); +}; + +export default TUIChat; \ No newline at end of file diff --git a/src/ui/index.ts b/src/ui/index.ts new file mode 100644 index 000000000..616414ae2 --- /dev/null +++ b/src/ui/index.ts @@ -0,0 +1,51 @@ +import { ContinueClient } from "@continuedev/sdk"; +import chalk from "chalk"; +import { render } from "ink"; +import React from "react"; +import { loadAuthConfig } from "../auth/workos.js"; +import { initializeContinueSDK } from "../continueSDK.js"; +import { introMessage } from "../intro.js"; +import { MCPService } from "../mcp.js"; +import TUIChat from "./TUIChat.js"; + +export async function startTUIChat(configPath: string, initialPrompt?: string) { + const authConfig = loadAuthConfig(); + + let assistant: ContinueClient["assistant"]; + let client: ContinueClient["client"]; + + try { + const continueSdk = await initializeContinueSDK( + authConfig.accessToken, + configPath + ); + + assistant = continueSdk.assistant; + client = continueSdk.client; + } catch (error) { + console.error(chalk.red(`Error loading assistant ${configPath}:`), error); + throw error; + } + + const mcpService = await MCPService.create(assistant.config); + + // Show intro message before starting TUI + introMessage(assistant, mcpService); + + // Start the TUI + const { unmount } = render( + React.createElement(TUIChat, { + assistant, + client, + initialPrompt, + }) + ); + + // Handle cleanup + process.on("SIGINT", () => { + unmount(); + process.exit(0); + }); + + return { unmount }; +} diff --git a/tsconfig.json b/tsconfig.json index 7893251dc..089f429f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,8 @@ "outDir": "dist", "declaration": true, "sourceMap": true, - "inlineSources": true + "inlineSources": true, + "jsx": "react" }, "include": ["src/**/*"] } From 3f7ae74bdd6712cb29c684757a11f179e57a2fb4 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:06:44 -0700 Subject: [PATCH 02/18] refactor: refactor --- src/index.ts | 32 ++++++++++++++++---------------- src/ui/index.ts | 32 +++++++------------------------- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2fb842254..60bbfd72a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,18 +29,8 @@ async function chat() { process.exit(1); } - // If TUI mode is requested, start the TUI chat - if (args.useTUI) { - await startTUIChat(args.configPath, args.prompt); - return; - } - const authConfig = loadAuthConfig(); - // Check if the assistant path is a file or a slug - let assistant: ContinueClient["assistant"]; - let client: ContinueClient["client"]; - // This was the previous default behavior, but currently the SDK // only supports slugs, so we've disabled reading local assistant files @@ -69,14 +59,20 @@ async function chat() { // } // } + // Initialize ContinueSDK and MCPService once + let assistant: ContinueClient["assistant"]; + let client: ContinueClient["client"]; + let mcpService: MCPService; + try { - let continueSdk = await initializeContinueSDK( + const continueSdk = await initializeContinueSDK( authConfig.accessToken, args.configPath ); assistant = continueSdk.assistant; client = continueSdk.client; + mcpService = await MCPService.create(assistant.config); } catch (error) { console.error( chalk.red(`Error loading assistant ${args.configPath}:`), @@ -85,16 +81,20 @@ async function chat() { throw error; } - const mcpService = await MCPService.create(assistant!.config); + // If TUI mode is requested, start the TUI chat with the initialized services + if (args.useTUI) { + await startTUIChat(assistant, client, mcpService, args.prompt); + return; + } // Only show intro message if not in headless mode if (!args.isHeadless) { - introMessage(assistant!, mcpService); + introMessage(assistant, mcpService); } // Rules const chatHistory: ChatCompletionMessageParam[] = []; - const systemMessage = assistant!.systemMessage; + const systemMessage = assistant.systemMessage; if (systemMessage) { chatHistory.push({ role: "system", content: systemMessage }); } @@ -115,7 +115,7 @@ async function chat() { isFirstMessage = false; // Handle slash commands - const commandResult = handleSlashCommands(userInput, assistant!.config); + const commandResult = handleSlashCommands(userInput, assistant.config); if (commandResult) { if (commandResult.exit) { break; @@ -140,7 +140,7 @@ async function chat() { } try { - await streamChatResponse(chatHistory, assistant!, client!); + await streamChatResponse(chatHistory, assistant, client); } catch (e: any) { console.error(`\n${chalk.red(`Error: ${e.message}`)}`); console.info( diff --git a/src/ui/index.ts b/src/ui/index.ts index 616414ae2..36eb0fcb5 100644 --- a/src/ui/index.ts +++ b/src/ui/index.ts @@ -1,34 +1,16 @@ import { ContinueClient } from "@continuedev/sdk"; -import chalk from "chalk"; import { render } from "ink"; import React from "react"; -import { loadAuthConfig } from "../auth/workos.js"; -import { initializeContinueSDK } from "../continueSDK.js"; import { introMessage } from "../intro.js"; import { MCPService } from "../mcp.js"; import TUIChat from "./TUIChat.js"; -export async function startTUIChat(configPath: string, initialPrompt?: string) { - const authConfig = loadAuthConfig(); - - let assistant: ContinueClient["assistant"]; - let client: ContinueClient["client"]; - - try { - const continueSdk = await initializeContinueSDK( - authConfig.accessToken, - configPath - ); - - assistant = continueSdk.assistant; - client = continueSdk.client; - } catch (error) { - console.error(chalk.red(`Error loading assistant ${configPath}:`), error); - throw error; - } - - const mcpService = await MCPService.create(assistant.config); - +export async function startTUIChat( + assistant: ContinueClient["assistant"], + client: ContinueClient["client"], + mcpService: MCPService, + initialPrompt?: string +) { // Show intro message before starting TUI introMessage(assistant, mcpService); @@ -48,4 +30,4 @@ export async function startTUIChat(configPath: string, initialPrompt?: string) { }); return { unmount }; -} +} \ No newline at end of file From 4af31b5f71356d61e4e389209d6f9e87829356da Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:12:04 -0700 Subject: [PATCH 03/18] chore: format TUIChat.tsx --- src/ui/TUIChat.tsx | 148 +++++++++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 60 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index b9eb38642..7ba547029 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -1,35 +1,41 @@ -import React, { useState, useEffect } from 'react'; -import { Box, Text, useInput, useApp } from 'ink'; -import { ChatCompletionMessageParam } from 'openai/resources.mjs'; -import { ContinueClient } from '@continuedev/sdk'; -import { streamChatResponse } from '../streamChatResponse.js'; -import { handleSlashCommands } from '../slashCommands.js'; +import { ContinueClient } from "@continuedev/sdk"; +import { Box, Text, useApp, useInput } from "ink"; +import { ChatCompletionMessageParam } from "openai/resources.mjs"; +import React, { useEffect, useState } from "react"; +import { handleSlashCommands } from "../slashCommands.js"; +import { streamChatResponse } from "../streamChatResponse.js"; interface TUIChatProps { - assistant: ContinueClient['assistant']; - client: ContinueClient['client']; + assistant: ContinueClient["assistant"]; + client: ContinueClient["client"]; initialPrompt?: string; } interface DisplayMessage { - role: string; - content: string; + role: string; + content: string; isStreaming?: boolean; } -const TUIChat: React.FC = ({ assistant, client, initialPrompt }) => { - const [chatHistory, setChatHistory] = useState(() => { - const history: ChatCompletionMessageParam[] = []; - const systemMessage = assistant.systemMessage; - if (systemMessage) { - history.push({ role: 'system', content: systemMessage }); +const TUIChat: React.FC = ({ + assistant, + client, + initialPrompt, +}) => { + const [chatHistory, setChatHistory] = useState( + () => { + const history: ChatCompletionMessageParam[] = []; + const systemMessage = assistant.systemMessage; + if (systemMessage) { + history.push({ role: "system", content: systemMessage }); + } + return history; } - return history; - }); - - const [userInput, setUserInput] = useState(''); + ); + + const [userInput, setUserInput] = useState(""); const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); - const [currentAssistantMessage, setCurrentAssistantMessage] = useState(''); + const [currentAssistantMessage, setCurrentAssistantMessage] = useState(""); const [messages, setMessages] = useState([]); const { exit } = useApp(); @@ -51,7 +57,10 @@ const TUIChat: React.FC = ({ assistant, client, initialPrompt }) = // Add command output to messages if (commandResult.output) { - setMessages(prev => [...prev, { role: 'system', content: commandResult.output! }]); + setMessages((prev) => [ + ...prev, + { role: "system", content: commandResult.output! }, + ]); } if (commandResult.newInput) { @@ -62,31 +71,41 @@ const TUIChat: React.FC = ({ assistant, client, initialPrompt }) = } // Add user message to history and display - const newUserMessage: ChatCompletionMessageParam = { role: 'user', content: message }; - setChatHistory(prev => [...prev, newUserMessage]); - setMessages(prev => [...prev, { role: 'user', content: message }]); + const newUserMessage: ChatCompletionMessageParam = { + role: "user", + content: message, + }; + setChatHistory((prev) => [...prev, newUserMessage]); + setMessages((prev) => [...prev, { role: "user", content: message }]); // Start streaming response setIsWaitingForResponse(true); - setCurrentAssistantMessage(''); - + setCurrentAssistantMessage(""); + // Add placeholder for streaming message - setMessages(prev => [...prev, { role: 'assistant', content: '', isStreaming: true }]); + setMessages((prev) => [ + ...prev, + { role: "assistant", content: "", isStreaming: true }, + ]); try { const newHistory = [...chatHistory, newUserMessage]; - + // Create a custom stream handler that updates our UI const originalWrite = process.stdout.write; - let assistantResponse = ''; - - process.stdout.write = function(chunk: any, encoding?: any, callback?: any) { + let assistantResponse = ""; + + process.stdout.write = function ( + chunk: any, + encoding?: any, + callback?: any + ) { const text = chunk.toString(); assistantResponse += text; setCurrentAssistantMessage(assistantResponse); - + // Update the streaming message - setMessages(prev => { + setMessages((prev) => { const newMessages = [...prev]; const lastMessage = newMessages[newMessages.length - 1]; if (lastMessage.isStreaming) { @@ -94,22 +113,25 @@ const TUIChat: React.FC = ({ assistant, client, initialPrompt }) = } return newMessages; }); - + // Call original write for logging purposes return originalWrite.call(this, chunk, encoding, callback); }; await streamChatResponse(newHistory, assistant, client); - + // Restore original write process.stdout.write = originalWrite; - + // Finalize the assistant message - const finalAssistantMessage: ChatCompletionMessageParam = { role: 'assistant', content: assistantResponse }; - setChatHistory(prev => [...prev, finalAssistantMessage]); - + const finalAssistantMessage: ChatCompletionMessageParam = { + role: "assistant", + content: assistantResponse, + }; + setChatHistory((prev) => [...prev, finalAssistantMessage]); + // Update messages to remove streaming flag - setMessages(prev => { + setMessages((prev) => { const newMessages = [...prev]; const lastMessage = newMessages[newMessages.length - 1]; if (lastMessage.isStreaming) { @@ -117,52 +139,56 @@ const TUIChat: React.FC = ({ assistant, client, initialPrompt }) = } return newMessages; }); - } catch (error: any) { const errorMessage = `Error: ${error.message}`; - setMessages(prev => [...prev, { role: 'system', content: errorMessage }]); + setMessages((prev) => [ + ...prev, + { role: "system", content: errorMessage }, + ]); } finally { setIsWaitingForResponse(false); - setCurrentAssistantMessage(''); + setCurrentAssistantMessage(""); } }; useInput((input, key) => { - if (key.ctrl && input === 'c') { + if (key.ctrl && (input === "c" || input === "d")) { exit(); return; } - + if (key.return) { if (userInput.trim() && !isWaitingForResponse) { handleUserMessage(userInput.trim()); - setUserInput(''); + setUserInput(""); } return; } - + if (key.backspace) { - setUserInput(prev => prev.slice(0, -1)); + setUserInput((prev) => prev.slice(0, -1)); return; } - + if (!key.ctrl && !key.meta && input) { - setUserInput(prev => prev + input); + setUserInput((prev) => prev + input); } }); const renderMessage = (message: DisplayMessage, index: number) => { - const isUser = message.role === 'user'; - const isSystem = message.role === 'system'; - + const isUser = message.role === "user"; + const isSystem = message.role === "system"; + if (isSystem) { return ( - {message.content} + + {message.content} + ); } - + return ( @@ -180,14 +206,16 @@ const TUIChat: React.FC = ({ assistant, client, initialPrompt }) = {messages.map(renderMessage)} - + {/* Input area */} - You: + + You:{" "} + {userInput} {!isWaitingForResponse && ▋} - + {/* Status */} {isWaitingForResponse && ( @@ -198,4 +226,4 @@ const TUIChat: React.FC = ({ assistant, client, initialPrompt }) = ); }; -export default TUIChat; \ No newline at end of file +export default TUIChat; From 8c0fd5e87e7e8ce59b4b022669d4aba2ba1b8bcf Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:16:42 -0700 Subject: [PATCH 04/18] fix: tui no longer completely broken --- src/ui/TUIChat.tsx | 59 +++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 7ba547029..81c4a51c2 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -35,8 +35,8 @@ const TUIChat: React.FC = ({ const [userInput, setUserInput] = useState(""); const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); - const [currentAssistantMessage, setCurrentAssistantMessage] = useState(""); const [messages, setMessages] = useState([]); + const [inputMode, setInputMode] = useState(true); const { exit } = useApp(); // Handle initial prompt @@ -80,7 +80,7 @@ const TUIChat: React.FC = ({ // Start streaming response setIsWaitingForResponse(true); - setCurrentAssistantMessage(""); + setInputMode(false); // Add placeholder for streaming message setMessages((prev) => [ @@ -90,43 +90,20 @@ const TUIChat: React.FC = ({ try { const newHistory = [...chatHistory, newUserMessage]; - - // Create a custom stream handler that updates our UI - const originalWrite = process.stdout.write; let assistantResponse = ""; - process.stdout.write = function ( - chunk: any, - encoding?: any, - callback?: any - ) { - const text = chunk.toString(); - assistantResponse += text; - setCurrentAssistantMessage(assistantResponse); - - // Update the streaming message - setMessages((prev) => { - const newMessages = [...prev]; - const lastMessage = newMessages[newMessages.length - 1]; - if (lastMessage.isStreaming) { - lastMessage.content = assistantResponse; - } - return newMessages; - }); - - // Call original write for logging purposes - return originalWrite.call(this, chunk, encoding, callback); - }; - + // Mock the streaming for now - you'll need to modify streamChatResponse + // to accept a callback or use a different approach await streamChatResponse(newHistory, assistant, client); - // Restore original write - process.stdout.write = originalWrite; + // For now, we'll just wait and then get the response + // In a real implementation, you'd need to modify streamChatResponse + // to provide a way to capture the streamed content // Finalize the assistant message const finalAssistantMessage: ChatCompletionMessageParam = { role: "assistant", - content: assistantResponse, + content: assistantResponse || "Response received", // Fallback }; setChatHistory((prev) => [...prev, finalAssistantMessage]); @@ -136,6 +113,9 @@ const TUIChat: React.FC = ({ const lastMessage = newMessages[newMessages.length - 1]; if (lastMessage.isStreaming) { lastMessage.isStreaming = false; + if (!lastMessage.content) { + lastMessage.content = "Response received"; + } } return newMessages; }); @@ -147,7 +127,7 @@ const TUIChat: React.FC = ({ ]); } finally { setIsWaitingForResponse(false); - setCurrentAssistantMessage(""); + setInputMode(true); } }; @@ -157,6 +137,10 @@ const TUIChat: React.FC = ({ return; } + if (!inputMode) { + return; + } + if (key.return) { if (userInput.trim() && !isWaitingForResponse) { handleUserMessage(userInput.trim()); @@ -165,12 +149,13 @@ const TUIChat: React.FC = ({ return; } - if (key.backspace) { + if (key.backspace || key.delete) { setUserInput((prev) => prev.slice(0, -1)); return; } - if (!key.ctrl && !key.meta && input) { + // Only add printable characters + if (input && input.length === 1 && !key.ctrl && !key.meta) { setUserInput((prev) => prev + input); } }); @@ -203,7 +188,7 @@ const TUIChat: React.FC = ({ return ( {/* Chat history */} - + {messages.map(renderMessage)} @@ -213,12 +198,12 @@ const TUIChat: React.FC = ({ You:{" "} {userInput} - {!isWaitingForResponse && ▋} + {inputMode && !isWaitingForResponse && ▋} {/* Status */} {isWaitingForResponse && ( - + Waiting for response... )} From e7ab301dbe3b7e27bd6bb15992f3cf1a3f9694d7 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:43:15 -0700 Subject: [PATCH 05/18] feat: new TextBuffer class for improved keystroke handling --- package.json | 3 +- src/ui/TUIChat.tsx | 59 +++++++--- src/ui/TextBuffer.ts | 249 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+), 14 deletions(-) create mode 100644 src/ui/TextBuffer.ts diff --git a/package.json b/package.json index 516d8da07..d39fc1f71 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "build": "tsc", "start": "node dist/index.js", "repomix:sdk": "npx repomix node_modules/@continuedev/sdk --ignore **/api,cli-repomix.xml -o sdk-repomix.xml", - "repomix:cli": "npx repomix --ignore sdk-repomix.xml -o cli-repomix.xml" + "repomix:cli": "npx repomix --ignore sdk-repomix.xml -o cli-repomix.xml", + "lint": "tsc --noEmit" }, "author": "Continue Dev, Inc.", "license": "Apache-2.0", diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 81c4a51c2..814797d4e 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -4,6 +4,7 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { streamChatResponse } from "../streamChatResponse.js"; +import { TextBuffer } from "./TextBuffer.js"; interface TUIChatProps { assistant: ContinueClient["assistant"]; @@ -33,7 +34,8 @@ const TUIChat: React.FC = ({ } ); - const [userInput, setUserInput] = useState(""); + const [textBuffer] = useState(() => new TextBuffer()); + const [inputText, setInputText] = useState(""); const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); const [messages, setMessages] = useState([]); const [inputMode, setInputMode] = useState(true); @@ -142,21 +144,20 @@ const TUIChat: React.FC = ({ } if (key.return) { - if (userInput.trim() && !isWaitingForResponse) { - handleUserMessage(userInput.trim()); - setUserInput(""); + if (textBuffer.text.trim() && !isWaitingForResponse) { + handleUserMessage(textBuffer.text.trim()); + textBuffer.clear(); + setInputText(""); } return; } - if (key.backspace || key.delete) { - setUserInput((prev) => prev.slice(0, -1)); - return; - } + // Let TextBuffer handle the input + const handled = textBuffer.handleInput(input, key); - // Only add printable characters - if (input && input.length === 1 && !key.ctrl && !key.meta) { - setUserInput((prev) => prev + input); + // Update React state to trigger re-render + if (handled) { + setInputText(textBuffer.text); } }); @@ -197,8 +198,40 @@ const TUIChat: React.FC = ({ You:{" "} - {userInput} - {inputMode && !isWaitingForResponse && ▋} + {(() => { + const cursorPosition = textBuffer.cursor; + + if (inputText.length === 0) { + return ( + <> + {inputMode && !isWaitingForResponse && ( + ▋Type your message... + )} + {(!inputMode || isWaitingForResponse) && ( + Type your message... + )} + + ); + } + + if (inputMode && !isWaitingForResponse) { + // Show cursor at the correct position + const beforeCursor = inputText.slice(0, cursorPosition); + const atCursor = + inputText.slice(cursorPosition, cursorPosition + 1) || " "; + const afterCursor = inputText.slice(cursorPosition + 1); + + return ( + <> + {beforeCursor} + {atCursor} + {afterCursor} + + ); + } else { + return {inputText}; + } + })()} {/* Status */} diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts new file mode 100644 index 000000000..7d890eea5 --- /dev/null +++ b/src/ui/TextBuffer.ts @@ -0,0 +1,249 @@ +import { Key } from 'ink'; + +export class TextBuffer { + private _text: string = ''; + private _cursor: number = 0; + + constructor(initialText: string = '') { + this._text = initialText; + this._cursor = initialText.length; + } + + get text(): string { + return this._text; + } + + get cursor(): number { + return this._cursor; + } + + setText(text: string): void { + this._text = text; + this._cursor = Math.min(this._cursor, text.length); + } + + setCursor(position: number): void { + this._cursor = Math.max(0, Math.min(position, this._text.length)); + } + + insertText(text: string): void { + this._text = this._text.slice(0, this._cursor) + text + this._text.slice(this._cursor); + this._cursor += text.length; + } + + deleteCharAt(position: number): void { + if (position >= 0 && position < this._text.length) { + this._text = this._text.slice(0, position) + this._text.slice(position + 1); + if (this._cursor > position) { + this._cursor--; + } + } + } + + deleteBackward(): void { + if (this._cursor > 0) { + this.deleteCharAt(this._cursor - 1); + } + } + + deleteForward(): void { + if (this._cursor < this._text.length) { + this.deleteCharAt(this._cursor); + } + } + + private findWordBoundary(position: number, direction: 'left' | 'right'): number { + if (direction === 'left') { + // Find start of current word or previous word + let pos = Math.max(0, position - 1); + + // Skip whitespace + while (pos > 0 && /\s/.test(this._text[pos])) { + pos--; + } + + // Find word boundary + while (pos > 0 && !/\s/.test(this._text[pos - 1])) { + pos--; + } + + return pos; + } else { + // Find end of current word or next word + let pos = position; + + // Skip whitespace + while (pos < this._text.length && /\s/.test(this._text[pos])) { + pos++; + } + + // Find word boundary + while (pos < this._text.length && !/\s/.test(this._text[pos])) { + pos++; + } + + return pos; + } + } + + moveWordLeft(): void { + this._cursor = this.findWordBoundary(this._cursor, 'left'); + } + + moveWordRight(): void { + this._cursor = this.findWordBoundary(this._cursor, 'right'); + } + + deleteWordBackward(): void { + const wordStart = this.findWordBoundary(this._cursor, 'left'); + if (wordStart < this._cursor) { + this._text = this._text.slice(0, wordStart) + this._text.slice(this._cursor); + this._cursor = wordStart; + } + } + + deleteWordForward(): void { + const wordEnd = this.findWordBoundary(this._cursor, 'right'); + if (wordEnd > this._cursor) { + this._text = this._text.slice(0, this._cursor) + this._text.slice(wordEnd); + } + } + + moveToStart(): void { + this._cursor = 0; + } + + moveToEnd(): void { + this._cursor = this._text.length; + } + + moveLeft(): void { + this._cursor = Math.max(0, this._cursor - 1); + } + + moveRight(): void { + this._cursor = Math.min(this._text.length, this._cursor + 1); + } + + clear(): void { + this._text = ''; + this._cursor = 0; + } + + handleInput(input: string, key: Key): boolean { + // Detect option key combinations through escape sequences + const isOptionKey = input.startsWith('\u001b') && input.length > 1; + + // Handle option key combinations (detected through escape sequences) + if (isOptionKey) { + const sequence = input.slice(1); + + // Option + left arrow (usually \u001b[1;9D or \u001bb) + if (sequence === 'b' || sequence.includes('1;9D')) { + this.moveWordLeft(); + return true; + } + + // Option + right arrow (usually \u001b[1;9C or \u001bf) + if (sequence === 'f' || sequence.includes('1;9C')) { + this.moveWordRight(); + return true; + } + + // Option + backspace (usually \u001b\u0008 or \u001b\u007f) + if (sequence === '\u0008' || sequence === '\u007f') { + this.deleteWordBackward(); + return true; + } + + return true; // Consume other option sequences + } + + // Handle special key combinations based on input character + if (key.ctrl) { + switch (input) { + case 'a': + this.moveToStart(); + return true; + case 'e': + this.moveToEnd(); + return true; + case 'u': + // Delete from cursor to start of line + this._text = this._text.slice(this._cursor); + this._cursor = 0; + return true; + case 'k': + // Delete from cursor to end of line + this._text = this._text.slice(0, this._cursor); + return true; + case 'w': + this.deleteWordBackward(); + return true; + case 'd': + this.deleteWordForward(); + return true; + } + } + + // Handle meta key combinations (cmd on Mac) + if (key.meta) { + if (key.backspace) { + this.deleteWordBackward(); + return true; + } + if (key.delete) { + this.deleteWordForward(); + return true; + } + if (key.leftArrow) { + this.moveWordLeft(); + return true; + } + if (key.rightArrow) { + this.moveWordRight(); + return true; + } + } + + // Handle arrow keys + if (key.leftArrow && !key.meta) { + this.moveLeft(); + return true; + } + if (key.rightArrow && !key.meta) { + this.moveRight(); + return true; + } + + // Handle backspace/delete + if (key.backspace && !key.meta) { + this.deleteBackward(); + return true; + } + if (key.delete && !key.meta) { + this.deleteForward(); + return true; + } + + // Handle regular character input + if (input && input.length === 1 && !key.ctrl && !key.meta && !isOptionKey) { + this.insertText(input); + return true; + } + + return false; + } + + // Helper method to render text with cursor + renderWithCursor(placeholder?: string): { text: string; cursorPosition: number } { + if (this._text.length === 0 && placeholder) { + return { text: placeholder, cursorPosition: 0 }; + } + + return { + text: this._text, + cursorPosition: this._cursor + }; + } +} \ No newline at end of file From 566b439d8e9558e75fca8de3ca1fe59304aeeaf3 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:46:00 -0700 Subject: [PATCH 06/18] chore: format --- src/ui/TextBuffer.ts | 88 ++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts index 7d890eea5..c0f2c3171 100644 --- a/src/ui/TextBuffer.ts +++ b/src/ui/TextBuffer.ts @@ -1,10 +1,10 @@ -import { Key } from 'ink'; +import { Key } from "ink"; export class TextBuffer { - private _text: string = ''; + private _text: string = ""; private _cursor: number = 0; - constructor(initialText: string = '') { + constructor(initialText: string = "") { this._text = initialText; this._cursor = initialText.length; } @@ -27,13 +27,15 @@ export class TextBuffer { } insertText(text: string): void { - this._text = this._text.slice(0, this._cursor) + text + this._text.slice(this._cursor); + this._text = + this._text.slice(0, this._cursor) + text + this._text.slice(this._cursor); this._cursor += text.length; } deleteCharAt(position: number): void { if (position >= 0 && position < this._text.length) { - this._text = this._text.slice(0, position) + this._text.slice(position + 1); + this._text = + this._text.slice(0, position) + this._text.slice(position + 1); if (this._cursor > position) { this._cursor--; } @@ -52,60 +54,65 @@ export class TextBuffer { } } - private findWordBoundary(position: number, direction: 'left' | 'right'): number { - if (direction === 'left') { + private findWordBoundary( + position: number, + direction: "left" | "right" + ): number { + if (direction === "left") { // Find start of current word or previous word let pos = Math.max(0, position - 1); - + // Skip whitespace while (pos > 0 && /\s/.test(this._text[pos])) { pos--; } - + // Find word boundary while (pos > 0 && !/\s/.test(this._text[pos - 1])) { pos--; } - + return pos; } else { // Find end of current word or next word let pos = position; - + // Skip whitespace while (pos < this._text.length && /\s/.test(this._text[pos])) { pos++; } - + // Find word boundary while (pos < this._text.length && !/\s/.test(this._text[pos])) { pos++; } - + return pos; } } moveWordLeft(): void { - this._cursor = this.findWordBoundary(this._cursor, 'left'); + this._cursor = this.findWordBoundary(this._cursor, "left"); } moveWordRight(): void { - this._cursor = this.findWordBoundary(this._cursor, 'right'); + this._cursor = this.findWordBoundary(this._cursor, "right"); } deleteWordBackward(): void { - const wordStart = this.findWordBoundary(this._cursor, 'left'); + const wordStart = this.findWordBoundary(this._cursor, "left"); if (wordStart < this._cursor) { - this._text = this._text.slice(0, wordStart) + this._text.slice(this._cursor); + this._text = + this._text.slice(0, wordStart) + this._text.slice(this._cursor); this._cursor = wordStart; } } deleteWordForward(): void { - const wordEnd = this.findWordBoundary(this._cursor, 'right'); + const wordEnd = this.findWordBoundary(this._cursor, "right"); if (wordEnd > this._cursor) { - this._text = this._text.slice(0, this._cursor) + this._text.slice(wordEnd); + this._text = + this._text.slice(0, this._cursor) + this._text.slice(wordEnd); } } @@ -126,61 +133,61 @@ export class TextBuffer { } clear(): void { - this._text = ''; + this._text = ""; this._cursor = 0; } handleInput(input: string, key: Key): boolean { // Detect option key combinations through escape sequences - const isOptionKey = input.startsWith('\u001b') && input.length > 1; - + const isOptionKey = input.startsWith("\u001b") && input.length > 1; + // Handle option key combinations (detected through escape sequences) if (isOptionKey) { const sequence = input.slice(1); - + // Option + left arrow (usually \u001b[1;9D or \u001bb) - if (sequence === 'b' || sequence.includes('1;9D')) { + if (sequence === "b" || sequence.includes("1;9D")) { this.moveWordLeft(); return true; } - + // Option + right arrow (usually \u001b[1;9C or \u001bf) - if (sequence === 'f' || sequence.includes('1;9C')) { + if (sequence === "f" || sequence.includes("1;9C")) { this.moveWordRight(); return true; } - + // Option + backspace (usually \u001b\u0008 or \u001b\u007f) - if (sequence === '\u0008' || sequence === '\u007f') { + if (sequence === "\u0008" || sequence === "\u007f") { this.deleteWordBackward(); return true; } - + return true; // Consume other option sequences } // Handle special key combinations based on input character if (key.ctrl) { switch (input) { - case 'a': + case "a": this.moveToStart(); return true; - case 'e': + case "e": this.moveToEnd(); return true; - case 'u': + case "u": // Delete from cursor to start of line this._text = this._text.slice(this._cursor); this._cursor = 0; return true; - case 'k': + case "k": // Delete from cursor to end of line this._text = this._text.slice(0, this._cursor); return true; - case 'w': + case "w": this.deleteWordBackward(); return true; - case 'd': + case "d": this.deleteWordForward(); return true; } @@ -236,14 +243,17 @@ export class TextBuffer { } // Helper method to render text with cursor - renderWithCursor(placeholder?: string): { text: string; cursorPosition: number } { + renderWithCursor(placeholder?: string): { + text: string; + cursorPosition: number; + } { if (this._text.length === 0 && placeholder) { return { text: placeholder, cursorPosition: 0 }; } - + return { text: this._text, - cursorPosition: this._cursor + cursorPosition: this._cursor, }; } -} \ No newline at end of file +} From aa5606f65f3284c9ff4d0a02cb1e4611b5cd080c Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:47:23 -0700 Subject: [PATCH 07/18] fix: backspace on mac --- src/ui/TextBuffer.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts index c0f2c3171..f3ee20ece 100644 --- a/src/ui/TextBuffer.ts +++ b/src/ui/TextBuffer.ts @@ -200,7 +200,7 @@ export class TextBuffer { return true; } if (key.delete) { - this.deleteWordForward(); + this.deleteWordBackward(); return true; } if (key.leftArrow) { @@ -224,12 +224,13 @@ export class TextBuffer { } // Handle backspace/delete - if (key.backspace && !key.meta) { + // On Mac, backspace key registers as key.delete, so treat it as backward deletion + if (key.delete && !key.meta) { this.deleteBackward(); return true; } - if (key.delete && !key.meta) { - this.deleteForward(); + if (key.backspace && !key.meta) { + this.deleteBackward(); return true; } From 388eeeb37afa7625b954e4dd44cbcd7cf0ab22bb Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:54:26 -0700 Subject: [PATCH 08/18] fix: cursor position --- src/ui/TUIChat.tsx | 9 +++++---- src/ui/TextBuffer.ts | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 814797d4e..ae027e17c 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -36,6 +36,7 @@ const TUIChat: React.FC = ({ const [textBuffer] = useState(() => new TextBuffer()); const [inputText, setInputText] = useState(""); + const [cursorPosition, setCursorPosition] = useState(0); const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); const [messages, setMessages] = useState([]); const [inputMode, setInputMode] = useState(true); @@ -148,6 +149,7 @@ const TUIChat: React.FC = ({ handleUserMessage(textBuffer.text.trim()); textBuffer.clear(); setInputText(""); + setCursorPosition(0); } return; } @@ -158,6 +160,7 @@ const TUIChat: React.FC = ({ // Update React state to trigger re-render if (handled) { setInputText(textBuffer.text); + setCursorPosition(textBuffer.cursor); } }); @@ -199,7 +202,6 @@ const TUIChat: React.FC = ({ You:{" "} {(() => { - const cursorPosition = textBuffer.cursor; if (inputText.length === 0) { return ( @@ -217,14 +219,13 @@ const TUIChat: React.FC = ({ if (inputMode && !isWaitingForResponse) { // Show cursor at the correct position const beforeCursor = inputText.slice(0, cursorPosition); - const atCursor = - inputText.slice(cursorPosition, cursorPosition + 1) || " "; + const atCursor = inputText.slice(cursorPosition, cursorPosition + 1); const afterCursor = inputText.slice(cursorPosition + 1); return ( <> {beforeCursor} - {atCursor} + {atCursor || " "} {afterCursor} ); diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts index f3ee20ece..6d56574dd 100644 --- a/src/ui/TextBuffer.ts +++ b/src/ui/TextBuffer.ts @@ -145,14 +145,22 @@ export class TextBuffer { if (isOptionKey) { const sequence = input.slice(1); - // Option + left arrow (usually \u001b[1;9D or \u001bb) - if (sequence === "b" || sequence.includes("1;9D")) { + // Option + left arrow - various possible sequences + if (sequence === "b" || + sequence.includes("1;9D") || + sequence.includes("[1;3D") || + sequence.includes("[D") || + sequence.includes("OD")) { this.moveWordLeft(); return true; } - // Option + right arrow (usually \u001b[1;9C or \u001bf) - if (sequence === "f" || sequence.includes("1;9C")) { + // Option + right arrow - various possible sequences + if (sequence === "f" || + sequence.includes("1;9C") || + sequence.includes("[1;3C") || + sequence.includes("[C") || + sequence.includes("OC")) { this.moveWordRight(); return true; } From efa2c434d0a5942e9aaf5171c2d1f03c5df3ca51 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 14:57:43 -0700 Subject: [PATCH 09/18] fix: option + left/rght --- src/ui/TextBuffer.ts | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts index 6d56574dd..d24d6a5e5 100644 --- a/src/ui/TextBuffer.ts +++ b/src/ui/TextBuffer.ts @@ -145,26 +145,6 @@ export class TextBuffer { if (isOptionKey) { const sequence = input.slice(1); - // Option + left arrow - various possible sequences - if (sequence === "b" || - sequence.includes("1;9D") || - sequence.includes("[1;3D") || - sequence.includes("[D") || - sequence.includes("OD")) { - this.moveWordLeft(); - return true; - } - - // Option + right arrow - various possible sequences - if (sequence === "f" || - sequence.includes("1;9C") || - sequence.includes("[1;3C") || - sequence.includes("[C") || - sequence.includes("OC")) { - this.moveWordRight(); - return true; - } - // Option + backspace (usually \u001b\u0008 or \u001b\u007f) if (sequence === "\u0008" || sequence === "\u007f") { this.deleteWordBackward(); @@ -219,6 +199,16 @@ export class TextBuffer { this.moveWordRight(); return true; } + + // Handle option+left/right as characters (on Mac, option+arrow sends character codes) + if (input === "b") { + this.moveWordLeft(); + return true; + } + if (input === "f") { + this.moveWordRight(); + return true; + } } // Handle arrow keys From 65f10a1a4f2862bf1166d187e49fc732a503f9da Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 15:00:18 -0700 Subject: [PATCH 10/18] feat: paste --- src/ui/TextBuffer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts index d24d6a5e5..65cebac0f 100644 --- a/src/ui/TextBuffer.ts +++ b/src/ui/TextBuffer.ts @@ -232,8 +232,8 @@ export class TextBuffer { return true; } - // Handle regular character input - if (input && input.length === 1 && !key.ctrl && !key.meta && !isOptionKey) { + // Handle regular character input (including paste - multi-character input) + if (input && input.length >= 1 && !key.ctrl && !key.meta && !isOptionKey) { this.insertText(input); return true; } From fa30094e61dbb2b11f7940b875fc719d06ed3eec Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:15:49 -0700 Subject: [PATCH 11/18] fix: shift+enter for newline --- src/ui/TUIChat.tsx | 74 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index ae027e17c..5940f6074 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -144,7 +144,8 @@ const TUIChat: React.FC = ({ return; } - if (key.return) { + // Handle Enter key (regular enter for submit) + if (key.return && !key.shift) { if (textBuffer.text.trim() && !isWaitingForResponse) { handleUserMessage(textBuffer.text.trim()); textBuffer.clear(); @@ -154,6 +155,16 @@ const TUIChat: React.FC = ({ return; } + // Handle Shift+Enter (carriage return character) for new line + if (input === "\r" || input === "\\\r") { + const handled = textBuffer.handleInput("\n", key); + if (handled) { + setInputText(textBuffer.text); + setCursorPosition(textBuffer.cursor); + } + return; + } + // Let TextBuffer handle the input const handled = textBuffer.handleInput(input, key); @@ -202,7 +213,6 @@ const TUIChat: React.FC = ({ You:{" "} {(() => { - if (inputText.length === 0) { return ( <> @@ -217,20 +227,60 @@ const TUIChat: React.FC = ({ } if (inputMode && !isWaitingForResponse) { - // Show cursor at the correct position - const beforeCursor = inputText.slice(0, cursorPosition); - const atCursor = inputText.slice(cursorPosition, cursorPosition + 1); - const afterCursor = inputText.slice(cursorPosition + 1); + // Handle multi-line text with cursor + const lines = inputText.split("\n"); + let charCount = 0; + let cursorLine = 0; + let cursorCol = 0; + + // Find which line and column the cursor is on + for (let i = 0; i < lines.length; i++) { + if (cursorPosition <= charCount + lines[i].length) { + cursorLine = i; + cursorCol = cursorPosition - charCount; + break; + } + charCount += lines[i].length + 1; // +1 for the newline character + } + + // Handle cursor at the very end + if (cursorPosition >= inputText.length) { + cursorLine = lines.length - 1; + cursorCol = lines[cursorLine].length; + } return ( - <> - {beforeCursor} - {atCursor || " "} - {afterCursor} - + + {lines.map((line, lineIndex) => { + if (lineIndex === cursorLine) { + // Line with cursor + const beforeCursor = line.slice(0, cursorCol); + const atCursor = line.slice(cursorCol, cursorCol + 1); + const afterCursor = line.slice(cursorCol + 1); + + return ( + + {beforeCursor} + {atCursor || " "} + {afterCursor} + + ); + } else { + // Regular line + return {line}; + } + })} + ); } else { - return {inputText}; + // Not in input mode, just display the text + return ( + + {inputText.split("\n").map((line, index) => ( + {line} + ))} + + ); } })()} From 423dbdd457683260f66eda9024f35dee9c49d5db Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:17:35 -0700 Subject: [PATCH 12/18] fix: allow multiple consecutive new lines --- src/ui/TUIChat.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 5940f6074..6a3f9cbfb 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -266,8 +266,8 @@ const TUIChat: React.FC = ({ ); } else { - // Regular line - return {line}; + // Regular line - ensure empty lines still render + return {line || " "}; } })} @@ -277,7 +277,7 @@ const TUIChat: React.FC = ({ return ( {inputText.split("\n").map((line, index) => ( - {line} + {line || " "} ))} ); From a08e2176a70f5a216f6e03657e9f6522eade99b8 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:22:04 -0700 Subject: [PATCH 13/18] fix: round corners --- src/ui/TUIChat.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 6a3f9cbfb..d25c8b939 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -192,7 +192,7 @@ const TUIChat: React.FC = ({ return ( - {isUser ? "You:" : "Assistant:"} + ● {message.content} {message.isStreaming && ▋} @@ -207,10 +207,10 @@ const TUIChat: React.FC = ({ {messages.map(renderMessage)} - {/* Input area */} - + {/* Input area with rounded corners */} + - You:{" "} + ●{" "} {(() => { if (inputText.length === 0) { @@ -295,4 +295,4 @@ const TUIChat: React.FC = ({ ); }; -export default TUIChat; +export default TUIChat; \ No newline at end of file From 0c179681bcba741f5e8ba58467589fe321b1bec9 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:29:28 -0700 Subject: [PATCH 14/18] refactor: UserInput.tsx --- src/ui/TUIChat.tsx | 130 +++----------------------------------- src/ui/UserInput.tsx | 144 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 122 deletions(-) create mode 100644 src/ui/UserInput.tsx diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index d25c8b939..f505d747e 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -1,10 +1,10 @@ import { ContinueClient } from "@continuedev/sdk"; -import { Box, Text, useApp, useInput } from "ink"; +import { Box, Text, useApp } from "ink"; import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { streamChatResponse } from "../streamChatResponse.js"; -import { TextBuffer } from "./TextBuffer.js"; +import UserInput from "./UserInput.js"; interface TUIChatProps { assistant: ContinueClient["assistant"]; @@ -34,9 +34,6 @@ const TUIChat: React.FC = ({ } ); - const [textBuffer] = useState(() => new TextBuffer()); - const [inputText, setInputText] = useState(""); - const [cursorPosition, setCursorPosition] = useState(0); const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); const [messages, setMessages] = useState([]); const [inputMode, setInputMode] = useState(true); @@ -134,46 +131,6 @@ const TUIChat: React.FC = ({ } }; - useInput((input, key) => { - if (key.ctrl && (input === "c" || input === "d")) { - exit(); - return; - } - - if (!inputMode) { - return; - } - - // Handle Enter key (regular enter for submit) - if (key.return && !key.shift) { - if (textBuffer.text.trim() && !isWaitingForResponse) { - handleUserMessage(textBuffer.text.trim()); - textBuffer.clear(); - setInputText(""); - setCursorPosition(0); - } - return; - } - - // Handle Shift+Enter (carriage return character) for new line - if (input === "\r" || input === "\\\r") { - const handled = textBuffer.handleInput("\n", key); - if (handled) { - setInputText(textBuffer.text); - setCursorPosition(textBuffer.cursor); - } - return; - } - - // Let TextBuffer handle the input - const handled = textBuffer.handleInput(input, key); - - // Update React state to trigger re-render - if (handled) { - setInputText(textBuffer.text); - setCursorPosition(textBuffer.cursor); - } - }); const renderMessage = (message: DisplayMessage, index: number) => { const isUser = message.role === "user"; @@ -207,83 +164,12 @@ const TUIChat: React.FC = ({ {messages.map(renderMessage)} - {/* Input area with rounded corners */} - - - ●{" "} - - {(() => { - if (inputText.length === 0) { - return ( - <> - {inputMode && !isWaitingForResponse && ( - ▋Type your message... - )} - {(!inputMode || isWaitingForResponse) && ( - Type your message... - )} - - ); - } - - if (inputMode && !isWaitingForResponse) { - // Handle multi-line text with cursor - const lines = inputText.split("\n"); - let charCount = 0; - let cursorLine = 0; - let cursorCol = 0; - - // Find which line and column the cursor is on - for (let i = 0; i < lines.length; i++) { - if (cursorPosition <= charCount + lines[i].length) { - cursorLine = i; - cursorCol = cursorPosition - charCount; - break; - } - charCount += lines[i].length + 1; // +1 for the newline character - } - - // Handle cursor at the very end - if (cursorPosition >= inputText.length) { - cursorLine = lines.length - 1; - cursorCol = lines[cursorLine].length; - } - - return ( - - {lines.map((line, lineIndex) => { - if (lineIndex === cursorLine) { - // Line with cursor - const beforeCursor = line.slice(0, cursorCol); - const atCursor = line.slice(cursorCol, cursorCol + 1); - const afterCursor = line.slice(cursorCol + 1); - - return ( - - {beforeCursor} - {atCursor || " "} - {afterCursor} - - ); - } else { - // Regular line - ensure empty lines still render - return {line || " "}; - } - })} - - ); - } else { - // Not in input mode, just display the text - return ( - - {inputText.split("\n").map((line, index) => ( - {line || " "} - ))} - - ); - } - })()} - + {/* Input area */} + {/* Status */} {isWaitingForResponse && ( diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx new file mode 100644 index 000000000..00496634c --- /dev/null +++ b/src/ui/UserInput.tsx @@ -0,0 +1,144 @@ +import { Box, Text, useApp, useInput } from "ink"; +import React, { useState } from "react"; +import { TextBuffer } from "./TextBuffer.js"; + +interface UserInputProps { + onSubmit: (message: string) => void; + isWaitingForResponse: boolean; + inputMode: boolean; +} + +const UserInput: React.FC = ({ + onSubmit, + isWaitingForResponse, + inputMode, +}) => { + const [textBuffer] = useState(() => new TextBuffer()); + const [inputText, setInputText] = useState(""); + const [cursorPosition, setCursorPosition] = useState(0); + const { exit } = useApp(); + + useInput((input, key) => { + if (key.ctrl && (input === "c" || input === "d")) { + exit(); + return; + } + + if (!inputMode) { + return; + } + + // Handle Enter key (regular enter for submit) + if (key.return && !key.shift) { + if (textBuffer.text.trim() && !isWaitingForResponse) { + onSubmit(textBuffer.text.trim()); + textBuffer.clear(); + setInputText(""); + setCursorPosition(0); + } + return; + } + + // Handle Shift+Enter (carriage return character) for new line + if (input === "\r" || input === "\\\r") { + const handled = textBuffer.handleInput("\n", key); + if (handled) { + setInputText(textBuffer.text); + setCursorPosition(textBuffer.cursor); + } + return; + } + + // Let TextBuffer handle the input + const handled = textBuffer.handleInput(input, key); + + // Update React state to trigger re-render + if (handled) { + setInputText(textBuffer.text); + setCursorPosition(textBuffer.cursor); + } + }); + + const renderInputText = () => { + if (inputText.length === 0) { + return ( + <> + {inputMode && !isWaitingForResponse && ( + ▋Type your message... + )} + {(!inputMode || isWaitingForResponse) && ( + Type your message... + )} + + ); + } + + if (inputMode && !isWaitingForResponse) { + // Handle multi-line text with cursor + const lines = inputText.split("\n"); + let charCount = 0; + let cursorLine = 0; + let cursorCol = 0; + + // Find which line and column the cursor is on + for (let i = 0; i < lines.length; i++) { + if (cursorPosition <= charCount + lines[i].length) { + cursorLine = i; + cursorCol = cursorPosition - charCount; + break; + } + charCount += lines[i].length + 1; // +1 for the newline character + } + + // Handle cursor at the very end + if (cursorPosition >= inputText.length) { + cursorLine = lines.length - 1; + cursorCol = lines[cursorLine].length; + } + + return ( + + {lines.map((line, lineIndex) => { + if (lineIndex === cursorLine) { + // Line with cursor + const beforeCursor = line.slice(0, cursorCol); + const atCursor = line.slice(cursorCol, cursorCol + 1); + const afterCursor = line.slice(cursorCol + 1); + + return ( + + {beforeCursor} + {atCursor || " "} + {afterCursor} + + ); + } else { + // Regular line - ensure empty lines still render + return {line || " "}; + } + })} + + ); + } else { + // Not in input mode, just display the text + return ( + + {inputText.split("\n").map((line, index) => ( + {line || " "} + ))} + + ); + } + }; + + return ( + + + ●{" "} + + {renderInputText()} + + ); +}; + +export default UserInput; \ No newline at end of file From c8945adb85c99379039afa02ac4d63f114a6de6b Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:34:58 -0700 Subject: [PATCH 15/18] fix: stream above input box --- src/streamChatResponse.ts | 54 +++++++++++++++++++------- src/ui/TUIChat.tsx | 79 ++++++++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 40 deletions(-) diff --git a/src/streamChatResponse.ts b/src/streamChatResponse.ts index 4755404c7..ad1b73b90 100644 --- a/src/streamChatResponse.ts +++ b/src/streamChatResponse.ts @@ -50,11 +50,19 @@ export function getAllTools() { type TODO = any; +export interface StreamCallbacks { + onContent?: (content: string) => void; + onToolStart?: (toolName: string) => void; + onToolResult?: (result: string) => void; + onToolError?: (error: string) => void; +} + // Define a function to handle streaming responses with tool calling export async function streamChatResponse( chatHistory: ChatCompletionMessageParam[], assistant: ContinueClient["assistant"], - client: ContinueClient["client"] + client: ContinueClient["client"], + callbacks?: StreamCallbacks ) { // Prepare tools for the API call const toolsForRequest = getAllTools(); @@ -94,7 +102,11 @@ export async function streamChatResponse( // Handle regular content if (chunk.choices[0].delta.content) { const content = chunk.choices[0].delta.content; - process.stdout.write(chalk.white(content)); + if (callbacks?.onContent) { + callbacks.onContent(content); + } else { + process.stdout.write(chalk.white(content)); + } aiResponse += content; } @@ -121,11 +133,15 @@ export async function streamChatResponse( if (toolCall) { if (!toolCall.name) { toolCall.name = toolCallDelta.function.name; - process.stdout.write( - `\n${chalk.yellow("[Using tool:")} ${chalk.yellow.bold( - toolCall.name - )}${chalk.yellow("]")}` - ); + if (callbacks?.onToolStart) { + callbacks.onToolStart(toolCall.name); + } else { + process.stdout.write( + `\n${chalk.yellow("[Using tool:")} ${chalk.yellow.bold( + toolCall.name + )}${chalk.yellow("]")}` + ); + } } } } @@ -152,7 +168,9 @@ export async function streamChatResponse( } } - console.info(); // Add a newline after the response + if (!callbacks?.onContent) { + console.info(); // Add a newline after the response + } // Add the assistant's response to chat history if there's content or tool calls if (currentToolCalls.length > 0) { @@ -193,7 +211,11 @@ export async function streamChatResponse( content: toolResult, }); - console.info(chalk.green(toolResult) + "\n"); + if (callbacks?.onToolResult) { + callbacks.onToolResult(toolResult); + } else { + console.info(chalk.green(toolResult) + "\n"); + } } catch (error) { const errorMessage = `Error executing tool ${toolCall.name}: ${ error instanceof Error ? error.message : String(error) @@ -203,11 +225,15 @@ export async function streamChatResponse( tool_call_id: toolCall.id, content: errorMessage, }); - console.info( - `${chalk.red("[Tool error:")} ${chalk.red(errorMessage)}${chalk.red( - ")" - )}` - ); + if (callbacks?.onToolError) { + callbacks.onToolError(errorMessage); + } else { + console.info( + `${chalk.red("[Tool error:")} ${chalk.red(errorMessage)}${chalk.red( + ")" + )}` + ); + } } } diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index f505d747e..145da891b 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -3,7 +3,7 @@ import { Box, Text, useApp } from "ink"; import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; -import { streamChatResponse } from "../streamChatResponse.js"; +import { streamChatResponse, StreamCallbacks } from "../streamChatResponse.js"; import UserInput from "./UserInput.js"; interface TUIChatProps { @@ -92,18 +92,45 @@ const TUIChat: React.FC = ({ const newHistory = [...chatHistory, newUserMessage]; let assistantResponse = ""; - // Mock the streaming for now - you'll need to modify streamChatResponse - // to accept a callback or use a different approach - await streamChatResponse(newHistory, assistant, client); + // Create callbacks to handle streaming updates + const streamCallbacks: StreamCallbacks = { + onContent: (content: string) => { + assistantResponse += content; + setMessages((prev) => { + const newMessages = [...prev]; + const lastMessage = newMessages[newMessages.length - 1]; + if (lastMessage.isStreaming) { + lastMessage.content += content; + } + return newMessages; + }); + }, + onToolStart: (toolName: string) => { + setMessages((prev) => [ + ...prev, + { role: "system", content: `[Using tool: ${toolName}]` }, + ]); + }, + onToolResult: (result: string) => { + setMessages((prev) => [ + ...prev, + { role: "system", content: result }, + ]); + }, + onToolError: (error: string) => { + setMessages((prev) => [ + ...prev, + { role: "system", content: `[Tool error: ${error}]` }, + ]); + }, + }; - // For now, we'll just wait and then get the response - // In a real implementation, you'd need to modify streamChatResponse - // to provide a way to capture the streamed content + await streamChatResponse(newHistory, assistant, client, streamCallbacks); // Finalize the assistant message const finalAssistantMessage: ChatCompletionMessageParam = { role: "assistant", - content: assistantResponse || "Response received", // Fallback + content: assistantResponse, }; setChatHistory((prev) => [...prev, finalAssistantMessage]); @@ -113,9 +140,6 @@ const TUIChat: React.FC = ({ const lastMessage = newMessages[newMessages.length - 1]; if (lastMessage.isStreaming) { lastMessage.isStreaming = false; - if (!lastMessage.content) { - lastMessage.content = "Response received"; - } } return newMessages; }); @@ -159,24 +183,27 @@ const TUIChat: React.FC = ({ return ( - {/* Chat history */} - + {/* Chat history - takes up all available space above input */} + {messages.map(renderMessage)} - {/* Input area */} - - - {/* Status */} - {isWaitingForResponse && ( - - Waiting for response... - - )} + {/* Fixed bottom section */} + + {/* Status */} + {isWaitingForResponse && ( + + Waiting for response... + + )} + + {/* Input area - always at bottom */} + + ); }; From 454df1554500a530645ef5e7a6a80fea6a27f207 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:36:51 -0700 Subject: [PATCH 16/18] fix: adjust waiting message --- src/ui/TUIChat.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 145da891b..550cd7c1f 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -3,7 +3,7 @@ import { Box, Text, useApp } from "ink"; import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; -import { streamChatResponse, StreamCallbacks } from "../streamChatResponse.js"; +import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; import UserInput from "./UserInput.js"; interface TUIChatProps { @@ -112,10 +112,7 @@ const TUIChat: React.FC = ({ ]); }, onToolResult: (result: string) => { - setMessages((prev) => [ - ...prev, - { role: "system", content: result }, - ]); + setMessages((prev) => [...prev, { role: "system", content: result }]); }, onToolError: (error: string) => { setMessages((prev) => [ @@ -155,7 +152,6 @@ const TUIChat: React.FC = ({ } }; - const renderMessage = (message: DisplayMessage, index: number) => { const isUser = message.role === "user"; const isSystem = message.role === "system"; @@ -193,10 +189,10 @@ const TUIChat: React.FC = ({ {/* Status */} {isWaitingForResponse && ( - Waiting for response... + esc to interrupt )} - + {/* Input area - always at bottom */} = ({ ); }; -export default TUIChat; \ No newline at end of file +export default TUIChat; From 9b7cea382906a16db4d71cb21c09df443ddfa634 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:42:16 -0700 Subject: [PATCH 17/18] chore: AGENTS.md --- AGENTS.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..f448f25df --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,67 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Development Commands + +- **Build**: `npm run build` - Compiles TypeScript to JavaScript in dist/ +- **Test**: `npm test` - Runs Jest tests with ESM support +- **Type Check**: `npm run lint` - Runs TypeScript compiler without emitting files for type checking +- **Start**: `npm start` - Runs the built CLI from dist/index.js +- **Development**: After building, test locally with `node dist/index.js` + +## Architecture Overview + +This is a CLI tool for Continue Dev that provides an interactive AI-assisted development experience. The architecture consists of: + +### Core Components + +1. **Entry Point** (`src/index.ts`): Main CLI logic with two modes: + - **Headless mode**: Non-interactive mode for automation/CI + - **TUI mode**: Terminal User Interface using Ink/React + - **Standard mode**: Traditional readline-based chat interface + +2. **Authentication** (`src/auth/`): WorkOS-based authentication system + - `ensureAuth.ts`: Handles authentication flow + - `workos.ts`: WorkOS configuration and token management + +3. **Continue SDK Integration** (`src/continueSDK.ts`): Initializes the Continue SDK client with: + - API key authentication + - Assistant configuration (slug-based) + - Organization support + +4. **Terminal UI** (`src/ui/`): React/Ink-based TUI components + - `TUIChat.tsx`: Main chat interface component + - `UserInput.tsx`: Input handling with multi-line support + - `TextBuffer.ts`: Text display utilities + +5. **Tools System** (`src/tools/`): Built-in development tools including: + - File operations (read, write, list) + - Code search functionality + - Terminal command execution + - Diff viewing + - Exit tool (headless mode only) + +6. **MCP Integration** (`src/mcp.ts`): Model Context Protocol service for extended tool capabilities + +### Key Features + +- **Streaming Responses**: Real-time AI response streaming (`streamChatResponse.ts`) +- **Slash Commands**: Built-in commands like `/help`, `/exit` (`slashCommands.ts`) +- **Multi-mode Operation**: Supports TUI, headless, and standard chat modes +- **Tool Integration**: Extensible tool system for development tasks + +### Testing Setup + +- Uses Jest with TypeScript and ESM support +- Configuration in `jest.config.mjs` +- Tests should be written with `.test.ts` extension +- No existing test files found - tests should be added when writing new functionality + +### Build System + +- TypeScript compilation with declaration files +- ESNext target with NodeNext module resolution +- Outputs to `dist/` directory +- Source maps and inline sources enabled +- JSX support for React components \ No newline at end of file From e73098b82ed5ea73f6d8d33eab24fdf6c67bb8ec Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:45:23 -0700 Subject: [PATCH 18/18] feat: TUI mode as default --- README.md | 6 - package-lock.json | 500 ++++++++++++++++++++++++++++++++++++++++++++- package.json | 4 +- src/args.ts | 6 - src/index.ts | 10 +- src/tools/index.ts | 2 +- 6 files changed, 507 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index df8eb7a0e..65d22f1d4 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,6 @@ npm install @continuedev/cli -g continue-cli ``` -### Terminal User Interface Mode - -```bash -continue-cli --tui -``` - ### With Custom Assistant ```bash diff --git a/package-lock.json b/package-lock.json index 154705eb7..6e8aab54f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,8 @@ "cross-env": "^7.0.3", "jest": "^29.7.0", "ts-jest": "^29.2.3", - "ts-node": "^10.9.2" + "ts-node": "^10.9.2", + "tsx": "^4.20.3" } }, "node_modules/@alcalzone/ansi-tokenize": { @@ -803,6 +804,422 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.6.tgz", + "integrity": "sha512-ShbM/3XxwuxjFiuVBHA+d3j5dyac0aEVVq1oluIDf71hUw0aRF59dV/efUsIwFnR6m8JNM2FjZOzmaZ8yG61kw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.6.tgz", + "integrity": "sha512-S8ToEOVfg++AU/bHwdksHNnyLyVM+eMVAOf6yRKFitnwnbwwPNqKr3srzFRe7nzV69RQKb5DgchIX5pt3L53xg==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.6.tgz", + "integrity": "sha512-hd5zdUarsK6strW+3Wxi5qWws+rJhCCbMiC9QZyzoxfk5uHRIE8T287giQxzVpEvCwuJ9Qjg6bEjcRJcgfLqoA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.6.tgz", + "integrity": "sha512-0Z7KpHSr3VBIO9A/1wcT3NTy7EB4oNC4upJ5ye3R7taCc2GUdeynSLArnon5G8scPwaU866d3H4BCrE5xLW25A==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.6.tgz", + "integrity": "sha512-FFCssz3XBavjxcFxKsGy2DYK5VSvJqa6y5HXljKzhRZ87LvEi13brPrf/wdyl/BbpbMKJNOr1Sd0jtW4Ge1pAA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.6.tgz", + "integrity": "sha512-GfXs5kry/TkGM2vKqK2oyiLFygJRqKVhawu3+DOCk7OxLy/6jYkWXhlHwOoTb0WqGnWGAS7sooxbZowy+pK9Yg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.6.tgz", + "integrity": "sha512-aoLF2c3OvDn2XDTRvn8hN6DRzVVpDlj2B/F66clWd/FHLiHaG3aVZjxQX2DYphA5y/evbdGvC6Us13tvyt4pWg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.6.tgz", + "integrity": "sha512-2SkqTjTSo2dYi/jzFbU9Plt1vk0+nNg8YC8rOXXea+iA3hfNJWebKYPs3xnOUf9+ZWhKAaxnQNUf2X9LOpeiMQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.6.tgz", + "integrity": "sha512-SZHQlzvqv4Du5PrKE2faN0qlbsaW/3QQfUUc6yO2EjFcA83xnwm91UbEEVx4ApZ9Z5oG8Bxz4qPE+HFwtVcfyw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.6.tgz", + "integrity": "sha512-b967hU0gqKd9Drsh/UuAm21Khpoh6mPBSgz8mKRq4P5mVK8bpA+hQzmm/ZwGVULSNBzKdZPQBRT3+WuVavcWsQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.6.tgz", + "integrity": "sha512-aHWdQ2AAltRkLPOsKdi3xv0mZ8fUGPdlKEjIEhxCPm5yKEThcUjHpWB1idN74lfXGnZ5SULQSgtr5Qos5B0bPw==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.6.tgz", + "integrity": "sha512-VgKCsHdXRSQ7E1+QXGdRPlQ/e08bN6WMQb27/TMfV+vPjjTImuT9PmLXupRlC90S1JeNNW5lzkAEO/McKeJ2yg==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.6.tgz", + "integrity": "sha512-WViNlpivRKT9/py3kCmkHnn44GkGXVdXfdc4drNmRl15zVQ2+D2uFwdlGh6IuK5AAnGTo2qPB1Djppj+t78rzw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.6.tgz", + "integrity": "sha512-wyYKZ9NTdmAMb5730I38lBqVu6cKl4ZfYXIs31Baf8aoOtB4xSGi3THmDYt4BTFHk7/EcVixkOV2uZfwU3Q2Jw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.6.tgz", + "integrity": "sha512-KZh7bAGGcrinEj4qzilJ4hqTY3Dg2U82c8bv+e1xqNqZCrCyc+TL9AUEn5WGKDzm3CfC5RODE/qc96OcbIe33w==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.6.tgz", + "integrity": "sha512-9N1LsTwAuE9oj6lHMyyAM+ucxGiVnEqUdp4v7IaMmrwb06ZTEVCIs3oPPplVsnjPfyjmxwHxHMF8b6vzUVAUGw==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.6.tgz", + "integrity": "sha512-A6bJB41b4lKFWRKNrWoP2LHsjVzNiaurf7wyj/XtFNTsnPuxwEBWHLty+ZE0dWBKuSK1fvKgrKaNjBS7qbFKig==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.6.tgz", + "integrity": "sha512-IjA+DcwoVpjEvyxZddDqBY+uJ2Snc6duLpjmkXm/v4xuS3H+3FkLZlDm9ZsAbF9rsfP3zeA0/ArNDORZgrxR/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.6.tgz", + "integrity": "sha512-dUXuZr5WenIDlMHdMkvDc1FAu4xdWixTCRgP7RQLBOkkGgwuuzaGSYcOpW4jFxzpzL1ejb8yF620UxAqnBrR9g==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.6.tgz", + "integrity": "sha512-l8ZCvXP0tbTJ3iaqdNf3pjaOSd5ex/e6/omLIQCVBLmHTlfXW3zAxQ4fnDmPLOB1x9xrcSi/xtCWFwCZRIaEwg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.6.tgz", + "integrity": "sha512-hKrmDa0aOFOr71KQ/19JC7az1P0GWtCN1t2ahYAf4O007DHZt/dW8ym5+CUdJhQ/qkZmI1HAF8KkJbEFtCL7gw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.6.tgz", + "integrity": "sha512-+SqBcAWoB1fYKmpWoQP4pGtx+pUUC//RNYhFdbcSA16617cchuryuhOCRpPsjCblKukAckWsV+aQ3UKT/RMPcA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.6.tgz", + "integrity": "sha512-dyCGxv1/Br7MiSC42qinGL8KkG4kX0pEsdb0+TKhmJZgCUDBGmyo1/ArCjNGiOLiIAgdbWgmWgib4HoCi5t7kA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.6.tgz", + "integrity": "sha512-42QOgcZeZOvXfsCBJF5Afw73t4veOId//XD3i+/9gSkhSV6Gk3VPlWncctI+JcOyERv85FUo7RxuxGy+z8A43Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.6.tgz", + "integrity": "sha512-4AWhgXmDuYN7rJI6ORB+uU9DHLq/erBbuMoAuB4VWJTu5KtCgcKYPynF0YI1VkBNuEfjNlLrFr9KZPJzrtLkrQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.6.tgz", + "integrity": "sha512-NgJPHHbEpLQgDH2MjQu90pzW/5vvXIZ7KOnPyNBm92A6WgZ/7b6fJyUBjoumLqeOQQGqY2QjQxRo97ah4Sj0cA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -3110,6 +3527,47 @@ "resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.39.7.tgz", "integrity": "sha512-ek/wWryKouBrZIjkwW2BFf91CWOIMvoy2AE5YYgUrfWsJQM2Su1LoLtrw8uusEpN9RfqLlV/0FVNjT0WMv8Bxw==" }, + "node_modules/esbuild": { + "version": "0.25.6", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.6.tgz", + "integrity": "sha512-GVuzuUwtdsghE3ocJ9Bs8PNoF13HNQ5TXbEi2AhvVb8xU1Iwt9Fos9FEamfoee+u/TOsn7GUWc04lz46n2bbTg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.6", + "@esbuild/android-arm": "0.25.6", + "@esbuild/android-arm64": "0.25.6", + "@esbuild/android-x64": "0.25.6", + "@esbuild/darwin-arm64": "0.25.6", + "@esbuild/darwin-x64": "0.25.6", + "@esbuild/freebsd-arm64": "0.25.6", + "@esbuild/freebsd-x64": "0.25.6", + "@esbuild/linux-arm": "0.25.6", + "@esbuild/linux-arm64": "0.25.6", + "@esbuild/linux-ia32": "0.25.6", + "@esbuild/linux-loong64": "0.25.6", + "@esbuild/linux-mips64el": "0.25.6", + "@esbuild/linux-ppc64": "0.25.6", + "@esbuild/linux-riscv64": "0.25.6", + "@esbuild/linux-s390x": "0.25.6", + "@esbuild/linux-x64": "0.25.6", + "@esbuild/netbsd-arm64": "0.25.6", + "@esbuild/netbsd-x64": "0.25.6", + "@esbuild/openbsd-arm64": "0.25.6", + "@esbuild/openbsd-x64": "0.25.6", + "@esbuild/openharmony-arm64": "0.25.6", + "@esbuild/sunos-x64": "0.25.6", + "@esbuild/win32-arm64": "0.25.6", + "@esbuild/win32-ia32": "0.25.6", + "@esbuild/win32-x64": "0.25.6" + } + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -3648,6 +4106,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/get-tsconfig": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.1.tgz", + "integrity": "sha512-auHyJ4AgMz7vgS8Hp3N6HXSmlMdUyhSUrfBF16w153rxtLIEOE+HGqaBppczZvnHLqQJfiHotCYpNhl0lUROFQ==", + "dev": true, + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -6391,6 +6861,15 @@ "node": ">=8" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/resolve.exports": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.3.tgz", @@ -7023,6 +7502,25 @@ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, + "node_modules/tsx": { + "version": "4.20.3", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.20.3.tgz", + "integrity": "sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==", + "dev": true, + "dependencies": { + "esbuild": "~0.25.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", diff --git a/package.json b/package.json index d39fc1f71..167328b1c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", "build": "tsc", "start": "node dist/index.js", + "dev": "tsx src/index.ts", "repomix:sdk": "npx repomix node_modules/@continuedev/sdk --ignore **/api,cli-repomix.xml -o sdk-repomix.xml", "repomix:cli": "npx repomix --ignore sdk-repomix.xml -o cli-repomix.xml", "lint": "tsc --noEmit" @@ -42,6 +43,7 @@ "cross-env": "^7.0.3", "jest": "^29.7.0", "ts-jest": "^29.2.3", - "ts-node": "^10.9.2" + "ts-node": "^10.9.2", + "tsx": "^4.20.3" } } diff --git a/src/args.ts b/src/args.ts index bc17b7027..ffac63648 100644 --- a/src/args.ts +++ b/src/args.ts @@ -2,7 +2,6 @@ export interface CommandLineArgs { isHeadless: boolean; configPath: string; prompt?: string; // Optional prompt argument - useTUI: boolean; // New flag for TUI mode } /** @@ -16,7 +15,6 @@ export function parseArgs(): CommandLineArgs { const result: CommandLineArgs = { isHeadless: false, configPath: "nate/default-assistant", - useTUI: false, }; // Parse flags @@ -24,10 +22,6 @@ export function parseArgs(): CommandLineArgs { result.isHeadless = true; } - if (args.includes("--tui")) { - result.useTUI = true; - } - // Get config path from --config flag const configIndex = args.indexOf("--config"); if (configIndex !== -1 && configIndex + 1 < args.length) { diff --git a/src/index.ts b/src/index.ts index 60bbfd72a..f74dff493 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,16 +81,14 @@ async function chat() { throw error; } - // If TUI mode is requested, start the TUI chat with the initialized services - if (args.useTUI) { + // If not in headless mode, start the TUI chat (default) + if (!args.isHeadless) { await startTUIChat(assistant, client, mcpService, args.prompt); return; } - // Only show intro message if not in headless mode - if (!args.isHeadless) { - introMessage(assistant, mcpService); - } + // Show intro message for headless mode + introMessage(assistant, mcpService); // Rules const chatHistory: ChatCompletionMessageParam[] = []; diff --git a/src/tools/index.ts b/src/tools/index.ts index 9dfc3d527..3ee6972c2 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -9,7 +9,7 @@ import { Tool, ToolParameters } from "./types.js"; import { viewDiffTool } from "./viewDiff.js"; import { writeFileTool } from "./writeFile.js"; -export { Tool } from "./types.js"; +export { Tool, ToolParameters }; export const BUILTIN_TOOLS: Tool[] = [ readFileTool,