From c5712cbaccfc1bd7ad62a6b9444386f663b4546f Mon Sep 17 00:00:00 2001 From: Ivan Kratunkov Date: Fri, 6 Dec 2024 01:30:39 +0200 Subject: [PATCH] Initial commit: Windsurf Cascade Step Tracker Extension --- .gitignore | 25 ++++ LICENSE | 21 +++ README.md | 162 +++++++++++++++++++++ package-lock.json | 48 +++++++ package.json | 81 +++++++++++ resources/step-icon.svg | 10 ++ src/README.md | 0 src/extension.ts | 289 +++++++++++++++++++++++++++++++++++++ src/webview-templates.ts | 298 +++++++++++++++++++++++++++++++++++++++ tsconfig.json | 12 ++ 10 files changed, 946 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 resources/step-icon.svg create mode 100644 src/README.md create mode 100644 src/extension.ts create mode 100644 src/webview-templates.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dcb40f --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Dependencies +node_modules/ + +# Build outputs +out/ +dist/ +*.vsix + +# Logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor directories and files +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# OS specific files +.DS_Store +Thumbs.db diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4b000ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Windsurf AI + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfa96d7 --- /dev/null +++ b/README.md @@ -0,0 +1,162 @@ +# Windsurf Cascade Monthly Step Tracker + +A Windsurf IDE extension that helps you track and manage your Windsurf AI Cascade steps across different projects. Keep track of your monthly step usage and ensure you stay within your limits. + +## Features + +- 📊 Track total steps used across all projects +- 🎯 Monitor monthly step limits +- 📝 Project-specific step tracking +- 🔄 Reset count functionality +- 📅 Automatic monthly usage tracking +- 💾 Persistent storage of step data +- 🖥️ Convenient sidebar view + +## Installation + +1. Download the `.vsix` file from the releases page +2. Open VS Code +3. Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (Mac) +4. Type "Install from VSIX" and select it +5. Navigate to the downloaded `.vsix` file and install + +## Usage + +### Accessing the Step Tracker + +1. Look for the Step Tracker icon in the VS Code activity bar (side bar) +2. Click it to open the Step Tracker panel + +### Adding Steps + +1. The current project name will be automatically detected from your workspace +2. Enter the number of steps in the input field +3. Click "Add Steps" to record them + +### Viewing Statistics + +- Total steps used this month +- Monthly step limit +- Per-project step usage +- Last update timestamp + +### Resetting Count + +- Use the "Reset Count" button to manually reset your step count +- Counts automatically reset at the beginning of each month + +### Managing Projects + +- Steps are tracked per project +- Project information is automatically detected from your workspace +- Step history is maintained for each project separately + +### Configuring Monthly Step Limit + +You can change your monthly step limit in two ways: + +1. **Through Windsurf Settings** + - Open Windsurf Settings + - Search for "windsurf-step-tracker" + - Look for the "Monthly Limit" setting + - Enter your desired step limit (default is 1000) + +2. **Directly in step-tracker.json** + - Navigate to `~/.windsurf/step-tracker.json` + - Find the `monthly_limit` field + - Update the value to your desired limit + - Save the file + +### Tracking Steps with Cascade AI + +Important: You need to explicitly ask Cascade to track steps - it does not happen automatically! + +The step tracking data is stored in: +``` +~/.windsurf/step-tracker.json +``` + +Here's how to track your steps: + +1. **Request Step Tracking** + - At the beginning of your conversation, tell Cascade: "Please track steps for this conversation" + - Or at any point during/after the conversation: "Please add X steps to my tracker" + - Make sure to request tracking for each conversation where you want to count steps + +2. **View Current Stats** + - Check the Step Tracker panel in the sidebar + - Look directly at the `step-tracker.json` file in your home directory + - Ask Cascade: "How many steps have I used so far?" + +3. **Best Practices** + - Always request step tracking at the start of important conversations + - Monitor your usage regularly through the Step Tracker panel + - Review the `step-tracker.json` file if you need detailed history + - Keep track of your monthly limits to avoid interruptions + +Remember: If you don't explicitly ask Cascade to track steps, they won't be recorded in your step count! + +## Data Storage + +The extension stores all step tracking data in the `.windsurf` directory in your home folder. The data persists between Windsurf sessions and is shared across different Windsurf windows. + +## Requirements + +- Windsurf IDE +- Active Windsurf AI Cascade subscription + +## Contributing + +Feel free to submit issues and enhancement requests through the GitHub repository. + +## License + +[MIT License](LICENSE) + +## Release Notes + +### 0.1.0 + +Initial release of Windsurf Cascade Monthly Step Tracker: +- Basic step tracking functionality +- Project-specific tracking +- Monthly limits +- Persistent storage +- User-friendly interface + +## Building from Source + +If you want to build the extension from source: + +1. **Clone the Repository** + ```bash + git clone https://github.com/SuBL1MMe/windsurf-cascade-step-tracker.git + cd windsurf-cascade-step-tracker + ``` + +2. **Install Dependencies** + ```bash + npm install + npm install -g @vscode/vsce # Install vsce globally if you haven't already + ``` + +3. **Compile TypeScript** + ```bash + npm run compile + # or for development with watch mode: + npm run watch + ``` + +4. **Package the Extension** + ```bash + vsce package + ``` + This will create a `.vsix` file in the root directory. + +5. **Install the Extension** + - Open Windsurf IDE + - Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (Mac) + - Type "Install from VSIX" and select it + - Navigate to the generated `.vsix` file and install + +Note: Make sure you have Node.js and npm installed on your system before starting. diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..7281b7f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,48 @@ +{ + "name": "windsurf-step-tracker", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "windsurf-step-tracker", + "version": "0.1.0", + "devDependencies": { + "@types/node": "^14.17.0", + "@types/vscode": "^1.60.0", + "typescript": "^4.3.5" + }, + "engines": { + "vscode": "^1.60.0" + } + }, + "node_modules/@types/node": { + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/vscode": { + "version": "1.95.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.95.0.tgz", + "integrity": "sha512-0LBD8TEiNbet3NvWsmn59zLzOFu/txSlGxnv5yAFHCrhG9WvAnR3IvfHzMOs2aeWqgvNjq9pO99IUw8d3n+unw==", + "dev": true, + "license": "MIT" + }, + "node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..8d64f8e --- /dev/null +++ b/package.json @@ -0,0 +1,81 @@ +{ + "name": "windsurf-step-tracker", + "displayName": "Windsurf Cascade Monthly Step Tracker", + "description": "Track Windsurf AI Cascade steps across projects", + "version": "0.1.0", + "publisher": "SuBL1MMe", + "repository": { + "type": "git", + "url": "https://github.com/SuBL1MMe/windsurf-cascade-step-tracker.git" + }, + "license": "MIT", + "engines": { + "vscode": "^1.60.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "onView:stepTrackerView", + "onCommand:windsurf-step-tracker.showSteps", + "onCommand:windsurf-step-tracker.addSteps", + "onCommand:windsurf-step-tracker.resetCount" + ], + "main": "./out/extension.js", + "contributes": { + "commands": [ + { + "command": "windsurf-step-tracker.showSteps", + "title": "Show Step Count" + }, + { + "command": "windsurf-step-tracker.addSteps", + "title": "Add Steps" + }, + { + "command": "windsurf-step-tracker.resetCount", + "title": "Reset Step Count" + } + ], + "viewsContainers": { + "activitybar": [ + { + "id": "step-tracker", + "title": "Step Tracker", + "icon": "resources/step-icon.svg" + } + ] + }, + "views": { + "step-tracker": [ + { + "type": "webview", + "id": "stepTrackerView", + "name": "Step Count" + } + ] + }, + "configuration": { + "title": "Windsurf Cascade Monthly Step Tracker", + "properties": { + "windsurf-step-tracker.monthlyLimit": { + "type": "number", + "default": 1000, + "description": "Monthly cascade step limit for Windsurf AI" + } + } + } + }, + "scripts": { + "vscode:prepublish": "npm run compile", + "compile": "tsc -p ./", + "watch": "tsc -watch -p ./", + "pretest": "npm run compile", + "test": "node ./out/test/runTest.js" + }, + "devDependencies": { + "@types/vscode": "^1.60.0", + "@types/node": "^14.17.0", + "typescript": "^4.3.5" + } +} diff --git a/resources/step-icon.svg b/resources/step-icon.svg new file mode 100644 index 0000000..ff914e2 --- /dev/null +++ b/resources/step-icon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/extension.ts b/src/extension.ts new file mode 100644 index 0000000..1e10aae --- /dev/null +++ b/src/extension.ts @@ -0,0 +1,289 @@ +import * as vscode from 'vscode'; +import * as fs from 'fs'; +import * as path from 'path'; +import * as os from 'os'; +import { createMainWebviewHtml, createProjectItemHtml } from './webview-templates'; + +interface StepData { + total_steps: number; + monthly_limit: number; + sessions: { + [key: string]: { + steps: number; + last_updated: string; + }; + }; + last_reset: string; +} + +export class StepTrackerProvider implements vscode.WebviewViewProvider { + public static readonly viewType = 'stepTrackerView'; + private _view?: vscode.WebviewView; + private _fileWatcher?: vscode.FileSystemWatcher; + + constructor( + private readonly _extensionUri: vscode.Uri, + ) { + // Set up file watcher for the step tracker file + const windsurfDir = path.join(os.homedir(), '.windsurf'); + const trackerPath = path.join(windsurfDir, 'step-tracker.json'); + this._fileWatcher = vscode.workspace.createFileSystemWatcher(trackerPath); + + // Update view when file changes (triggered by other VSCode instances) + this._fileWatcher.onDidChange(() => { + this._updateView(); + }); + + // Listen for configuration changes + vscode.workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('windsurf-step-tracker.monthlyLimit')) { + this._updateView(); + } + }); + } + + dispose() { + if (this._fileWatcher) { + this._fileWatcher.dispose(); + } + } + + public resolveWebviewView( + webviewView: vscode.WebviewView, + context: vscode.WebviewViewResolveContext, + _token: vscode.CancellationToken, + ) { + this._view = webviewView; + + webviewView.webview.options = { + enableScripts: true, + localResourceRoots: [this._extensionUri] + }; + + webviewView.webview.html = this._getHtmlForWebview(); + + // Initial update + this._updateView(); + + // Update when the view becomes visible + webviewView.onDidChangeVisibility(() => { + if (webviewView.visible) { + this._updateView(); + } + }); + + // Handle messages from the webview + webviewView.webview.onDidReceiveMessage(async (data) => { + switch (data.type) { + case 'addSteps': + await this.addSteps(data.project, data.steps); + break; + case 'resetCount': + await this.resetCount(); + break; + case 'confirmDelete': + const deleteChoice = await vscode.window.showWarningMessage( + data.message, + { modal: true }, + 'Delete', + 'Cancel' + ); + if (deleteChoice === 'Delete') { + await this.deleteProject(data.project); + vscode.window.showInformationMessage(`Deleted project ${data.project}`); + } + break; + case 'confirmEdit': + const editChoice = await vscode.window.showWarningMessage( + data.message, + { modal: true }, + 'Update', + 'Cancel' + ); + if (editChoice === 'Update') { + await this.editSteps(data.project, data.newSteps); + vscode.window.showInformationMessage(`Updated steps for ${data.project} to ${data.newSteps}`); + } + break; + case 'error': + vscode.window.showErrorMessage(data.message); + break; + } + }); + } + + private async _updateView() { + if (this._view) { + const data = await this._getStepData(); + this._view.webview.postMessage({ type: 'update', data }); + } + } + + private _getHtmlForWebview() { + const styleVars = { + fontFamily: 'var(--vscode-font-family)', + backgroundColor: 'var(--vscode-editor-background)', + foregroundColor: 'var(--vscode-editor-foreground)', + buttonBackground: 'var(--vscode-button-background)', + buttonForeground: 'var(--vscode-button-foreground)', + inputBackground: 'var(--vscode-input-background)', + inputForeground: 'var(--vscode-input-foreground)', + inputBorder: 'var(--vscode-input-border)', + }; + + const currentProject = this._getCurrentProjectInfo(); + return createMainWebviewHtml(styleVars, currentProject ?? { name: '', description: '' }); + } + + private _getStepData(): StepData { + const windsurfDir = path.join(os.homedir(), '.windsurf'); + const trackerPath = path.join(windsurfDir, 'step-tracker.json'); + + // Create .windsurf directory if it doesn't exist + if (!fs.existsSync(windsurfDir)) { + fs.mkdirSync(windsurfDir, { recursive: true }); + } + + const config = vscode.workspace.getConfiguration('windsurf-step-tracker'); + const monthlyLimit = config.get('monthlyLimit', 1000); + + if (!fs.existsSync(trackerPath)) { + const initialData: StepData = { + total_steps: 0, + monthly_limit: monthlyLimit, + sessions: {}, + last_reset: new Date().toISOString() + }; + fs.writeFileSync(trackerPath, JSON.stringify(initialData, null, 2)); + return initialData; + } + + const data = JSON.parse(fs.readFileSync(trackerPath, 'utf8')); + // Update monthly limit if configuration changed + if (data.monthly_limit !== monthlyLimit) { + data.monthly_limit = monthlyLimit; + fs.writeFileSync(trackerPath, JSON.stringify(data, null, 2)); + } + return data; + } + + private _getCurrentProjectInfo() { + const workspaceFolders = vscode.workspace.workspaceFolders; + if (!workspaceFolders || workspaceFolders.length === 0) { + return null; + } + + const activeFolder = workspaceFolders[0]; + const packageJsonPath = path.join(activeFolder.uri.fsPath, 'package.json'); + + try { + if (fs.existsSync(packageJsonPath)) { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + return { + name: packageJson.name || path.basename(activeFolder.uri.fsPath), + description: packageJson.description || '' + }; + } + return { + name: path.basename(activeFolder.uri.fsPath), + description: '' + }; + } catch { + return { + name: path.basename(activeFolder.uri.fsPath), + description: '' + }; + } + } + + public async addSteps(project: string, steps: number) { + const data = this._getStepData(); + if (!data.sessions[project]) { + data.sessions[project] = { + steps: 0, + last_updated: new Date().toISOString() + }; + } + data.sessions[project].steps += steps; + data.sessions[project].last_updated = new Date().toISOString(); + data.total_steps += steps; + + const trackerPath = path.join(os.homedir(), '.windsurf', 'step-tracker.json'); + fs.writeFileSync(trackerPath, JSON.stringify(data, null, 2)); + await this._updateView(); + } + + public async editSteps(project: string, newSteps: number) { + try { + const data = this._getStepData(); + if (data.sessions[project]) { + const oldSteps = data.sessions[project].steps; + data.total_steps = data.total_steps - oldSteps + newSteps; + data.sessions[project].steps = newSteps; + data.sessions[project].last_updated = new Date().toISOString(); + + const trackerPath = path.join(os.homedir(), '.windsurf', 'step-tracker.json'); + fs.writeFileSync(trackerPath, JSON.stringify(data, null, 2)); + await this._updateView(); + } else { + throw new Error(`Project ${project} not found`); + } + } catch (error) { + if (error instanceof Error) { + vscode.window.showErrorMessage(error.message); + } else { + vscode.window.showErrorMessage('An unknown error occurred'); + } + } + } + + public async deleteProject(project: string) { + try { + const data = this._getStepData(); + if (data.sessions[project]) { + data.total_steps -= data.sessions[project].steps; + delete data.sessions[project]; + + const trackerPath = path.join(os.homedir(), '.windsurf', 'step-tracker.json'); + fs.writeFileSync(trackerPath, JSON.stringify(data, null, 2)); + await this._updateView(); + } else { + throw new Error(`Project ${project} not found`); + } + } catch (error) { + if (error instanceof Error) { + vscode.window.showErrorMessage(error.message); + } else { + vscode.window.showErrorMessage('An unknown error occurred'); + } + } + } + + private async resetCount() { + const data = this._getStepData(); + data.total_steps = 0; + data.sessions = {}; + data.last_reset = new Date().toISOString(); + + const trackerPath = path.join(os.homedir(), '.windsurf', 'step-tracker.json'); + fs.writeFileSync(trackerPath, JSON.stringify(data, null, 2)); + await this._updateView(); + } +} + +export function activate(context: vscode.ExtensionContext) { + const provider = new StepTrackerProvider(context.extensionUri); + + context.subscriptions.push( + vscode.window.registerWebviewViewProvider(StepTrackerProvider.viewType, provider), + provider + ); + + let disposable = vscode.commands.registerCommand('windsurf-step-tracker.showSteps', () => { + vscode.commands.executeCommand('workbench.view.extension.step-tracker'); + }); + + context.subscriptions.push(disposable); +} + +export function deactivate() {} diff --git a/src/webview-templates.ts b/src/webview-templates.ts new file mode 100644 index 0000000..d9e0249 --- /dev/null +++ b/src/webview-templates.ts @@ -0,0 +1,298 @@ +interface StyleVars { + fontFamily: string; + backgroundColor: string; + foregroundColor: string; + buttonBackground: string; + buttonForeground: string; + inputBackground: string; + inputForeground: string; + inputBorder: string; +} + +interface ProjectInfo { + steps: number; + last_updated: string; +} + +export function createMainWebviewHtml(styleVars: StyleVars, currentProject?: { name: string, description: string }): string { + return ` + + + + + Step Tracker + + + + +
+
+
+
+ Steps: 0 / 1000 +
+
+ + + + +
+
+

Projects

+
+ + `; +} + +export function createProjectItemHtml(name: string, info: ProjectInfo): string { + return ` +
+ ${name} + ${info.steps} steps +
+
+
Last updated: ${new Date(info.last_updated).toLocaleString()}
+
+
+ + +
+
+
+ + +
+
`; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..de29686 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "ES2020", + "outDir": "out", + "lib": ["ES2020"], + "sourceMap": true, + "rootDir": "src", + "strict": true + }, + "exclude": ["node_modules", ".vscode-test"] +}