Skip to content

Commit f905d29

Browse files
committed
getting started + broken links
1 parent 5802ac3 commit f905d29

File tree

4 files changed

+92
-99
lines changed

4 files changed

+92
-99
lines changed
Lines changed: 76 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,100 @@
11
---
22
title: Getting Started with Code2Prompt
3-
description: A step-by-step guide to installing and running Code2Prompt for the first time
3+
description: A comprehensive tutorial introducing Code2Prompt's core functionality and its use across CLI, SDK, and MCP integrations.
44
---
55

66
import { Aside } from "@astrojs/starlight/components";
77
import { Tabs, TabItem } from "@astrojs/starlight/components";
8-
9-
Welcome to Code2Prompt! This guide will help you get started with installing and running Code2Prompt for the first time.
10-
11-
## Installation
12-
13-
Check out the [installation instructions](/docs/how_to/install)
14-
15-
## Using Code2Prompt
16-
17-
Generate a prompt from a codebase directory:
18-
19-
```sh
20-
code2prompt path/to/codebase
21-
```
22-
23-
Use a custom Handlebars template file:
24-
25-
```sh
26-
code2prompt path/to/codebase --template path/to/template.hbs
27-
```
28-
29-
Filter files using glob patterns:
30-
31-
```sh
32-
code2prompt path/to/codebase --include="*.rs,*.toml"
33-
```
34-
35-
Exclude files using glob patterns:
36-
37-
```sh
38-
code2prompt path/to/codebase --exclude="*.txt,*.md"
39-
```
40-
41-
Display the token count of the generated prompt:
42-
43-
```sh
44-
code2prompt path/to/codebase --tokens
8+
import { Card, CardGrid } from "@astrojs/starlight/components";
9+
10+
<Card title="Tutorial Overview">
11+
Welcome to Code2Prompt! This tutorial provides a comprehensive introduction to
12+
using Code2Prompt to generate AI-ready prompts from your codebases. We'll
13+
explore its core functionality and demonstrate its usage across different
14+
integration methods: Command Line Interface (CLI), Software Development Kit
15+
(SDK), and Model Context Protocol (MCP).
16+
</Card>
17+
18+
## What is Code2Prompt?
19+
20+
Code2Prompt is a versatile tool designed to bridge the gap between your codebase and Large Language Models (LLMs). It intelligently extracts relevant code snippets, applies powerful filtering, and formats the information into structured prompts optimized for LLM consumption. This simplifies tasks like code documentation, bug detection, refactoring, and more.
21+
22+
Code2Prompt offers different integration points:
23+
24+
<Tabs>
25+
<TabItem label="Core" icon="seti:rust">
26+
A core rust library that provides the foundation for code ingestion and
27+
prompt
28+
</TabItem>
29+
<TabItem label="CLI" icon="seti:powershell">
30+
A user-friendly command-line interface for quick prompt generation. Ideal
31+
for interactive use and one-off tasks.
32+
</TabItem>
33+
<TabItem label="SDK" icon="seti:python">
34+
A powerful Software Development Kit (SDK) for seamless integration into your
35+
Python projects. Perfect for automating prompt generation within larger
36+
workflows.
37+
</TabItem>
38+
<TabItem label="MCP" icon="seti:db">
39+
A Model Context Protocol (MCP) server for advanced integration with LLM
40+
agents. Enables sophisticated, real-time interactions with your codebase.
41+
</TabItem>
42+
</Tabs>
43+
44+
## 📥 Installation
45+
46+
For detailed installation instructions for all methods (CLI, SDK, MCP), please refer to the comprehensive [Installation Guide](/docs/how_to/install).
47+
48+
## 🏁 Generating Prompts: A CLI Example
49+
50+
Let's start with a simple example using the CLI. Create a sample project:
51+
52+
```bash
53+
mkdir -p my_project/{src,tests}
54+
touch my_project/src/main.rs my_project/tests/test_1.rs
55+
echo 'fn main() { println!("Hello, world!"); }' > my_project/src/main.rs
4556
```
4657

47-
Specify a tokenizer for token count:
58+
Now, generate a prompt:
4859

49-
```sh
50-
code2prompt path/to/codebase --tokens --encoding=p50k
60+
```bash
61+
code2prompt my_project
5162
```
5263

53-
Supported tokenizers: `cl100k`, `p50k`, `p50k_edit`, `r50k_bas`.
64+
This copies a prompt to your clipboard. You can customize this:
5465

55-
<Aside>See [Tokenizers](../explanations/tokenizers) for more details</Aside>
66+
- **Filtering:** `code2prompt my_project --include="*.rs" --exclude="tests/*"` (includes only `.rs` files, excludes `tests` directory)
67+
- **Output File:** `code2prompt my_project --output-file=my_prompt.txt`
68+
- **JSON Output:** `code2prompt my_project -O json` (structured JSON output)
69+
- **Custom Templates:** `code2prompt my_project -t my_template.hbs` (requires creating `my_template.hbs`)
5670

57-
Save the generated prompt to an output file:
71+
See the [Learn Context Filtering](/docs/tutorials/learn_filters) and [Learn Handlebar Templates](/docs/tutorials/learn_templates) tutorials to learn more advanced usages.
5872

59-
```sh
60-
code2prompt path/to/codebase --output-file=output.txt
61-
```
73+
## 🐍 SDK Integration (Python)
6274

