Metadata-Version: 2.4
Name: promptv
Version: 0.1.6
Summary: A comprehensive developer-first prompt management tool with git-like version control
Author: Thompson Wong
Author-email: Thompson Wong <thompsonwong@labs21.dev>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/thompson0012/promptv
Project-URL: Repository, https://github.com/thompson0012/promptv
Keywords: prompt,management,tool,git-like,version,control,developer-first
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.3.1
Requires-Dist: pydantic>=2.12.5
Requires-Dist: jinja2>=3.1.4
Requires-Dist: pyyaml>=6.0.2
Requires-Dist: rich>=13.9.4
Requires-Dist: tiktoken>=0.8.0
Requires-Dist: textual>=0.84.0
Dynamic: author
Dynamic: license-file
Dynamic: requires-python

This project sponsored by [DLS by LABs21](https://dls.labs21.dev/?utm_source=github&utm_medium=banner&utm_campaign=promptv)

<img width="289" height="51" alt="image" src="https://github.com/user-attachments/assets/5eef16c4-a4a4-413f-bc3d-3e2c35d50cc5" />

If you think this project is helpful, treat me a coffee.

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://buymeacoffee.com/fdatwlnur)

=================

WARNING: This is a pre-release version of promptv. Expect breaking changes.

# promptv - Prompt Versioning CLI Tool & Environment Variable Management Tool

A command-line interface tool for managing prompts locally with versioning support.

## Features

- Local prompt management with version control
- Cloud storage support with API key and project ID
- Markdown format support for all prompts
- Automatic directory creation on first run
- Full version history tracking
- Multiple prompt operations (create, update, retrieve, list, delete)
- Variable substitution with Jinja2 templates
- Tag/label system for easy version references
- Cost estimation for LLM API calls
- API testing with LLM integration
- Project-based organization for prompts and secrets
- Git-style diff visualization

## Installation

```bash
# Clone the repository
git clone <repository-url>
cd promptv

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install the package
pip install promptv
```

## Configuration

### First-time Setup

Initialize promptv to create the required directory structure:

```bash
promptv init
```

This creates:

```
~/.promptv/
├── .config/
│   ├── config.yaml      # User configuration
│   └── pricing.yaml     # LLM pricing data (customizable)
├── .secrets/
│   └── secrets.json     # API keys and secrets
└── prompts/             # Saved prompts
```

**Note:** promptv will automatically initialize on first command if not already done.

On first run, promptv creates `~/.promptv/.config/config.yaml` with default settings.

### Execution Modes

**Local Mode (default)**: Stores all data in `~/.promptv/`

```yaml
execution:
  mode: "local"
```

### LLM Provider Configuration

Configure API base URLs for different LLM providers:

```yaml
llm_providers:
  openai:
    api_base_url: "https://api.openai.com/v1"
    default_model: "gpt-4"
  anthropic:
    api_base_url: "https://api.anthropic.com/v1"
    default_model: "claude-3-5-sonnet-20241022"
  custom:
    api_base_url: "http://localhost:8000/v1"
    default_model: "custom-model"
```

### Customizing LLM Pricing

You can customize LLM pricing by editing `~/.promptv/.config/pricing.yaml`. This allows you to:

- Update pricing for existing models
- Add new models
- Adjust pricing for local/custom models

The file is copied from package resources during initialization and never auto-updated.

## Usage

### Commands

0. **init** - Initialize promptv directory structure

   ```bash
   promptv init                    # Create directory structure
   promptv init --force            # Delete and recreate (WARNING: destructive!)
   ```

1. **commit** - Save a prompt file with a specific name

   ```bash
   promptv commit --source file.md --name prompt-name                    # Saves to /default project
   promptv commit --source file.md --name prompt-name -m "Update message"
   promptv commit --source file.md --name prompt-name --tag prod
   promptv commit --source file.md --name prompt-name --project my-app   # Saves to /my-app project
   ```

2. **set** - Set/update a prompt with the given name

   ```bash
   promptv set prompt-name --file file.txt                 # Saves to /default project
   promptv set prompt-name --content "Prompt content"
   echo "Content" | promptv set prompt-name
   promptv set prompt-name --file file.txt --project my-app  # Saves to /my-app project
   ```

3. **edit** - Edit a prompt directly in your terminal editor

   ```bash
   promptv edit prompt-name
   promptv edit prompt-name --version 2
   promptv edit prompt-name -m "Updated instructions"
   promptv edit prompt-name --editor vim
   ```

4. **get** - Retrieve a specific version of a prompt

   ```bash
   promptv get prompt-name --version latest
   promptv get prompt-name --version 1
   promptv get prompt-name --label prod

   # Variable substitution - space-separated key=value pairs
   promptv get prompt-name --var "name=Alice count=5"

   # Multiple --var flags also supported
   promptv get prompt-name --var key1=val1 --var key2=val2
   ```

5. **list** - List all versions and metadata for a prompt

   ```bash
   promptv list prompt-name
   ```

6. **remove** - Remove one or more prompts

   ```bash
   promptv remove prompt-name
   promptv remove prompt1 prompt2 prompt3
   promptv remove prompt-name --yes  # Skip confirmation
   ```

7. **tags** - Manage tags/labels for versions

   ```bash
   promptv tag create prompt-name tag-name --version 1
   promptv tag create prompt-name tag-name --project my-app
   promptv tag list prompt-name
   promptv tag list prompt-name --project my-app
   promptv tag show prompt-name tag-name --project my-app
   promptv tag delete prompt-name tag-name
   promptv tag delete prompt-name tag-name --project my-app
   ```

8. **secrets** - Manage API keys and secrets securely

   ```bash
   # Set provider API key (validated against supported providers)
   promptv secrets set openai --provider
   promptv secrets set anthropic --provider

   # Set generic secret (default project)
   promptv secrets set DATABASE_URL
   promptv secrets set MY_API_KEY

   # Set project-scoped secret
   promptv secrets set DATABASE_URL --project my-app
   promptv secrets set REDIS_URL --project moonshoot

   # Get secret
   promptv secrets get openai --provider          # Shows masked (last 4 chars)
   promptv secrets get DATABASE_URL               # Shows full value
   promptv secrets get API_KEY --project my-app   # Get from specific project

   # List all secrets
   promptv secrets list                           # All secrets
   promptv secrets list --project my-app          # Filter by project

   # Delete secret
   promptv secrets delete openai --provider
   promptv secrets delete DATABASE_URL --project my-app --yes

   # Activate secrets in shell (like 'source .env')
   source <(promptv secrets activate --project moonshoot)
   eval "$(promptv secrets activate --project moonshoot)"
   ```

9. **diff** - Compare two versions of a prompt

   ```bash
   promptv diff prompt-name v1 v2
   promptv diff prompt-name --label prod --label staging
   promptv diff prompt-name v1 v2 --format unified
   promptv diff prompt-name v1 v2 --format side-by-side  # Shows --, ++, ~~ markers
   ```

10. **estimate-cost** - Estimate cost of running a prompt

   ```bash
   promptv estimate-cost prompt-name --model gpt-4 --provider openai
   promptv estimate-cost prompt-name --output-tokens 1000
   ```

11. **test** - Run API tests with LLM integration
    ```bash
    promptv test --suite test-suite.json
    ```

## Secrets Management

promptv provides secure storage for API keys and generic secrets:

### Provider API Keys

Store API keys for supported LLM providers (openai, anthropic, cohere, etc.):

```bash
# Set provider API key (validated)
promptv secrets set openai --provider
promptv secrets set anthropic --provider

# Get provider key (shows last 4 chars only)
promptv secrets get openai --provider

# Delete provider key
promptv secrets delete openai --provider
```

### Generic Secrets

Store any secrets with optional project scoping:

```bash
# Default project
promptv secrets set DATABASE_URL
promptv secrets set API_KEY

# Project-scoped
promptv secrets set DATABASE_URL --project my-app
promptv secrets set REDIS_URL --project moonshoot

# Retrieve secrets
promptv secrets get DATABASE_URL
promptv secrets get API_KEY --project my-app
```

### Listing Secrets

```bash
# List all secrets
promptv secrets list

# Example output:
# Provider API Keys:
#   ✓ openai
#   ✓ anthropic
#
# Project Secrets:
#   default:
#     ✓ DATABASE_URL
#     ✓ API_KEY
#
#   my-app:
#     ✓ DB_PASSWORD
#     ✓ REDIS_URL

# Filter by project
promptv secrets list --project my-app
```

### Activating Secrets in Shell

Similar to `source .env`, you can export all secrets for a project to your current shell:

```bash
# Basic usage - activate default project
source <(promptv secrets activate)

# Activate specific project
source <(promptv secrets activate --project moonshoot)

# Alternative syntax with eval
eval "$(promptv secrets activate --project moonshoot)"

# Exclude provider API keys
source <(promptv secrets activate --project moonshoot --no-include-providers)
```

**Shell Function Helper** (add to `~/.bashrc` or `~/.zshrc`):

```bash
# Convenient alias for activating secrets
promptv-activate() {
    eval "$(promptv secrets activate --project ${1:-default})"
}

# Usage:
promptv-activate                # Activate default project
promptv-activate moonshoot      # Activate moonshoot project
```

**How it works:**

- Exports all secrets for the specified project as environment variables
- Provider API keys are exported as `PROVIDER_API_KEY` (e.g., `OPENAI_API_KEY`)
- Works like `source .env` but pulls from promptv's secure storage
- Changes only affect the current shell session

**Output formats:**

```bash
# Shell format (default) - includes comment
promptv secrets activate --project moonshoot

# Export statements only (no comments)
promptv secrets activate --project moonshoot --format export

# JSON format for other tools
promptv secrets activate --project moonshoot --format json
```

### Security

- All secrets are stored in `~/.promptv/.secrets/secrets.json`
- File has restrictive permissions (0600 - owner read/write only)
- Secrets directory has restrictive permissions (0700 - owner access only)
- Provider API keys show only last 4 characters when retrieved

## Project Organization

**Default Behavior:** All prompts are automatically saved to the `default` project unless you specify otherwise.

```bash
# These commands save to ~/.promptv/prompts/default/
promptv commit --source prompt.md --name my-prompt
promptv set my-prompt -c "Content here"
promptv tag create my-prompt prod

# These commands save to ~/.promptv/prompts/my-app/
promptv commit --source prompt.md --name my-prompt --project my-app
promptv set my-prompt -c "Content here" --project my-app
promptv tag create my-prompt prod --project my-app
```

Use project tags to organize prompts and secrets:

```bash
# Set a prompt with project tag
promptv commit --source prompt.md --name my-prompt --project my-app

# Set project-scoped secret
promptv secrets set DATABASE_URL --project my-app

# Get secret for specific project
promptv secrets get DATABASE_URL --project my-app
```

## Variable Substitution

Prompts support Jinja2 template variables:

```markdown
Hello {{ name }},

Welcome to {{ product }}! Your account is ready.

Support: {{ support_email }}
```

Retrieve with variables:

```bash
promptv get welcome-email --var "name=Alice product=MyApp support_email=help@example.com"
```

## API Testing

Create a test suite JSON file:

```json
{
  "name": "greeting-tests",
  "prompt_name": "greeting-prompt",
  "prompt_version": "latest",
  "provider": "openai",
  "model": "gpt-4",
  "test_cases": [
    {
      "name": "test-formal",
      "variables": { "tone": "formal", "name": "Alice" },
      "expected_contains": ["Dear", "Alice"],
      "max_tokens": 100
    }
  ]
}
```

Run tests:

```bash
promptv test --suite tests.json --output results.json
```

## Directory Structure

```
~/.promptv/
├── .config/
│   └── config.yaml          # Configuration file
└── prompts/
    ├── default/             # Default project (auto-created)
    │   └── prompt-name/
    │       ├── metadata.json     # Version metadata
    │       ├── tags.json         # Tag registry
    │       ├── v1.md            # Version 1
    │       ├── v2.md            # Version 2
    │       └── ...
    └── my-app/              # Custom project
        └── prompt-name/
            ├── metadata.json
            ├── tags.json
            └── ...
```

## Diff Visualization

The diff engine supports git-style markers:

- `--` : Deleted lines (red)
- `++` : Added lines (green)
- `~~` : Modified lines (yellow)
- `@@` : Context markers in unified diff

```bash
promptv diff my-prompt 1 2 --format side-by-side
```

## Examples

```bash
# Commit a prompt from a file
promptv commit --source my_prompt.txt --name chatgpt-instructions

# Create/update a prompt with direct content
promptv set summarization-prompt -c "Summarize the following text in 3 sentences."

# Get the latest version of a prompt with variables
promptv get email-template --var "name=John product=Widget"

# Edit a prompt in your editor
promptv edit email-template

# Create a tag for production
promptv tags create email-template prod --version 3

# Get production version
promptv get email-template --label prod

# Compare versions
promptv diff email-template 2 3 --format side-by-side

# List all versions of a prompt
promptv list chatgpt-instructions

# Remove prompts
promptv remove chatgpt-instructions summarization-prompt --yes

# Set API key
promptv secrets set openai_api_key

# Estimate cost
promptv estimate-cost my-prompt --model gpt-4

# Run tests
```

## Development

Run tests:

```bash
pytest
pytest --cov=promptv  # With coverage
```

## License

Apache License, Version 2.0
