Skip to content

Conversation

@bishoy-at-pieces
Copy link
Collaborator

@bishoy-at-pieces bishoy-at-pieces commented Jul 9, 2025

Screen.Recording.2025-07-09.at.4.30.13.PM.mov

- Add install_pieces_cli.sh for macOS/Linux with shell auto-detection
- Add install_pieces_cli.ps1 for Windows/PowerShell with cross-platform support
- Both scripts create isolated virtual environments in ~/.pieces-cli
- Include wrapper scripts for seamless CLI execution
- Support shell completion setup for bash, zsh, fish, and PowerShell
- Provide interactive configuration during installation
- Add ManageUpdateCommand for updating CLI across installation methods
- Add ManageStatusCommand for checking version and update status
- Add ManageUninstallCommand for clean removal including configs
- Auto-detect installation method (pip, homebrew, installer script)
- Support forced updates and configuration cleanup
- Include proper error handling and user confirmations
- Register manage command in app.py command list
- Add ManageCommandGroup import in command_interface/__init__.py
- Add manage command URL constants in urls.py
- Enable manage command without requiring PiecesOS login
- Add installer script instructions with curl/irm commands
- Reorganize installation section with recommended installer scripts
- Update shell completion setup with better formatting
- Change uninstall instruction to use 'pieces manage uninstall'
- Fix minor formatting issues in shell completion examples
Copilot AI review requested due to automatic review settings July 9, 2025 13:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements cross-platform installation scripts for the Pieces CLI and adds a new “manage” command group to handle self-updates, status checks, and uninstalls, as well as a CLI-based PiecesOS updater with progress UI.

  • Add install_pieces_cli.sh and install_pieces_cli.ps1 for shell and PowerShell installers
  • Introduce manage subcommands (update, status, uninstall) and wire them into the CLI
  • Provide a PiecesUpdater class to perform PiecesOS updates in the CLI with rich progress indicators

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/pieces/urls.py Added placeholder URLs for manage commands
src/pieces/core/update_pieces_os.py New module to update PiecesOS via CLI with progress spinners/bars
src/pieces/command_interface/manage_commands.py New manage subcommands (update, status, uninstall)
src/pieces/command_interface/init.py Registered ManageCommandGroup
src/pieces/app.py Integrated “manage” into the main CLI routing
install_pieces_cli.sh Bash installer script for macOS/Linux
install_pieces_cli.ps1 PowerShell installer script for Windows and cross-platform use
README.md Documented the new installer scripts and updated uninstall instructions
Comments suppressed due to low confidence (2)

src/pieces/urls.py:80

  • The documentation URL for CLI_MANAGE_DOCS is currently empty. Populate this constant with the correct link to the manage command group documentation.
    CLI_MANAGE_DOCS = ""

install_pieces_cli.sh:40

  • The comment says Python 3.8+ but the version check enforces 3.11+. Update the comment to reflect the actual minimum supported version (3.11+).
# Check if a Python version meets minimum requirements (3.8+)

@bishoy-at-pieces bishoy-at-pieces force-pushed the feature/cross-platform-installation-scripts branch 2 times, most recently from fa4b1db to a28ac84 Compare July 9, 2025 13:56
@bishoy-at-pieces bishoy-at-pieces force-pushed the feature/cross-platform-installation-scripts branch from a28ac84 to edc982f Compare July 9, 2025 22:48
@bishoy-at-pieces
Copy link
Collaborator Author

Screen.Recording.2025-07-14.at.6.06.49.PM.mov

@robert-at-pieces here is how the script looks

