@intend-it/core 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +161 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ <div align="center">
2
+ <h1>@intend-it/core</h1>
3
+ <p><strong>AI-Powered Code Generator for the Intend Language</strong></p>
4
+ <p>
5
+ <a href="https://www.npmjs.com/package/@intend-it/core"><img src="https://img.shields.io/npm/v/@intend-it/core.svg" alt="npm version"></a>
6
+ <a href="https://www.npmjs.com/package/@intend-it/core"><img src="https://img.shields.io/npm/dm/@intend-it/core.svg" alt="npm downloads"></a>
7
+ <a href="https://github.com/DRFR0ST/intend/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@intend-it/core.svg" alt="license"></a>
8
+ </p>
9
+ </div>
10
+
11
+ ---
12
+
13
+ ## Overview
14
+
15
+ `@intend-it/core` is the heart of the Intend compiler. It takes parsed AST from `@intend-it/parser` and generates production-ready TypeScript code using AI (Google Gemini or Ollama).
16
+
17
+ ### ✨ Key Features
18
+
19
+ - **🧠 AI Code Generation** - Transforms natural language steps into actual code
20
+ - **🔄 Self-Correction Loop** - Validates output and auto-fixes errors
21
+ - **⚡ Smart Caching (CAS)** - Content-addressable storage for instant rebuilds
22
+ - **🔌 Multi-Provider** - Supports Gemini and Ollama (local)
23
+ - **🛡️ Type-Safe Output** - Generates valid, compilable TypeScript
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install @intend-it/core @intend-it/parser
29
+ # or
30
+ bun add @intend-it/core @intend-it/parser
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Basic Code Generation
36
+
37
+ ```typescript
38
+ import { AICodeGenerator } from "@intend-it/core";
39
+ import { parseToAST } from "@intend-it/parser";
40
+
41
+ const source = `
42
+ export intent Add(a: number, b: number) -> number {
43
+ step "Add the two numbers together" => const result
44
+ ensure result is a number
45
+ }
46
+ `;
47
+
48
+ const { ast } = parseToAST(source);
49
+
50
+ const generator = new AICodeGenerator({
51
+ provider: "gemini",
52
+ geminiConfig: {
53
+ apiKey: process.env.GEMINI_API_KEY!,
54
+ model: "gemini-2.0-flash"
55
+ }
56
+ });
57
+
58
+ const result = await generator.generate(ast);
59
+ console.log(result.code);
60
+ // export function Add(a: number, b: number): number {
61
+ // const result = a + b;
62
+ // if (typeof result !== 'number') throw new Error(...);
63
+ // return result;
64
+ // }
65
+ ```
66
+
67
+ ### Using Ollama (Local AI)
68
+
69
+ ```typescript
70
+ const generator = new AICodeGenerator({
71
+ provider: "ollama",
72
+ ollamaConfig: {
73
+ model: "llama3",
74
+ baseUrl: "http://localhost:11434",
75
+ num_thread: 4 // Optional: limit CPU usage
76
+ }
77
+ });
78
+ ```
79
+
80
+ ### Template Generation (No AI)
81
+
82
+ ```typescript
83
+ import { generateTypeScript } from "@intend-it/core";
84
+
85
+ const result = generateTypeScript(ast);
86
+ // Generates template with // TODO comments
87
+ ```
88
+
89
+ ## Configuration Options
90
+
91
+ ```typescript
92
+ interface AIGeneratorOptions {
93
+ provider: "gemini" | "ollama";
94
+
95
+ geminiConfig?: {
96
+ apiKey: string;
97
+ model?: string; // Default: "gemini-2.0-flash"
98
+ temperature?: number; // Default: 0.2
99
+ };
100
+
101
+ ollamaConfig?: {
102
+ model?: string; // Default: "llama3"
103
+ baseUrl?: string; // Default: "http://localhost:11434"
104
+ temperature?: number;
105
+ num_thread?: number; // CPU thread limit
106
+ };
107
+
108
+ maxAttempts?: number; // Auto-correction retries (default: 5)
109
+ }
110
+ ```
111
+
112
+ ## Caching with CAS
113
+
114
+ The compiler includes a Content-Addressable Storage system for caching:
115
+
116
+ ```typescript
117
+ import { FileSystemCAS, computeHash } from "@intend-it/core";
118
+
119
+ const cas = new FileSystemCAS("./.intend/store");
120
+
121
+ // Check cache
122
+ const hash = computeHash(sourceCode, config);
123
+ const cached = await cas.get(hash);
124
+
125
+ if (cached) {
126
+ console.log("Cache hit!");
127
+ return cached.code;
128
+ }
129
+
130
+ // Generate and cache
131
+ const result = await generator.generate(ast);
132
+ await cas.put(hash, result.code);
133
+ ```
134
+
135
+ ## Architecture
136
+
137
+ ```
138
+ ┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
139
+ │ .intent file │ ──▶ │ Parser │ ──▶ │ AST │
140
+ └─────────────────┘ └──────────────┘ └────────┬────────┘
141
+
142
+ ┌──────────────┐ ▼
143
+ │ AI Provider │ ◀── ┌─────────────────┐
144
+ │ (Gemini/Ollama)│ │ Prompt Builder │
145
+ └───────┬───────┘ └─────────────────┘
146
+
147
+
148
+ ┌──────────────┐ ┌─────────────────┐
149
+ │ Validator │ ──▶ │ TypeScript.ts │
150
+ │ (auto-retry) │ └─────────────────┘
151
+ └──────────────┘
152
+ ```
153
+
154
+ ## Related Packages
155
+
156
+ - [`@intend-it/parser`](https://www.npmjs.com/package/@intend-it/parser) - Lexer and parser
157
+ - [`@intend-it/cli`](https://www.npmjs.com/package/@intend-it/cli) - Command-line interface
158
+
159
+ ## License
160
+
161
+ MIT © [Intend Team](https://github.com/DRFR0ST/intend)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intend-it/core",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Core compiler and AI integration for the Intend programming language",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@intend-it/parser": "workspace:*",
38
+ "@intend-it/parser": "^1.1.0",
39
39
  "@google/generative-ai": "^0.21.0"
40
40
  },
41
41
  "devDependencies": {
@@ -43,6 +43,6 @@
43
43
  "typescript": "^5.0.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "@intend-it/parser": ">=1.0.1"
46
+ "@intend-it/parser": ">=1.1.0"
47
47
  }
48
48
  }