npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

copa

v1.1.0

Published

CoPa: Copy File Sources For Prompting and LLM Template Processing

Downloads

99

Readme

npm version License: MIT

CoPa is a simple CLI tool for creating structured prompts for Large Language Models (LLMs) using file references. It offers two main functionalities:

  1. Processing LLM prompt templates with file references
  2. Copying file contents in an LLM-friendly format

Key Features

  • Process template files with dynamic file references
  • Copy an entire folder or a single file to clipboard in a LLM friendly format
  • Support for Git repositories and respect for .gitignore
  • Built-in token counting
  • Easy-to-use CLI utility
  • Inline ignore patterns for fine-grained control over included files

Usage

Use CoPa directly with npx (recommended) or install it globally.

Using npx (Recommended)

Process a template file:

npx copa t prompt.txt

Global Installation (Alternative)

Install CoPa globally:

npm install -g copa

Then use it as:

copa t prompt.txt

Template Syntax

Create a template file (e.g., prompt.txt) using {{@filepath}} to reference files or directories:

Analyze this code:
```
{{@src/main.js}}
```

And its test:
```
{{@tests/main.test.js}}
```

Review the entire 'utils' directory:
```
{{@utils}}
```

Review the 'src' directory, excluding .test.js files:
```
{{@src:-*.test.js}}
```

Review all files in the current directory, excluding markdown files and the 'subdir' directory:
```
{{@.:-*.md,-**/subdir/**}}
```

[new feature description / instructions for the LLM]

Process the template and copy to clipboard:

copa template prompt.txt
# or use the short alias
copa t prompt.txt

Inline Ignore Patterns

You can use inline ignore patterns to exclude specific files or patterns within a directory reference:

{{@directory:-pattern1,-pattern2,...}}

Examples:

  • {{@src:-*.test.js}} includes all files in the 'src' directory except for files ending with '.test.js'
  • {{@.:-*.md,-**/subdir/**}} includes all files in the current directory, excluding markdown files and the 'subdir' directory
  • {{@.:-**/*dir/**,-*.y*}} excludes all files in any directory ending with 'dir' and all files with extensions starting with 'y'

Ignore patterns support:

  • File extensions: -*.js
  • Specific files: -file.txt
  • Directories: -**/dirname/**
  • Glob patterns: -**/*.test.js
  • Hidden files and directories: -.*

Commands

  • t, template <file>: Process a template file

    • Option: -v, --verbose (Display detailed file and token information)
  • c, copy [directory]: Copy files to clipboard (legacy mode)

    • Options:
      • -ex, --exclude <extensions> (Exclude file types)
      • -v, --verbose (List copied files)
      • -f, --file <filePath> (Copy a single file)

Output Format

CoPa uses a format that's easy for LLMs to understand:

Analyze this code:
```
===== src/main.js =====
File contents here...
```

And its test:
```
===== tests/main.test.js =====
...

Use Cases

  • Control over what's included in a prompt
  • Repeatable complex prompts with complex file imports
  • Sharing project wide prompt templates
  • Any task requiring code context from multiple files

Tips

  1. Use relative paths in templates for better portability
  2. Create a "prompts" directory in project root
  3. Create a library of templates for common tasks
  4. Use inline ignore patterns for fine-grained control over included files

Global Configuration

Create ~/.copa to set default exclude patterns:

ignore: jpg,png,gif

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.