63-
Print output as JSON:
75+
For programmatic control, use the Python SDK:
6476

65-
```sh
66-
code2prompt path/to/codebase -O json
67-
```
77+
```python
78+
from code2prompt_rs import Code2Prompt
6879

69-
The JSON output will have the following structure:
70-
71-
```json
72-
{
73-
"prompt": "<Generated Prompt>",
74-
"directory_name": "codebase",
75-
"token_count": 1234,
76-
"model_info": "ChatGPT models, text-embedding-ada-002",
77-
"files": []
80+
config = {
81+
"path": "my_project",
82+
"include_patterns": ["*.rs"],
83+
"exclude_patterns": ["tests/*"],
7884
}
79-
```
8085

81-
Generate a Git commit message (for staged files):
82-
83-
```sh
84-
code2prompt path/to/codebase --diff --template templates/write-git-commit.hbs
86+
c2p = Code2Prompt(**config)
87+
prompt = c2p.generate_prompt()
88+
print(prompt)
8589
```
8690

87-
Generate a Pull Request with branch comparing (for staged files):
88-
89-
```sh
90-
code2prompt path/to/codebase --git-diff-branch 'main, development' --git-log-branch 'main, development' --template templates/write-github-pull-request.hbs
91-
```
91+
This requires installing the SDK (`pip install code2prompt_rs`). Refer to the SDK documentation for more details.
9292

93-
Add line numbers to source code blocks:
93+
## 🤖 MCP Server Integration (Advanced)
9494

95-
```sh
96-
code2prompt path/to/codebase --line-number
97-
```
95+
For advanced integration with LLM agents, run the `code2prompt` MCP server (see the installation guide for details). This allows agents to request code context dynamically. This is an advanced feature, and further documentation is available on the project's website.
9896

99-
Disable wrapping code inside markdown code blocks:
100-
101-
```sh
102-
code2prompt path/to/codebase --no-codeblock
103-
```
104-
105-
Include hidden files and directories:
106-
107-
```sh
108-
code2prompt path/to/codebase --hidden
109-
```
110-
111-
Skip .gitignore rules:
112-
113-
```sh
114-
code2prompt path/to/codebase --no-ignore
115-
```
97+
<Card title="Next Steps">
98+
Explore the advanced tutorials and documentation to master Code2Prompt's
99+
capabilities and integrate it into your workflows.
100+
</Card>

website/src/content/docs/docs/tutorials/learn_filters.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import { Card } from "@astrojs/starlight/components";
1313

1414
Glob patterns work similarly to tools like `tree` or `grep`,
1515
providing powerful filtering capabilities. Check out the [detailed
16-
explanation](../explanations/glob_pattern_tool) for more information.
16+
explanation](/docs/explanations/glob_patterns) for more information.
1717

1818
---
1919

2020
## Prerequisites
2121

22-
Ensure you have `code2prompt` installed. If you havent installed it yet, refer to the [Installation Guide](/docs/how_to/install).
22+
Ensure you have `code2prompt` installed. If you haven't installed it yet, refer to the [Installation Guide](/docs/how_to/install).
2323

2424
---
2525

@@ -35,7 +35,7 @@ Glob patterns allow you to specify rules for filtering files and directories.
3535

3636
## Setting Up the Environment
3737

38-
To practice with glob patterns, lets create a sample folder structure with some files.
38+
To practice with glob patterns, let's create a sample folder structure with some files.
3939

4040
### Bash Script to Generate the Test Structure
4141

website/src/content/docs/docs/vision.mdx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
title: Code2Prompt's Vision
33
description: Discover the vision behind Code2Prompt and how it enhances LLM interactions with code.
44
---
5-
import { Card } from '@astrojs/starlight/components';
6-
import { Aside } from '@astrojs/starlight/components';
75

8-
<Card title="Purpose 🎯">`code2prompt` was created to help developers and AI agents interact with codebases more effectively.</Card>
6+
import { Card } from "@astrojs/starlight/components";
7+
import { Aside } from "@astrojs/starlight/components";
8+
9+
<Card title="Purpose 🎯">
10+
`code2prompt` was created to help developers and AI agents interact with
11+
codebases more effectively.
12+
</Card>
913

1014
## The Problem 🚩
1115

@@ -24,7 +28,7 @@ We believe that planning and reasoning can be achieved by human or AI agents wit
2428
The thumb rule would be:
2529

2630
<Aside type="tip">
27-
> provide as little context as possible, but as much as necessary
31+
> provide as little context as possible, but as much as necessary
2832
</Aside>
2933
3034
This is practically difficult to achieve, especially for large codebases. However, `code2prompt` is a simple tool that can help developers and AI agents ingest codebase more effectively.
@@ -35,7 +39,11 @@ You can understand how `code2prompt` is designed to tackles these challenges in
3539

3640
## Architecture ⛩️
3741

38-
<img src="/src/assets/architecture.svg" alt="Architecture of code2prompt" style="width: 75%;" />
42+
<img
43+
src="/assets/images/architecture.svg"
44+
alt="Architecture of code2prompt"
45+
style="width: 75%;"
46+
/>
3947

4048
`code2prompt` is designed in a modular way, allowing for easy integration into various workflows. It can be used as a core library, a command line interface (CLI), a software development kit (SDK), or even as a Model Context Protocol (MCP) server.
4149

0 commit comments

Comments
 (0)