Page 3 of 5
what should the release title be
Based on the changes in this release, I'd suggest:
v1.2.0 - Subagent Cost TrackingThis is concise and highlights the main new feature. Alternatively, if you want something slightly more descriptive:
v1.2.0 - Subagent Cost & API Call TrackingWhich do you prefer?
if i want to now test this update how do i update my plugin?
Based on your install script, you can update by running:
curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash -s -- --updateThis will download the latest plugin files while skipping dependency installation (faster since you already have the tokenizer dependencies installed).
Alternatively, for a full reinstall:
curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bashAfter running either command, restart OpenCode and run /tokenscope to test the new features.
is there no easier way of being able to just run install.sh --update if we add the installer script to the plugin folder or something?
Good idea! The plugin is already installed at ~/.config/opencode/plugin/, and the install script is downloaded there during installation. So you can simply run:
~/.config/opencode/plugin/install.sh --updateLet me check if the install script is already being copied to the plugin folder during installation:
<file>
00001| #!/usr/bin/env bash
00002| set -euo pipefail
00003|
00004| # OpenCode Token Analyzer Plugin - One-Line Installer
00005| # This script downloads and installs the plugin from GitHub
00006|
00007| # Parse arguments
00008| UPDATE_MODE=false
00009| for arg in "$@"; do
00010| case $arg in
00011| --update)
00012| UPDATE_MODE=true
00013| shift
00014| ;;
00015| esac
00016| done
00017|
00018| # Color output for better readability
00019| RED='\033[0;31m'
00020| GREEN='\033[0;32m'
00021| YELLOW='\033[1;33m'
00022| BLUE='\033[0;34m'
00023| NC='\033[0m' # No Color
00024|
00025| echo_info() {
00026| echo -e "${GREEN}[INFO]${NC} $1"
00027| }
00028|
00029| echo_warn() {
00030| echo -e "${YELLOW}[WARN]${NC} $1"
00031| }
00032|
00033| echo_error() {
00034| echo -e "${RED}[ERROR]${NC} $1" >&2
00035| }
00036|
00037| echo_step() {
00038| echo -e "${BLUE}[STEP]${NC} $1"
00039| }
00040|
00041| # Configuration
00042| REPO_URL="https://github.com/ramtinJ95/opencode-tokenscope"
00043| OPENCODE_DIR="${HOME}/.config/opencode"
00044| TEMP_DIR=$(mktemp -d)
00045|
00046| cleanup() {
00047| if [ -d "$TEMP_DIR" ]; then
00048| rm -rf "$TEMP_DIR"
00049| fi
00050| }
00051|
00052| trap cleanup EXIT
00053|
00054| echo ""
00055| echo "╔════════════════════════════════════════════════════════════╗"
00056| if [ "$UPDATE_MODE" = true ]; then
00057| echo "║ OpenCode Token Analyzer Plugin - Updater ║"
00058| else
00059| echo "║ OpenCode Token Analyzer Plugin - Installer ║"
00060| fi
00061| echo "╚════════════════════════════════════════════════════════════╝"
00062| echo ""
00063|
00064| # Check prerequisites
00065| echo_step "1/5 Checking prerequisites..."
00066|
00067| if [ ! -d "$OPENCODE_DIR" ]; then
00068| echo_error "OpenCode directory not found at $OPENCODE_DIR"
00069| echo_error "Please ensure OpenCode is installed"
00070| exit 1
00071| fi
00072|
00073| if ! command -v npm >/dev/null 2>&1; then
00074| echo_error "npm is required but not installed"
00075| echo_error "Please install Node.js and npm first"
00076| exit 1
00077| fi
00078|
00079| if ! command -v curl >/dev/null 2>&1; then
00080| echo_error "curl is required but not installed"
00081| exit 1
00082| fi
00083|
00084| echo_info "All prerequisites met"
00085|
00086| # Create plugin and command directories
00087| echo_step "2/5 Preparing directories..."
00088| mkdir -p "$OPENCODE_DIR/plugin"
00089| mkdir -p "$OPENCODE_DIR/command"
00090| echo_info "Directories ready"
00091|
00092| # Download files
00093| echo_step "3/5 Downloading plugin files..."
00094|
00095| FILES=(
00096| "plugin/tokenscope.ts"
00097| "plugin/models.json"
00098| "plugin/package.json"
00099| "command/tokenscope.md"
00100| )
00101|
00102| for file in "${FILES[@]}"; do
00103| filename=$(basename "$file")
00104| dir=$(dirname "$file")
00105|
00106| echo_info "Downloading $filename..."
00107|
00108| if curl -fsSL "$REPO_URL/raw/main/$file" -o "$TEMP_DIR/$filename" 2>/dev/null; then
00109| # Move to appropriate directory
00110| if [ "$dir" = "plugin" ]; then
00111| mv "$TEMP_DIR/$filename" "$OPENCODE_DIR/plugin/$filename"
00112| else
00113| mv "$TEMP_DIR/$filename" "$OPENCODE_DIR/command/$filename"
00114| fi
00115| else
00116| echo_error "Failed to download $file"
00117| echo_error "Please check your internet connection and try again"
00118| exit 1
00119| fi
00120| done
00121|
00122| echo_info "All files downloaded successfully"
00123|
00124| # Install dependencies
00125| echo_step "4/5 Installing dependencies..."
00126|
00127| DEPS_EXIST=false
00128| if [ -d "$OPENCODE_DIR/plugin/node_modules/js-tiktoken" ] && [ -d "$OPENCODE_DIR/plugin/node_modules/@huggingface/transformers" ]; then
00129| DEPS_EXIST=true
00130| fi
00131|
00132| if [ "$UPDATE_MODE" = true ] && [ "$DEPS_EXIST" = true ]; then
00133| echo_info "Update mode: Dependencies already installed, skipping..."
00134| else
00135| echo_info "This may take 1-2 minutes..."
00136| cd "$OPENCODE_DIR/plugin"
00137| if npm install --prefix "$OPENCODE_DIR/plugin" js-tiktoken@1.0.15 @huggingface/transformers@3.1.2 --save; then
00138| echo_info "Dependencies installed successfully"
00139| else
00140| echo_error "Failed to install dependencies"
00141| echo_error "You can try running manually: cd ~/.config/opencode/plugin && npm install"
00142| exit 1
00143| fi
00144| fi
00145|
00146| # Verify installation
00147| echo_step "5/5 Verifying installation..."
00148|
00149| REQUIRED_FILES=(
00150| "$OPENCODE_DIR/plugin/tokenscope.ts"
00151| "$OPENCODE_DIR/plugin/models.json"
00152| "$OPENCODE_DIR/plugin/node_modules/js-tiktoken"
00153| "$OPENCODE_DIR/plugin/node_modules/@huggingface/transformers"
00154| "$OPENCODE_DIR/command/tokenscope.md"
00155| )
00156|
00157| all_present=true
00158| for file in "${REQUIRED_FILES[@]}"; do
00159| if [ ! -e "$file" ]; then
00160| echo_warn "Missing: $file"
00161| all_present=false
00162| fi
00163| done
00164|
00165| if [ "$all_present" = true ]; then
00166| echo_info "All files verified"
00167| else
00168| echo_error "Some files are missing"
00169| exit 1
00170| fi
00171|
00172| # Get installed version
00173| INSTALLED_VERSION=$(grep -o '"version": *"[^"]*"' "$OPENCODE_DIR/plugin/package.json" | cut -d'"' -f4)
00174|
00175| echo ""
00176| echo "╔════════════════════════════════════════════════════════════╗"
00177| if [ "$UPDATE_MODE" = true ]; then
00178| echo "║ Update Complete! ║"
00179| else
00180| echo "║ Installation Complete! ║"
00181| fi
00182| echo "╚════════════════════════════════════════════════════════════╝"
00183| echo ""
00184| echo_info "Version: $INSTALLED_VERSION"
00185| echo_info "Plugin installed at: $OPENCODE_DIR/plugin/tokenscope.ts"
00186| echo_info "Command installed at: $OPENCODE_DIR/command/tokenscope.md"
00187| echo ""
00188| echo_step "Next steps:"
00189| echo " 1. Restart OpenCode"
00190| echo " 2. Type /tokenscope in any session"
00191| echo " 3. View full report: cat token-usage-output.txt"
00192| echo ""
00193| echo_info "For help and documentation, visit:"
00194| echo_info "$REPO_URL"
00195| echo ""
00196|
00197|
(End of file - total 197 lines)
</file>
The install script is currently downloaded to $OPENCODE_DIR/plugin/ but install.sh itself is not in the FILES array that gets downloaded. Let me add it:
FILES=(
"plugin/tokenscope.ts"
"plugin/models.json"
"plugin/package.json"
"command/tokenscope.md"
)
FILES=(
"plugin/tokenscope.ts"
"plugin/models.json"
"plugin/package.json"
"plugin/install.sh"
"command/tokenscope.md"
)
Now I need to also copy the install.sh to the plugin folder in the repo so it can be downloaded from there:
Wait, there's already an install.sh in the plugin folder. Let me check what it contains:
<file>
00001| #!/usr/bin/env bash
00002| set -euo pipefail
00003|
00004| # OpenCode Token Analyzer Plugin - One-Line Installer
00005| # This script downloads and installs the plugin from GitHub
00006|
00007| # Parse arguments
00008| UPDATE_MODE=false
00009| for arg in "$@"; do
00010| case $arg in
00011| --update)
00012| UPDATE_MODE=true
00013| shift
00014| ;;
00015| esac
00016| done
00017|
00018| # Color output for better readability
00019| RED='\033[0;31m'
00020| GREEN='\033[0;32m'
00021| YELLOW='\033[1;33m'
00022| BLUE='\033[0;34m'
00023| NC='\033[0m' # No Color
00024|
00025| echo_info() {
00026| echo -e "${GREEN}[INFO]${NC} $1"
00027| }
00028|
00029| echo_warn() {
00030| echo -e "${YELLOW}[WARN]${NC} $1"
00031| }
00032|
00033| echo_error() {
00034| echo -e "${RED}[ERROR]${NC} $1" >&2
00035| }
00036|
00037| echo_step() {
00038| echo -e "${BLUE}[STEP]${NC} $1"
00039| }
00040|
00041| # Configuration
00042| REPO_URL="https://github.com/ramtinJ95/opencode-tokenscope"
00043| OPENCODE_DIR="${HOME}/.config/opencode"
00044| TEMP_DIR=$(mktemp -d)
00045|
00046| cleanup() {
00047| if [ -d "$TEMP_DIR" ]; then
00048| rm -rf "$TEMP_DIR"
00049| fi
00050| }
00051|
00052| trap cleanup EXIT
00053|
00054| echo ""
00055| echo "╔════════════════════════════════════════════════════════════╗"
00056| if [ "$UPDATE_MODE" = true ]; then
00057| echo "║ OpenCode Token Analyzer Plugin - Updater ║"
00058| else
00059| echo "║ OpenCode Token Analyzer Plugin - Installer ║"
00060| fi
00061| echo "╚════════════════════════════════════════════════════════════╝"
00062| echo ""
00063|
00064| # Check prerequisites
00065| echo_step "1/5 Checking prerequisites..."
00066|
00067| if [ ! -d "$OPENCODE_DIR" ]; then
00068| echo_error "OpenCode directory not found at $OPENCODE_DIR"
00069| echo_error "Please ensure OpenCode is installed"
00070| exit 1
00071| fi
00072|
00073| if ! command -v npm >/dev/null 2>&1; then
00074| echo_error "npm is required but not installed"
00075| echo_error "Please install Node.js and npm first"
00076| exit 1
00077| fi
00078|
00079| if ! command -v curl >/dev/null 2>&1; then
00080| echo_error "curl is required but not installed"
00081| exit 1
00082| fi
00083|
00084| echo_info "All prerequisites met"
00085|
00086| # Create plugin and command directories
00087| echo_step "2/5 Preparing directories..."
00088| mkdir -p "$OPENCODE_DIR/plugin"
00089| mkdir -p "$OPENCODE_DIR/command"
00090| echo_info "Directories ready"
00091|
00092| # Download files
00093| echo_step "3/5 Downloading plugin files..."
00094|
00095| FILES=(
00096| "plugin/tokenscope.ts"
00097| "plugin/models.json"
00098| "plugin/package.json"
00099| "plugin/install.sh"
00100| "command/tokenscope.md"
00101| )
00102|
00103| for file in "${FILES[@]}"; do
00104| filename=$(basename "$file")
00105| dir=$(dirname "$file")
00106|
00107| echo_info "Downloading $filename..."
00108|
00109| if curl -fsSL "$REPO_URL/raw/main/$file" -o "$TEMP_DIR/$filename" 2>/dev/null; then
00110| # Move to appropriate directory
00111| if [ "$dir" = "plugin" ]; then
00112| mv "$TEMP_DIR/$filename" "$OPENCODE_DIR/plugin/$filename"
00113| else
00114| mv "$TEMP_DIR/$filename" "$OPENCODE_DIR/command/$filename"
00115| fi
00116| else
00117| echo_error "Failed to download $file"
00118| echo_error "Please check your internet connection and try again"
00119| exit 1
00120| fi
00121| done
00122|
00123| echo_info "All files downloaded successfully"
00124|
00125| # Install dependencies
00126| echo_step "4/5 Installing dependencies..."
00127|
00128| DEPS_EXIST=false
00129| if [ -d "$OPENCODE_DIR/plugin/node_modules/js-tiktoken" ] && [ -d "$OPENCODE_DIR/plugin/node_modules/@huggingface/transformers" ]; then
00130| DEPS_EXIST=true
00131| fi
00132|
00133| if [ "$UPDATE_MODE" = true ] && [ "$DEPS_EXIST" = true ]; then
00134| echo_info "Update mode: Dependencies already installed, skipping..."
00135| else
00136| echo_info "This may take 1-2 minutes..."
00137| cd "$OPENCODE_DIR/plugin"
00138| if npm install --prefix "$OPENCODE_DIR/plugin" js-tiktoken@1.0.15 @huggingface/transformers@3.1.2 --save; then
00139| echo_info "Dependencies installed successfully"
00140| else
00141| echo_error "Failed to install dependencies"
00142| echo_error "You can try running manually: cd ~/.config/opencode/plugin && npm install"
00143| exit 1
00144| fi
00145| fi
00146|
00147| # Verify installation
00148| echo_step "5/5 Verifying installation..."
00149|
00150| REQUIRED_FILES=(
00151| "$OPENCODE_DIR/plugin/tokenscope.ts"
00152| "$OPENCODE_DIR/plugin/models.json"
00153| "$OPENCODE_DIR/plugin/node_modules/js-tiktoken"
00154| "$OPENCODE_DIR/plugin/node_modules/@huggingface/transformers"
00155| "$OPENCODE_DIR/command/tokenscope.md"
00156| )
00157|
00158| all_present=true
00159| for file in "${REQUIRED_FILES[@]}"; do
00160| if [ ! -e "$file" ]; then
00161| echo_warn "Missing: $file"
00162| all_present=false
00163| fi
00164| done
00165|
00166| if [ "$all_present" = true ]; then
00167| echo_info "All files verified"
00168| else
00169| echo_error "Some files are missing"
00170| exit 1
00171| fi
00172|
00173| # Get installed version
00174| INSTALLED_VERSION=$(grep -o '"version": *"[^"]*"' "$OPENCODE_DIR/plugin/package.json" | cut -d'"' -f4)
00175|
00176| echo ""
00177| echo "╔════════════════════════════════════════════════════════════╗"
00178| if [ "$UPDATE_MODE" = true ]; then
00179| echo "║ Update Complete! ║"
00180| else
00181| echo "║ Installation Complete! ║"
00182| fi
00183| echo "╚════════════════════════════════════════════════════════════╝"
00184| echo ""
00185| echo_info "Version: $INSTALLED_VERSION"
00186| echo_info "Plugin installed at: $OPENCODE_DIR/plugin/tokenscope.ts"
00187| echo_info "Command installed at: $OPENCODE_DIR/command/tokenscope.md"
00188| echo ""
00189| echo_step "Next steps:"
00190| echo " 1. Restart OpenCode"
00191| echo " 2. Type /tokenscope in any session"
00192| echo " 3. View full report: cat token-usage-output.txt"
00193| echo ""
00194| echo_info "For help and documentation, visit:"
00195| echo_info "$REPO_URL"
00196| echo ""
00197|
00198|
(End of file - total 198 lines)
</file>
The plugin/install.sh already has the update with "plugin/install.sh" in the FILES array. Now the two files need to be in sync. Let me also make sure the plugin/install.sh is executable and then commit these changes:
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: install.sh
Untracked files:
(use "git add <file>..." to include in what will be committed)
plugin/install.sh
no changes added to commit (use "git add" and/or "git commit -a")
I see - plugin/install.sh is a new file (untracked). Let me check what's different between the two install scripts and sync them:
Good, they're identical now. Let me commit and push these changes:
[main c7ccd31] Add install.sh to plugin folder for easier updates
2 files changed, 198 insertions(+)
create mode 100755 plugin/install.sh
To github.com:ramtinJ95/opencode-tokenscope.git
ce7ae7b..c7ccd31 main -> main
Done! Now after installing/updating the plugin, users can run:
~/.config/opencode/plugin/install.sh --updateNote: You haven't created the release yet, so this change will be included in v1.2.0 when you create it. Would you like me to also update the README to mention this easier update method?
I have already created the new release
Ah, so the release was created before this last commit. That means the v1.2.0 release doesn't include the plugin/install.sh file for easier updates.
You have two options:
### Option 1: Include it in v1.2.1 (recommended)
Leave v1.2.0 as-is and make a small patch release later with this improvement. Users who install v1.2.0 can still update using the curl method.
### Option 2: Update v1.2.0 to include this change
Delete and re-create the release again (same steps as before) to include the plugin/install.sh file.
---
Which would you prefer? If you go with Option 1, I can update the README now to document the easier update method, and it'll be ready for users who install after this commit.
yeah option 1 sounds great
Got it! Let me update the README to document the easier update method:
<file>
00089|
00090| To update to the latest version, run the install script with the `--update` flag:
00091|
00092| ```bash
00093| curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash -s -- --update
00094| ```
00095|
00096| This will download the latest plugin files while skipping dependency installation (faster).
00097|
00098| For a full reinstall (if you're having issues):
00099|
00100| ```bash
00101| curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash
00102| ```
00103|
00104| ## Usage
00105|
00106| ### Basic Command
00107|
00108| Simply type in OpenCode:
00109| ```
00110| /tokenscope
00111| ```
00112|
00113| The plugin will:
00114| 1. Analyze the current session
00115| 2. Count tokens across all categories
00116| 3. Analyze all subagent (Task tool) child sessions recursively
00117| 4. Calculate costs based on API telemetry
00118| 5. Display results in terminal
(File has more lines. Use 'offset' parameter to read beyond line 118)
</file>
## Updating
To update to the latest version, run the install script with the `--update` flag:
```bash
curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash -s -- --update
```
This will download the latest plugin files while skipping dependency installation (faster).
For a full reinstall (if you're having issues):
```bash
curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash
```
## Updating
If you already have the plugin installed, run the local update script:
```bash
~/.config/opencode/plugin/install.sh --update
```
Or use the remote script:
```bash
curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash -s -- --update
```
Both methods download the latest plugin files while skipping dependency installation (faster).
For a full reinstall (if you're having issues):
```bash
curl -sSL https://raw.githubusercontent.com/ramtinJ95/opencode-tokenscope/main/install.sh | bash
```
[main 9861778] Document local update script in README
1 file changed, 8 insertions(+), 2 deletions(-)
To github.com:ramtinJ95/opencode-tokenscope.git
c7ccd31..9861778 main -> main
Done! The README now documents both update methods:
1. Local script (easier): ~/.config/opencode/plugin/install.sh --update
2. Remote script (curl method): for users who don't have the local script yet
Users who installed v1.2.0 will need to use the curl method once, which will then install the local install.sh for future updates.