|
| 1 | +# Context Examples |
| 2 | + |
| 3 | +Examples demonstrating the Auggie SDK's context modes and AI-powered code analysis. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **Node.js 18+** - Required to run the examples |
| 8 | +2. **Auggie CLI** - Required for FileSystem Context examples |
| 9 | + ```bash |
| 10 | + npm install -g @augmentcode/auggie |
| 11 | + ``` |
| 12 | +3. **Authentication** - Required for all examples |
| 13 | + ```bash |
| 14 | + auggie login |
| 15 | + ``` |
| 16 | + This creates a session file at `~/.augment/session.json` with your API token. |
| 17 | + |
| 18 | + Alternatively, you can set environment variables: |
| 19 | + ```bash |
| 20 | + export AUGMENT_API_TOKEN=your_token_here |
| 21 | + export AUGMENT_API_URL=https://staging-shard-0.api.augmentcode.com/ |
| 22 | + ``` |
| 23 | + |
| 24 | +## Setup |
| 25 | + |
| 26 | +Install dependencies: |
| 27 | + |
| 28 | +```bash |
| 29 | +cd examples/typescript-sdk/context |
| 30 | +npm install |
| 31 | +``` |
| 32 | + |
| 33 | +## Examples |
| 34 | + |
| 35 | +### [Direct Context](./direct-context/) |
| 36 | +API-based indexing with semantic search and AI Q&A. |
| 37 | + |
| 38 | +**Run it:** |
| 39 | +```bash |
| 40 | +npm run direct-context |
| 41 | +``` |
| 42 | + |
| 43 | +### [FileSystem Context](./filesystem-context/) |
| 44 | +Local directory search via MCP protocol. |
| 45 | + |
| 46 | +**Prerequisites:** |
| 47 | +- Auggie CLI must be installed and in your PATH |
| 48 | +- Authentication via `auggie login` or `AUGMENT_API_TOKEN` environment variable |
| 49 | +- A `.gitignore` or `.augmentignore` file in the workspace directory to exclude `node_modules/` and other large directories |
| 50 | + |
| 51 | +**Important:** The FileSystem Context indexes all files in the workspace directory. To avoid timeouts when indexing large directories (like `node_modules/`), make sure you have a `.gitignore` or `.augmentignore` file that excludes them. The auggie CLI respects both `.gitignore` and `.augmentignore` patterns during indexing. |
| 52 | + |
| 53 | +**Run it:** |
| 54 | +```bash |
| 55 | +npm run filesystem-context |
| 56 | +``` |
| 57 | + |
| 58 | +### [File Search Server](./file-search-server/) |
| 59 | +REST API for semantic file search with AI summarization. |
| 60 | + |
| 61 | +**Prerequisites:** Auggie CLI must be installed and in your PATH. |
| 62 | + |
| 63 | +**Run it:** |
| 64 | +```bash |
| 65 | +npm run file-search-server [workspace-directory] |
| 66 | +``` |
| 67 | + |
| 68 | +Then query the API: |
| 69 | +```bash |
| 70 | +curl "http://localhost:3000/search?q=typescript" |
| 71 | +``` |
| 72 | + |
| 73 | +### [Prompt Enhancer Server](./prompt-enhancer-server/) |
| 74 | +HTTP server that enhances prompts with codebase context. |
| 75 | + |
| 76 | +**Prerequisites:** Auggie CLI must be installed and in your PATH. |
| 77 | + |
| 78 | +**Run it:** |
| 79 | +```bash |
| 80 | +npm run prompt-enhancer-server [workspace-directory] |
| 81 | +``` |
| 82 | + |
| 83 | +Then enhance prompts: |
| 84 | +```bash |
| 85 | +curl -X POST http://localhost:3001/enhance \ |
| 86 | + -H "Content-Type: application/json" \ |
| 87 | + -d '{"prompt": "fix the login bug"}' |
| 88 | +``` |
| 89 | + |
| 90 | +### [GitHub Action Indexer](./github-action-indexer/) |
| 91 | +Index GitHub repositories for semantic search. |
| 92 | + |
| 93 | +This example has its own package.json and dependencies. |
| 94 | + |
| 95 | +**Setup:** |
| 96 | +```bash |
| 97 | +npm run github-indexer:install |
| 98 | +``` |
| 99 | + |
| 100 | +**Run it:** |
| 101 | +```bash |
| 102 | +npm run github-indexer:index |
| 103 | +npm run github-indexer:search |
| 104 | +``` |
| 105 | + |
| 106 | +See [github-action-indexer/README.md](./github-action-indexer/README.md) for more details. |
| 107 | + |
| 108 | +## Running Examples Directly with tsx |
| 109 | + |
| 110 | +You can also run examples directly without installing dependencies: |
| 111 | + |
| 112 | +```bash |
| 113 | +npx tsx direct-context/index.ts |
| 114 | +npx tsx filesystem-context/index.ts |
| 115 | +npx tsx file-search-server/index.ts . |
| 116 | +npx tsx prompt-enhancer-server/index.ts . |
| 117 | +``` |
| 118 | + |
| 119 | +Note: This will download dependencies on each run. For better performance, use `npm install` first. |
| 120 | + |
| 121 | +## Troubleshooting |
| 122 | + |
| 123 | +### MCP Timeout in FileSystem Context |
| 124 | + |
| 125 | +**Problem:** The FileSystem Context example times out during indexing. |
| 126 | + |
| 127 | +**Cause:** The workspace directory contains too many files (e.g., `node_modules/` with 45,000+ files). |
| 128 | + |
| 129 | +**Solution:** Create a `.gitignore` or `.augmentignore` file in the workspace directory to exclude large directories: |
| 130 | + |
| 131 | +```bash |
| 132 | +# .gitignore or .augmentignore |
| 133 | +node_modules/ |
| 134 | +dist/ |
| 135 | +*.log |
| 136 | +.DS_Store |
| 137 | +``` |
| 138 | + |
| 139 | +The auggie CLI respects both `.gitignore` and `.augmentignore` patterns and will skip excluded files during indexing. |
| 140 | + |
| 141 | +### Authentication Errors |
| 142 | + |
| 143 | +**Problem:** `Error: API key is required for searchAndAsk()` |
| 144 | + |
| 145 | +**Cause:** The SDK cannot find your authentication credentials. |
| 146 | + |
| 147 | +**Solution:** Run `auggie login` to authenticate, or set the `AUGMENT_API_TOKEN` and `AUGMENT_API_URL` environment variables. |
| 148 | + |
| 149 | + |
0 commit comments