|
1 | | -# GenAIScript Copilot Instructions |
| 1 | +--- |
| 2 | +Source: .ruler/instructions.md |
| 3 | +--- |
| 4 | +# GenAIScript |
2 | 5 |
|
3 | | -This document provides AI coding agents with essential knowledge for immediate productivity when working with the GenAIScript codebase. |
| 6 | +- Always use the `dev` branch for development or upstream. |
| 7 | +- Use `vitest` to generate tests. Place tests in the `tests` directory. |
4 | 8 |
|
5 | | -## Architecture Overview |
6 | | - |
7 | | -GenAIScript is a TypeScript-based monorepo that enables programmatic assembly of prompts for Large Language Models (LLMs). The repository is organized as follows: |
8 | | - |
9 | | -**Core Packages:** |
10 | | -- `packages/core/` - Core runtime and execution engine |
11 | | -- `packages/cli/` - Command-line interface and tools |
12 | | -- `packages/vscode/` - Visual Studio Code extension |
13 | | -- `packages/web/` - Web-based interface |
14 | | -- `packages/api/` - API definitions and types |
15 | | -- `packages/runtime/` - Runtime environment and execution |
16 | | - |
17 | | -**Development Areas:** |
18 | | -- `genaisrc/` - Main GenAI scripts for project automation |
19 | | -- `samples/` - Example projects demonstrating usage patterns |
20 | | -- `docs/` - Documentation site built with Astro |
21 | | -- `examples/` - Additional examples and demonstrations |
22 | | - |
23 | | -## Development Patterns |
24 | | - |
25 | | -### GenAI Script Pattern |
26 | | - |
27 | | -GenAI scripts follow a consistent structure using TypeScript/JavaScript: |
28 | | - |
29 | | -```typescript |
30 | | -script({ |
31 | | - model: "large", |
32 | | - system: ["system", "system.files"], |
33 | | - tools: ["fs", "md"] |
34 | | -}) |
35 | | - |
36 | | -def("FILES", env.files) |
37 | | -$`Analyze FILES and extract insights` |
| 9 | +```files |
| 10 | + src/code.ts |
| 11 | + test/code.test.ts |
38 | 12 | ``` |
39 | 13 |
|
40 | | -**Key Conventions:** |
41 | | -- Scripts use `.genai.mts` extension for TypeScript modules |
42 | | -- Scripts use `.genai.mjs` extension for JavaScript modules |
43 | | -- Place scripts in `genaisrc/` directory |
44 | | -- Use `script()` function to configure execution parameters |
45 | | -- Use `def()` to define reusable variables |
46 | | -- Use template literals with `$\`\`` for prompts |
| 14 | +- Generate TypeScript (esm, async/await) code when possible, not JavaScript. |
| 15 | +- Filenames should be lowercase, with no spaces or special characters. |
47 | 16 |
|
48 | | -### TypeScript Usage |
| 17 | +## Building and testing |
49 | 18 |
|
50 | | -- All core packages use TypeScript 5.8.3 |
51 | | -- Configuration via `tsconfig.json` files with shared base configs |
52 | | -- ESM modules throughout the codebase |
53 | | -- Strict type checking enabled |
54 | | -- Use catalog references for consistent dependency versions |
| 19 | +- Use `pnpm build` to build the project |
| 20 | +- Use `pnpm -r test` to run all tests |
| 21 | +- Use `pnpm test:core` for fast unit tests. It uses `vitest` to run tests. |
55 | 22 |
|
56 | | -## Build System |
| 23 | +## Debug logging |
57 | 24 |
|
58 | | -The project uses pnpm workspaces with Turbo for orchestration. |
| 25 | +If you need to add debug logging, use `genaiscriptDebug("category")` to instantiate a new debug logger in a file |
| 26 | +where `category` is a descriptive name for the module or feature. |
59 | 27 |
|
60 | | -### Essential Commands |
61 | | - |
62 | | -**Build Commands:** |
63 | | -```bash |
64 | | -pnpm run build:cli # Build CLI without docs/vscode |
65 | | -pnpm run build # Full build with Turbo |
66 | | -pnpm run build:ci # CI build excluding docs |
| 28 | +```ts |
| 29 | +import { genaiscriptDebug } from "@genaiscript"; |
| 30 | +const debug = genaiscriptDebug("category"); |
67 | 31 | ``` |
68 | 32 |
|
69 | | -**Testing Commands:** |
70 | | -```bash |
71 | | -pnpm run test:core # Core package tests |
72 | | -pnpm run test:samples # Sample project tests |
73 | | -pnpm run test:scripts # Script validation tests |
74 | | -``` |
| 33 | +To enable debug logging, add `DEBUG=genaiscript:category` to the environment variables when running the script. |
75 | 34 |
|
76 | | -**Development Commands:** |
77 | 35 | ```bash |
78 | | -pnpm run genai <script> # Run GenAI scripts |
79 | | -pnpm run serve # Start development servers |
80 | | -pnpm run lint:fix # Fix linting issues |
| 36 | +DEBUG=genaiscript:category pnpm test:core |
81 | 37 | ``` |
82 | | - |
83 | | -### Workspace Structure |
84 | | - |
85 | | -The `pnpm-workspace.yaml` defines: |
86 | | -- `packages/*` - Core packages |
87 | | -- `docs` - Documentation site |
88 | | -- `samples/*` - Example projects |
89 | | -- `tools/*` - Build and development tools |
90 | | - |
91 | | -## Integration Points |
92 | | - |
93 | | -### LLM Providers |
94 | | - |
95 | | -GenAIScript supports multiple LLM providers: |
96 | | -- OpenAI (GPT models) |
97 | | -- Azure OpenAI |
98 | | -- GitHub Models |
99 | | -- Ollama (local models) |
100 | | -- Anthropic Claude |
101 | | -- Google Gemini |
102 | | - |
103 | | -### External Services |
104 | | - |
105 | | -- **Azure AI Services** - Content safety, document intelligence |
106 | | -- **GitHub Integration** - Issues, PRs, code scanning |
107 | | -- **Container Support** - Docker, Pyodide for Python |
108 | | -- **File Format Support** - PDF, DOCX, CSV, XLSX, images |
109 | | - |
110 | | -### Tools and Agents |
111 | | - |
112 | | -Common tools available in scripts: |
113 | | -- `fs` - File system operations |
114 | | -- `md` - Markdown processing |
115 | | -- `git` - Git operations |
116 | | -- `github` - GitHub API access |
117 | | -- `agent_*` - Specialized agents (fs, docs, web, etc.) |
118 | | - |
119 | | -## Essential References |
120 | | - |
121 | | -### Key Configuration Files |
122 | | - |
123 | | -- `package.json` - Root package with 100+ npm scripts |
124 | | -- `turbo.json` - Build orchestration configuration |
125 | | -- `pnpm-workspace.yaml` - Workspace definitions |
126 | | -- `genaiscript.config.json` - GenAI script configuration |
127 | | - |
128 | | -### Important Directories |
129 | | - |
130 | | -- `genaisrc/linters/` - Linting and validation scripts |
131 | | -- `samples/sample/genaisrc/` - Comprehensive script examples |
132 | | -- `packages/core/src/` - Core runtime implementation |
133 | | -- `.github/instructions/` - Additional AI development guides |
134 | | - |
135 | | -### Script Examples |
136 | | - |
137 | | -- `genaisrc/linters.genai.mts` - Code linting and review |
138 | | -- `samples/sample/genaisrc/summarize.genai.mjs` - File summarization |
139 | | -- `samples/sample/genaisrc/code-review.genai.js` - Code review automation |
140 | | -- `samples/sample/genaisrc/pr-review.genai.mjs` - Pull request analysis |
141 | | - |
142 | | -### Development Workflow |
143 | | - |
144 | | -1. **Setup**: `pnpm install` to install dependencies |
145 | | -2. **Build**: `pnpm run build:cli` for core functionality |
146 | | -3. **Test**: `pnpm run test:core` to validate changes |
147 | | -4. **Scripts**: `pnpm run genai <script-name>` to run GenAI scripts |
148 | | -5. **Lint**: `pnpm run lint:fix` to maintain code quality |
149 | | - |
150 | | -The codebase emphasizes TypeScript, ESM modules, and modern JavaScript patterns throughout. All development follows the established patterns in the samples directory. |
0 commit comments