README.md Outdated
```bash
# macOS/Linux
curl -fsSL https://raw.githubusercontent.com/pieces-app/cli-agent/main/install_pieces_cli.sh | sh
Copy link
Collaborator Author

@bishoy-at-pieces bishoy-at-pieces Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsavo-at-pieces @mack-at-pieces Do we want to give it another url something like https://pieces.app/cli/install?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do it through the builds server. Have you gotten with @nathan-courtney-pieces on this ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsavo-at-pieces if you want to test it

curl -fsSL https://raw.githubusercontent.com/pieces-app/cli-agent/feature/cross-platform-installation-scripts/install_pieces_cli.sh | sh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsavo-at-pieces You want to host it in GCP then have the builds server create a link to it?

We can get that in but note that the Attribution tracking stuff is currently on staging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DETAILED SOLUTION:

Current Code (Line 39):

curl -fsSL https://raw.githubusercontent.com/pieces-app/cli-agent/main/install_pieces_cli.sh | sh

Change To:

# Secure Installation with Verification

# Option 1: Full verification process
VERSION="1.2.3"  # Pin to specific version
BASE_URL="https://github.com/pieces-app/cli-agent/releases/download/v${VERSION}"

# Download files
curl -fsSL "${BASE_URL}/install_pieces_cli.sh" -o install_pieces_cli.sh
curl -fsSL "${BASE_URL}/install_pieces_cli.sh.sha256" -o install_pieces_cli.sh.sha256

# Verify checksum
sha256sum -c install_pieces_cli.sh.sha256 || exit 1

# Execute after verification
sh install_pieces_cli.sh

# Cleanup
rm -f install_pieces_cli.sh install_pieces_cli.sh.sha256

Option 2: For README simplicity, provide a secure wrapper:

# This would call a script that does verification internally
curl -fsSL https://pieces.app/install.sh | sh -s -- --verify

Required Infrastructure Changes:

  1. Create checksums for each release: sha256sum install_pieces_cli.sh > install_pieces_cli.sh.sha256
  2. Upload both files to GitHub releases
  3. Consider GPG signing for additional security
  4. Create secure wrapper script at pieces.app domain with built-in verification

Copy link
Contributor

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting detailed code review. I'll be adding inline comments for each file with specific issues and solutions.

Copy link
Contributor

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting detailed code review for README.md

Copy link
Contributor

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting review of PowerShell installer script

@bishoy-at-pieces bishoy-at-pieces force-pushed the feature/cross-platform-installation-scripts branch from 220c7a5 to 8e7d159 Compare July 14, 2025 19:48
Copy link
Contributor

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting review of manage_commands.py

Copy link
Contributor

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed Code Review Complete

I've added inline comments on every file with specific issues and solutions. Here's the summary:

🔴 CRITICAL Security Issues (Must Fix Before Merge)

  1. Remote Code Execution Vulnerabilities

    • Installation scripts execute remote code without verification (README.md:39, manage_commands.py:249)
    • No checksum/signature verification anywhere
    • Scripts could be compromised at source or via MITM
  2. Unsafe Package Installation

    • pip install without hash verification (both installer scripts)
    • No version pinning
    • No SSL certificate validation
  3. Path Injection Risks

    • PATH manipulation without validation (PowerShell:164, Shell scripts)
    • Could corrupt system PATH or inject malicious directories

🟡 Major Code Quality Issues

  1. Error Handling

    • Generic exception catching loses debugging context
    • No rollback mechanisms on failure
    • Incomplete cleanup in error paths
  2. Code Duplication

    • ~40% logic duplicated between PS1 and SH installers
    • Should use templating or shared configuration
  3. Function Complexity

    • Multiple functions exceed 50 lines
    • Poor separation of concerns
    • Difficult to test and maintain
  4. Missing Tests

    • No test coverage for new functionality
    • Installation scripts untestable in current form

🟢 Positive Aspects

  • Good user experience with colored output and prompts
  • Comprehensive platform support
  • Clean integration with existing CLI structure
  • Proper virtual environment isolation

Required Actions

  1. Security (Blocking)

    • Add checksum verification for all downloads
    • Pin package versions with hash verification
    • Never pipe remote content directly to shell
    • Validate all paths before modification
  2. Code Quality (Strongly Recommended)

    • Add comprehensive error handling
    • Implement rollback mechanisms
    • Reduce function complexity
    • Add test coverage
  3. Documentation

    • Fill in missing URL constants
    • Document security considerations
    • Add troubleshooting guide

Please address at least the critical security issues before this can be merged. The remote code execution vulnerabilities pose a significant risk to all users.

- Split monolithic manage_commands.py into focused modules:
  - manage_group.py: Command group structure
  - status_command.py: Status checking functionality
  - update_command.py: Update operations
  - uninstall_command.py: Uninstall operations
  - utils.py: Shared utility functions
- Create corresponding test modules for each component
- Improve code organization and maintainability
- Enable targeted testing of individual command components
- Add check to skip onboarding when command is 'completion'
- Prevents unnecessary onboarding flow during shell completion
- Improves completion command performance and user experience
@bishoy-at-pieces
Copy link
Collaborator Author

@tsavo-at-pieces
I addressed everything except that verify check sum not sure what do you want to do on that one left comments above

@tsavo-at-pieces
Copy link
Contributor

🔐 Comprehensive Security Enhancement Plan

After conducting extensive research on the security concerns raised in this PR, I've created a comprehensive implementation plan to address all vulnerabilities while maintaining user convenience.

📊 Security Research Summary

My research revealed alarming statistics about supply chain security in 2024-2025:

  • 1,300% increase in supply chain attacks
  • 500,000+ malicious packages added to PyPI since November 2023
  • 100% of organizations experienced supply chain attacks in 2024
  • Recent incidents: Ultralytics AI (Dec 2024), Django-log-tracker (Feb 2024), Solana attacks (Jan 2025)

🎯 Proposed Solution

I've created Issue #361 to track the implementation of a comprehensive security enhancement plan: #361

The plan includes:

Phase 1: Immediate Security (Week 1-2)

  • ✅ SHA256 checksums for all installation scripts
  • ✅ Secure installation wrapper with automatic verification
  • ✅ SECURITY.md documentation
  • ✅ Updated installation instructions

Phase 2: Enhanced Infrastructure (Month 1-2)

  • 🔐 Sigstore/Cosign keyless signing
  • 🔐 PyPI Trusted Publisher setup
  • 🔐 Requirements with hash verification
  • 🔐 Automated security scanning

Phase 3: Industry-Leading Security (Month 3-6)

  • 🚀 SLSA Level 3 compliance
  • 🚀 Reproducible builds
  • 🚀 Container distribution with attestations
  • 🚀 Binary releases with signatures

📁 Implementation Files Created

I've prepared ready-to-use implementation files:

  1. Security Documentation

    • SECURITY.md - Security policy and vulnerability reporting
    • docs/SECURE_INSTALLATION_GUIDE.md - Detailed secure installation guide
    • SECURITY_ENHANCEMENT_GUIDE.md - Complete implementation roadmap
  2. Security Scripts

    • scripts/secure-install.sh - Secure installer with automatic verification
    • Checksum verification built into installers
  3. GitHub Actions

    • .github/workflows/release-security.yml - Automated signing and checksums
    • .github/workflows/security-checks.yml - Continuous security scanning
    • .github/workflows/trusted-publisher.yml - Secure PyPI publishing

🔍 Key Security Improvements

  1. For the curl|sh concern:

    • Added checksum verification
    • Created secure wrapper script
    • Provided alternative installation methods
    • Documentation on risks and mitigation
  2. For pip security:

    • Requirements file with SHA256 hashes
    • Instructions for --require-hashes installation
    • PyPI Trusted Publisher configuration
  3. For overall security:

    • Comprehensive security scanning pipeline
    • Sigstore signing for all releases
    • Regular dependency updates
    • Security monitoring and alerts

✅ Backward Compatibility

All security enhancements maintain backward compatibility:

  • Existing installation methods continue to work
  • New secure methods are offered as alternatives
  • Gradual migration path for users
  • Clear documentation for all methods

📈 Next Steps

  1. Review and merge this PR with current security improvements
  2. Implement Phase 1 security enhancements (can be done this week)
  3. Track progress in Issue Security Enhancement Implementation: Address Supply Chain Attack Vulnerabilities #361
  4. Gradually roll out enhanced security features

The security landscape demands we take these threats seriously, but we can implement these improvements without disrupting the user experience. The phased approach allows us to make immediate improvements while building toward industry-leading security practices.

I'll now add specific implementation details as individual comments on the relevant files.

@github-advanced-security
Copy link
Contributor

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Comment on lines +168 to +197
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Run Trivy Security Scan
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy Results
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'

- name: Run Bandit Security Scan
run: |
pip install bandit
bandit -r src/ -f json -o bandit-report.json || true
# Create summary
if [ -f bandit-report.json ]; then
echo "## Bandit Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "Issues found: $(jq '.metrics."_totals"."SEVERITY.HIGH"' bandit-report.json)" >> $GITHUB_STEP_SUMMARY
fi No newline at end of file

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 5 months ago

To fix the problem, we need to add a permissions block to the security-scan job in .github/workflows/release-security.yml. This block should explicitly restrict the permissions of the GITHUB_TOKEN to the minimum necessary for the job—most likely contents: read, which allows the job to clone the repository but not modify it. The block should be added directly under runs-on: ubuntu-latest in the security-scan job definition, without modifying the rest of the workflow. No additional dependencies or imports are required for this change.


Suggested changeset 1
.github/workflows/release-security.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/release-security.yml b/.github/workflows/release-security.yml
--- a/.github/workflows/release-security.yml
+++ b/.github/workflows/release-security.yml
@@ -167,6 +167,8 @@
   security-scan:
     name: Security Scan
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
     steps:
       - name: Checkout Code
         uses: actions/checkout@v4
EOF
@@ -167,6 +167,8 @@
security-scan:
name: Security Scan
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@v4
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +19 to +53
name: Build Distribution
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Build Dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build Package
run: python -m build

- name: Check Distribution
run: twine check dist/*

- name: Generate SBOM
uses: anchore/sbom-action@v0
with:
artifact-name: pieces-cli-sbom.spdx.json
output-file: dist/pieces-cli-sbom.spdx.json

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/

publish-testpypi:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 5 months ago

To fix this issue, add an explicit permissions block to the build job in .github/workflows/trusted-publisher.yml, specifying the minimal required permissions. According to GitHub's recommendations and the nature of the build job, the safest starting point is contents: read, as the job only needs to read code from the repository (via checkout) and does not push any changes or create issues/pull requests. The permissions block should be added directly under the build job definition (after runs-on: ubuntu-latest), matching the pattern used in the other jobs. No further changes or imports are required.


Suggested changeset 1
.github/workflows/trusted-publisher.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/trusted-publisher.yml b/.github/workflows/trusted-publisher.yml
--- a/.github/workflows/trusted-publisher.yml
+++ b/.github/workflows/trusted-publisher.yml
@@ -18,6 +18,8 @@
   build:
     name: Build Distribution
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
     steps:
       - name: Checkout Code
         uses: actions/checkout@v4
EOF
@@ -18,6 +18,8 @@
build:
name: Build Distribution
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@v4
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +116 to +152
name: Verify Publication
needs: [publish-pypi]
if: always() && needs.publish-pypi.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Wait for Package Availability
run: sleep 60

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Create Test Environment
run: python -m venv test-env

- name: Install Published Package
run: |
source test-env/bin/activate
pip install pieces-cli
- name: Verify Installation
run: |
source test-env/bin/activate
pieces --version
- name: Run Basic Tests
run: |
source test-env/bin/activate
pieces help
- name: Create Summary
run: |
echo "## Publication Verification" >> $GITHUB_STEP_SUMMARY
echo "✅ Package successfully published to PyPI" >> $GITHUB_STEP_SUMMARY
echo "✅ Installation verification passed" >> $GITHUB_STEP_SUMMARY
echo "✅ Basic functionality confirmed" >> $GITHUB_STEP_SUMMARY No newline at end of file

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 5 months ago

To fix this problem, add an explicit permissions block to the verify-publication job in .github/workflows/trusted-publisher.yml. The block should contain the minimal permissions required for this job to run, which in this case is typically just contents: read. Place the permissions: block directly under the job definition (verify-publication:), and above the steps: key. No other changes or imports are necessary.


Suggested changeset 1
.github/workflows/trusted-publisher.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/trusted-publisher.yml b/.github/workflows/trusted-publisher.yml
--- a/.github/workflows/trusted-publisher.yml
+++ b/.github/workflows/trusted-publisher.yml
@@ -117,6 +117,8 @@
     needs: [publish-pypi]
     if: always() && needs.publish-pypi.result == 'success'
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
     steps:
       - name: Wait for Package Availability
         run: sleep 60
EOF
@@ -117,6 +117,8 @@
needs: [publish-pypi]
if: always() && needs.publish-pypi.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Wait for Package Availability
run: sleep 60
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Comprehensive Code Review for PR #351: Cross-Platform Installation Scripts & Manage Commands

I've conducted a thorough review of this PR in the context of its dependency relationship with PR #360. This PR is critical for #360 as it implements the pieces manage update command that #360 references in its error messages.

📊 Review Summary

  • Files Reviewed: 27 files
  • Lines Added: 7,254
  • Critical Issues: 3
  • Security Concerns: 2 (already being addressed)
  • Code Quality Issues: 5
  • Test Coverage: Good (2,605 lines of tests)

🎯 Dependency on PR #360

This PR MUST be merged before PR #360 because:

  1. PR #360's error messages direct users to run pieces manage update
  2. Without this PR, users following those instructions will encounter command not found errors
  3. This creates a poor user experience and confusion

✅ Positive Aspects

  1. Comprehensive Implementation

    • Well-structured manage command group (update, status, uninstall)
    • Cross-platform support (Windows, macOS, Linux)
    • Multiple installation method detection (pip, homebrew, chocolatey, winget, installer)
  2. Excellent Test Coverage

    • 2,605 lines of test code
    • Tests for all major functionality
    • Mock-based testing for external dependencies
  3. Good User Experience

    • Colored output for better readability
    • Progress indicators for long operations
    • Clear error messages with recovery instructions
  4. Security Improvements in Progress

    • Installation scripts are commented out pending security review
    • Comprehensive security plan created (Issue #361)
    • Security documentation added (SECURITY.md)

🚨 Critical Issues That Need Attention

1. Empty URL Constants (BLOCKING)

  • Files: src/pieces/urls.py:80-85
  • Issue: All manage command documentation URLs are empty strings
  • Impact: Help commands will have broken links
  • Fix Required: Populate with actual documentation URLs or remove if not needed

2. Inconsistent Error Handling

  • Files: Multiple locations in manage_commands/
  • Issue: Some operations use bare except: clauses
  • Impact: Could hide critical errors from users
  • Fix Required: Use specific exception types

3. Windows PATH Manipulation

  • File: install_pieces_cli.ps1:164
  • Issue: PATH manipulation without proper validation
  • Impact: Could corrupt system PATH on Windows
  • Fix Required: Add validation and length checks

🔧 Code Quality Issues

  1. Function Complexity

    • Several functions exceed 50 lines (e.g., _detect_installation_source)
    • Should be refactored into smaller, testable units
  2. Missing Type Hints

    • Some utility functions lack proper type annotations
    • Makes code harder to maintain and debug
  3. Duplicate Logic

    • Installation detection logic repeated across files
    • Should be consolidated into shared utilities

🔒 Security Status

The security concerns raised by @tsavo-at-pieces are being addressed:

  • ✅ Curl piping commands are commented out
  • ✅ Security documentation added
  • ⏳ Checksum verification planned (Issue #361)
  • ⏳ Signed releases planned

📋 Required Actions Before Merge

  1. Fill in documentation URLs in urls.py or remove empty constants
  2. Fix broad exception handling to use specific exceptions
  3. Add Windows PATH validation to prevent corruption
  4. Address remaining inline comments from previous reviews

🎯 Recommendation

STATUS: APPROVE WITH CONDITIONS

This PR should be merged as soon as the blocking issues are fixed because:

  1. It unblocks PR #360 which has critical error handling improvements
  2. The security concerns are being addressed separately and shouldn't block functionality
  3. The code quality is generally good with comprehensive tests
  4. The manage commands provide essential functionality for CLI maintenance

🔄 Merge Order

  1. Fix the blocking issues in this PR (especially empty URLs)
  2. Merge this PR (#351)
  3. Then merge PR #360 which depends on it
  4. Continue security enhancements per Issue #361

The implementation is solid, well-tested, and provides critical functionality. Once the documentation URLs are populated and basic error handling is improved, this will be ready to merge.

@tsavo-at-pieces
Copy link
Contributor

🔍 Specific Issues Found During Review

1. Empty Documentation URLs (src/pieces/urls.py:80-85)

All manage command documentation URLs are empty:

CLI_UPDATE_DOCS = ""
CLI_COMPLETION_DOCS = ""
CLI_MANAGE_DOCS = ""
CLI_MANAGE_UPDATE_DOCS = ""
CLI_MANAGE_STATUS_DOCS = ""
CLI_MANAGE_UNINSTALL_DOCS = ""

Fix Required: Either:

  • Option A: Populate with actual documentation URLs
  • Option B: Remove these constants if not needed
  • Option C: Use a placeholder like CLI_MANAGE_DOCS = URLs.CLI_HELP_DOCS.value + "#manage"

2. Broad Exception Handling

Multiple locations use bare except: which can hide errors:

src/pieces/command_interface/manage_commands/utils.py:26

except (subprocess.CalledProcessError, FileNotFoundError, OSError):
    return None

This is good! But other places need similar specific exception handling.

src/pieces/command_interface/manage_commands/update_command.py:239

except Exception as e:
    Settings.logger.error(f"Update failed: {e}")
    return False

Should catch specific exceptions like subprocess.CalledProcessError.

3. Windows PATH Security Issue (install_pieces_cli.ps1:164)

The PATH manipulation lacks validation:

$newPath = "$InstallDir;$currentPath"
[Environment]::SetEnvironmentVariable("Path", $newPath, [EnvironmentVariableTarget]::User)

Issues:

  • No check if PATH length exceeds Windows limit (2048 chars)
  • No validation that $InstallDir exists
  • No check for duplicate entries

Fix Required:

# Validate install directory exists
if (-not (Test-Path $InstallDir)) {
    Write-Error "Installation directory does not exist: $InstallDir"
    return
}

# Check PATH length
if (($newPath.Length) -gt 2000) {
    Write-Warning "PATH would exceed safe length. Please manually add: $InstallDir"
    return
}

# Check for duplicates
if ($currentPath -notlike "*$InstallDir*") {
    [Environment]::SetEnvironmentVariable("Path", $newPath, [EnvironmentVariableTarget]::User)
}

4. Function Complexity

The _detect_installation_source function in utils.py is 390 lines long! This should be refactored into smaller functions:

  • _detect_pip_installation()
  • _detect_homebrew_installation()
  • _detect_installer_installation()
  • etc.

5. Missing Error Context

When operations fail, we often don't provide enough context:

src/pieces/command_interface/manage_commands/update_command.py:203

Settings.logger.error(f"Failed to update pieces-cli")

Should include:

  • Current version
  • Target version
  • Installation method
  • Actual error message

6. Test Improvements Needed

While test coverage is good, some edge cases are missing:

  • PATH corruption scenarios
  • Network timeout handling
  • Partial update failures
  • Cross-platform compatibility

Priority Order for Fixes

  1. 🔴 Fill in empty URL constants - Blocking issue
  2. 🟡 Fix Windows PATH validation - Security issue
  3. 🟡 Improve exception handling - Reliability issue
  4. 🟢 Refactor complex functions - Maintainability
  5. 🟢 Add missing test cases - Quality

Once these are addressed, this PR will be ready to merge and unblock PR #360.

@tsavo-at-pieces
Copy link
Contributor

✅ Verification of Implementation Status

I've verified the current state of the PR and can confirm:

Security Measures ✓

Code Implementation ✓

  • Manage commands are properly implemented and modularized:
    • manage_group.py: Main command group registration
    • update_command.py: Comprehensive update logic for all package managers
    • utils.py: Shared utilities with robust installation detection
  • Extensive test coverage: 560 lines of tests in test_update_command.py
  • Installation detection supports: installer, homebrew, pip, chocolatey, winget

Minor Issues Remaining

  1. Empty URL constants in src/pieces/urls.py (lines 80-85):

    CLI_UPDATE_DOCS = ""
    CLI_MANAGE_DOCS = ""

    These should be populated before merge (though I couldn't find Issue add kiro mcp #362 tracking this).

  2. Commented installer method needs re-enabling once security enhancements from Issue Security Enhancement Implementation: Address Supply Chain Attack Vulnerabilities #361 are implemented.

Integration with PR #360

The pieces manage update command referenced in PR #360's error messages is properly implemented here, making this a true blocking dependency.

Recommendation: This PR is ready to merge with the understanding that:

  1. Documentation URLs will be added in a follow-up
  2. Installer script method will be re-enabled after security enhancements

@bishoy-at-pieces bishoy-at-pieces force-pushed the feature/cross-platform-installation-scripts branch from 0927a8f to ae513cd Compare August 28, 2025 12:08
@bishoy-at-pieces bishoy-at-pieces force-pushed the feature/cross-platform-installation-scripts branch from ae513cd to 9f0c329 Compare August 28, 2025 12:18
Fixed two test failures in TestExecutableLocation:
- test_finds_pieces_in_installer_structure
- test_finds_pieces_relative_to_python

The issue was that these tests were trying to patch the 'exists' method
directly on Path objects using patch.object(), but Path.exists is read-only.

Changed approach to patch pathlib.Path.exists globally with custom mock
functions that return True only for the specific paths being tested.

Also fixed the __file__ patching in test_finds_pieces_in_installer_structure
to properly patch the module-level __file__ attribute instead of trying
to patch pathlib.Path.__file__ which doesn't exist.

All TestExecutableLocation tests now pass successfully.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants