@intend-it/core 3.0.2 → 4.0.1
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.
- package/README.md +4 -0
- package/dist/index.js +155 -82
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
<h1>@intend-it/core</h1>
|
|
3
3
|
<p><strong>AI-Powered Code Generator for the Intend Language</strong></p>
|
|
4
4
|
<p>
|
|
5
|
+
<a href="https://intend.fly.dev">Documentation</a> •
|
|
5
6
|
<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
7
|
<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
8
|
<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>
|
|
@@ -14,9 +15,12 @@
|
|
|
14
15
|
|
|
15
16
|
`@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
|
|
|
18
|
+
**[Read the full documentation 📖](https://intend.fly.dev)**
|
|
19
|
+
|
|
17
20
|
### ✨ Key Features
|
|
18
21
|
|
|
19
22
|
- **🧠 AI Code Generation** - Transforms natural language steps into actual code
|
|
23
|
+
- **🔀 Hybrid Orchestration** - Mix AI steps with deterministic function calls
|
|
20
24
|
- **🔄 Self-Correction Loop** - Validates output and auto-fixes errors
|
|
21
25
|
- **⚡ Smart Caching (CAS)** - Content-addressable storage for instant rebuilds
|
|
22
26
|
- **🔌 Multi-Provider** - Supports Gemini and Ollama (local)
|
package/dist/index.js
CHANGED
|
@@ -168803,8 +168803,15 @@ class TypeScriptGenerator {
|
|
|
168803
168803
|
`;
|
|
168804
168804
|
code += `if (import.meta.main) {
|
|
168805
168805
|
`;
|
|
168806
|
-
|
|
168806
|
+
if (intent.parameters.length === 0) {
|
|
168807
|
+
code += ` Promise.resolve(${intent.name}()).catch((err: any) => console.error(err));
|
|
168807
168808
|
`;
|
|
168809
|
+
} else {
|
|
168810
|
+
code += ` // CLI Auto-Run disabled: function requires arguments
|
|
168811
|
+
`;
|
|
168812
|
+
code += ` // Promise.resolve(${intent.name}(/* ...args */)).catch((err: any) => console.error(err));
|
|
168813
|
+
`;
|
|
168814
|
+
}
|
|
168808
168815
|
code += `}
|
|
168809
168816
|
`;
|
|
168810
168817
|
}
|
|
@@ -168817,7 +168824,8 @@ class TypeScriptGenerator {
|
|
|
168817
168824
|
}
|
|
168818
168825
|
generateImport(imp) {
|
|
168819
168826
|
const specifiers = imp.specifiers.join(", ");
|
|
168820
|
-
|
|
168827
|
+
const source = imp.source.replace(/\.intent$/, "");
|
|
168828
|
+
return `import { ${specifiers} } from "${source}";`;
|
|
168821
168829
|
}
|
|
168822
168830
|
generateJsDoc(intent) {
|
|
168823
168831
|
const lines = ["/**"];
|
|
@@ -168911,6 +168919,9 @@ class TypeScriptGenerator {
|
|
|
168911
168919
|
}
|
|
168912
168920
|
generateStep(step, index) {
|
|
168913
168921
|
const blocks = [];
|
|
168922
|
+
if (step.type === "Call") {
|
|
168923
|
+
return this.generateCall(step);
|
|
168924
|
+
}
|
|
168914
168925
|
if (this.options.includeTodos) {
|
|
168915
168926
|
blocks.push({
|
|
168916
168927
|
type: "comment",
|
|
@@ -168934,6 +168945,33 @@ class TypeScriptGenerator {
|
|
|
168934
168945
|
blocks.push({ type: "comment", content: "", indent: 0 });
|
|
168935
168946
|
return blocks;
|
|
168936
168947
|
}
|
|
168948
|
+
generateCall(call) {
|
|
168949
|
+
const blocks = [];
|
|
168950
|
+
const args = call.args.map((arg) => this.generateValue(arg)).join(", ");
|
|
168951
|
+
const callExpr = `await ${call.intent}(${args})`;
|
|
168952
|
+
if (call.resultVariable) {
|
|
168953
|
+
const decl = call.variableKind || "const";
|
|
168954
|
+
blocks.push({
|
|
168955
|
+
type: "statement",
|
|
168956
|
+
content: `${decl} ${call.resultVariable} = ${callExpr};`,
|
|
168957
|
+
indent: 1
|
|
168958
|
+
});
|
|
168959
|
+
} else {
|
|
168960
|
+
blocks.push({
|
|
168961
|
+
type: "statement",
|
|
168962
|
+
content: `${callExpr};`,
|
|
168963
|
+
indent: 1
|
|
168964
|
+
});
|
|
168965
|
+
}
|
|
168966
|
+
blocks.push({ type: "comment", content: "", indent: 0 });
|
|
168967
|
+
return blocks;
|
|
168968
|
+
}
|
|
168969
|
+
generateValue(v) {
|
|
168970
|
+
if (v.type === "String") {
|
|
168971
|
+
return JSON.stringify(v.value);
|
|
168972
|
+
}
|
|
168973
|
+
return v.value;
|
|
168974
|
+
}
|
|
168937
168975
|
generateEnsure(ensure) {
|
|
168938
168976
|
const blocks = [];
|
|
168939
168977
|
const expr = ensure.expression.trim();
|
|
@@ -169149,21 +169187,22 @@ class PromptBuilder {
|
|
|
169149
169187
|
};
|
|
169150
169188
|
}
|
|
169151
169189
|
buildSystemPrompt() {
|
|
169152
|
-
return `You are an expert TypeScript
|
|
169153
|
-
|
|
169154
|
-
Your task is to implement function bodies based on natural language specifications.
|
|
169155
|
-
|
|
169156
|
-
Rules:
|
|
169157
|
-
1. Generate ONLY the implementation code (function body content)
|
|
169158
|
-
2. Do NOT include the function signature or braces
|
|
169159
|
-
3. Use
|
|
169160
|
-
4. Handle errors
|
|
169161
|
-
5. Return values must match the specified return type
|
|
169162
|
-
6. Follow the
|
|
169163
|
-
7. Respect all invariants (
|
|
169164
|
-
8. Ensure all postconditions are
|
|
169165
|
-
9. Use
|
|
169166
|
-
10.
|
|
169190
|
+
return `You are an expert Senior TypeScript Developer specializing in robust, production-grade code.
|
|
169191
|
+
|
|
169192
|
+
Your task is to implement function bodies based on structured natural language specifications (Intend).
|
|
169193
|
+
|
|
169194
|
+
Rules:
|
|
169195
|
+
1. Generate ONLY the implementation code (function body content).
|
|
169196
|
+
2. Do NOT include the function signature, exports, or braces surfacing the function.
|
|
169197
|
+
3. Use strict TypeScript (no 'any' unless absolutely necessary).
|
|
169198
|
+
4. Handle edge cases and errors defensively (throw descriptive Errors).
|
|
169199
|
+
5. Return values must strictly match the specified return type.
|
|
169200
|
+
6. Follow the provided steps EXACTLY in order.
|
|
169201
|
+
7. Respect all invariants (implement usage checks at the start if needed).
|
|
169202
|
+
8. Ensure all postconditions (ensures) are satisfiable by your logic.
|
|
169203
|
+
9. Use clear, semantic variable names.
|
|
169204
|
+
10. Do not hallucinate imports; use only what is provided.
|
|
169205
|
+
11. If a variable name in the requirements seems to have a typo (e.g. 'totals' instead of 'total'), fix it to match the defined variable.`;
|
|
169167
169206
|
}
|
|
169168
169207
|
buildStepPrompt(context, stepIndex) {
|
|
169169
169208
|
const step = context.steps[stepIndex];
|
|
@@ -169185,7 +169224,12 @@ Rules:
|
|
|
169185
169224
|
lines.push("");
|
|
169186
169225
|
}
|
|
169187
169226
|
lines.push(`Step ${stepIndex + 1} of ${context.steps.length}:`);
|
|
169188
|
-
|
|
169227
|
+
if (step.type === "Call") {
|
|
169228
|
+
const args = step.args.map((a) => a.type === "String" ? JSON.stringify(a.value) : a.value).join(", ");
|
|
169229
|
+
lines.push(`Execute Call: ${step.intent}(${args})`);
|
|
169230
|
+
} else {
|
|
169231
|
+
lines.push(`"${step.instruction}"`);
|
|
169232
|
+
}
|
|
169189
169233
|
if (step.resultVariable) {
|
|
169190
169234
|
lines.push(`
|
|
169191
169235
|
This step must store its result in a variable named: ${step.resultVariable}`);
|
|
@@ -169195,10 +169239,17 @@ This step must store its result in a variable named: ${step.resultVariable}`);
|
|
|
169195
169239
|
Previous steps:`);
|
|
169196
169240
|
for (let i = 0;i < stepIndex; i++) {
|
|
169197
169241
|
const prevStep = context.steps[i];
|
|
169242
|
+
let desc = "";
|
|
169243
|
+
if (prevStep.type === "Call") {
|
|
169244
|
+
const args = prevStep.args.map((a) => a.type === "String" ? JSON.stringify(a.value) : a.value).join(", ");
|
|
169245
|
+
desc = `Call: ${prevStep.intent}(${args})`;
|
|
169246
|
+
} else {
|
|
169247
|
+
desc = `"${prevStep.instruction}"`;
|
|
169248
|
+
}
|
|
169198
169249
|
if (prevStep.resultVariable) {
|
|
169199
|
-
lines.push(`- Step ${i + 1}: ${
|
|
169250
|
+
lines.push(`- Step ${i + 1}: ${desc} => const ${prevStep.resultVariable}`);
|
|
169200
169251
|
} else {
|
|
169201
|
-
lines.push(`- Step ${i + 1}: ${
|
|
169252
|
+
lines.push(`- Step ${i + 1}: ${desc}`);
|
|
169202
169253
|
}
|
|
169203
169254
|
}
|
|
169204
169255
|
}
|
|
@@ -169247,10 +169298,16 @@ Generate ONLY the TypeScript code for this step (no explanations, no markdown).`
|
|
|
169247
169298
|
}
|
|
169248
169299
|
lines.push(`Implementation Steps (in order):`);
|
|
169249
169300
|
context.steps.forEach((step, i) => {
|
|
169250
|
-
let line = `${i + 1}.
|
|
169301
|
+
let line = `${i + 1}. `;
|
|
169302
|
+
if (step.type === "Call") {
|
|
169303
|
+
const args = step.args.map((a) => a.type === "String" ? JSON.stringify(a.value) : a.value).join(", ");
|
|
169304
|
+
line += `Call: ${step.intent}(${args})`;
|
|
169305
|
+
} else {
|
|
169306
|
+
line += `"${step.instruction}"`;
|
|
169307
|
+
}
|
|
169251
169308
|
if (step.resultVariable) {
|
|
169252
169309
|
line += ` => const ${step.resultVariable}`;
|
|
169253
|
-
if (step.resultType) {
|
|
169310
|
+
if (step.type === "Step" && step.resultType) {
|
|
169254
169311
|
line += `: ${step.resultType}`;
|
|
169255
169312
|
}
|
|
169256
169313
|
}
|
|
@@ -169266,6 +169323,9 @@ Generate ONLY the TypeScript code for this step (no explanations, no markdown).`
|
|
|
169266
169323
|
lines.push(`The code should:`);
|
|
169267
169324
|
lines.push(`- Follow all steps in order`);
|
|
169268
169325
|
lines.push(`- Store results in the specified variable names`);
|
|
169326
|
+
lines.push(`- Make sure that imported functions are called with the correct arguments from the context.`);
|
|
169327
|
+
lines.push(`- Make sure the return value matches the expected return type strictly.`);
|
|
169328
|
+
lines.push(`- If a Step requires a return, ensure it is returned.`);
|
|
169269
169329
|
lines.push(`- Satisfy all postconditions`);
|
|
169270
169330
|
lines.push(`- Be production-ready TypeScript`);
|
|
169271
169331
|
lines.push(`
|
|
@@ -169321,10 +169381,16 @@ Response Format:
|
|
|
169321
169381
|
`);
|
|
169322
169382
|
lines.push(`Required Steps:`);
|
|
169323
169383
|
context.steps.forEach((step, i) => {
|
|
169324
|
-
let line = `${i + 1}.
|
|
169384
|
+
let line = `${i + 1}. `;
|
|
169385
|
+
if (step.type === "Call") {
|
|
169386
|
+
const args = step.args.map((a) => a.type === "String" ? JSON.stringify(a.value) : a.value).join(", ");
|
|
169387
|
+
line += `Call: ${step.intent}(${args})`;
|
|
169388
|
+
} else {
|
|
169389
|
+
line += `"${step.instruction}"`;
|
|
169390
|
+
}
|
|
169325
169391
|
if (step.resultVariable) {
|
|
169326
169392
|
line += ` => ${step.resultVariable}`;
|
|
169327
|
-
if (step.resultType)
|
|
169393
|
+
if (step.type === "Step" && step.resultType)
|
|
169328
169394
|
line += `: ${step.resultType}`;
|
|
169329
169395
|
}
|
|
169330
169396
|
lines.push(line);
|
|
@@ -169341,6 +169407,7 @@ Verify:`);
|
|
|
169341
169407
|
lines.push(`3. All declared variables are used`);
|
|
169342
169408
|
lines.push(`4. Return value matches required type`);
|
|
169343
169409
|
lines.push(`5. No infinite loops or unintended recursion`);
|
|
169410
|
+
lines.push(`6. Imports are correct (no .intent extension, only using provided imports)`);
|
|
169344
169411
|
lines.push(`
|
|
169345
169412
|
Respond with APPROVED or ISSUES + FIX as specified.`);
|
|
169346
169413
|
return lines.join(`
|
|
@@ -169562,6 +169629,7 @@ ${request.prompt}`;
|
|
|
169562
169629
|
var DEFAULT_MODEL3 = "llama3";
|
|
169563
169630
|
var DEFAULT_BASE_URL = "http://localhost:11434";
|
|
169564
169631
|
var DEFAULT_TEMPERATURE3 = 0.2;
|
|
169632
|
+
var DEFAULT_TIMEOUT = 90 * 60 * 1000;
|
|
169565
169633
|
|
|
169566
169634
|
class OllamaProvider {
|
|
169567
169635
|
name = "ollama";
|
|
@@ -169569,11 +169637,13 @@ class OllamaProvider {
|
|
|
169569
169637
|
baseUrl;
|
|
169570
169638
|
temperature;
|
|
169571
169639
|
num_thread;
|
|
169640
|
+
timeout;
|
|
169572
169641
|
constructor(config) {
|
|
169573
169642
|
this.model = config.model || DEFAULT_MODEL3;
|
|
169574
169643
|
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
169575
169644
|
this.temperature = config.temperature ?? DEFAULT_TEMPERATURE3;
|
|
169576
169645
|
this.num_thread = config.num_thread;
|
|
169646
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
169577
169647
|
}
|
|
169578
169648
|
async generateCode(request) {
|
|
169579
169649
|
try {
|
|
@@ -169633,13 +169703,17 @@ ${request.prompt}`;
|
|
|
169633
169703
|
}
|
|
169634
169704
|
};
|
|
169635
169705
|
try {
|
|
169706
|
+
const controller = new AbortController;
|
|
169707
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
169636
169708
|
const response = await fetch(url, {
|
|
169637
169709
|
method: "POST",
|
|
169638
169710
|
headers: {
|
|
169639
169711
|
"Content-Type": "application/json"
|
|
169640
169712
|
},
|
|
169641
|
-
body: JSON.stringify(body)
|
|
169713
|
+
body: JSON.stringify(body),
|
|
169714
|
+
signal: controller.signal
|
|
169642
169715
|
});
|
|
169716
|
+
clearTimeout(timeoutId);
|
|
169643
169717
|
if (!response.ok) {
|
|
169644
169718
|
throw new Error(`Ollama API error: ${response.status} - ${response.statusText}`);
|
|
169645
169719
|
}
|
|
@@ -169730,7 +169804,10 @@ class TypeScriptValidator {
|
|
|
169730
169804
|
esModuleInterop: true,
|
|
169731
169805
|
skipLibCheck: true,
|
|
169732
169806
|
checkJs: false,
|
|
169733
|
-
allowJs: false
|
|
169807
|
+
allowJs: false,
|
|
169808
|
+
noImplicitReturns: true,
|
|
169809
|
+
strictNullChecks: true,
|
|
169810
|
+
noImplicitAny: true
|
|
169734
169811
|
};
|
|
169735
169812
|
const host = ts.createCompilerHost(compilerOptions);
|
|
169736
169813
|
const originalReadFile = host.readFile;
|
|
@@ -169749,6 +169826,12 @@ class TypeScriptValidator {
|
|
|
169749
169826
|
`);
|
|
169750
169827
|
if (msg.includes("Cannot find global type"))
|
|
169751
169828
|
return false;
|
|
169829
|
+
if (msg.includes("Cannot find name 'process'"))
|
|
169830
|
+
return false;
|
|
169831
|
+
if (msg.includes("Cannot find name 'console'"))
|
|
169832
|
+
return false;
|
|
169833
|
+
if (msg.includes("Cannot find name 'Buffer'"))
|
|
169834
|
+
return false;
|
|
169752
169835
|
return true;
|
|
169753
169836
|
}).map((d) => {
|
|
169754
169837
|
const line = d.file ? d.file.getLineAndCharacterOfPosition(d.start).line + 1 : 0;
|
|
@@ -169778,8 +169861,8 @@ class AICodeGenerator {
|
|
|
169778
169861
|
constructor(options) {
|
|
169779
169862
|
this.promptBuilder = new PromptBuilder;
|
|
169780
169863
|
this.validator = new TypeScriptValidator;
|
|
169781
|
-
this.mode =
|
|
169782
|
-
this.maxAttempts = options.maxAttempts ??
|
|
169864
|
+
this.mode = "full";
|
|
169865
|
+
this.maxAttempts = options.maxAttempts ?? 3;
|
|
169783
169866
|
this.projectContext = options.projectContext;
|
|
169784
169867
|
this.debug = options.debug ?? false;
|
|
169785
169868
|
const providerName = options.provider || "gemini";
|
|
@@ -169828,7 +169911,6 @@ class AICodeGenerator {
|
|
|
169828
169911
|
const context = this.promptBuilder.buildContext(intent, file.imports, importedIntents);
|
|
169829
169912
|
totalSteps += context.steps.length;
|
|
169830
169913
|
if (this.mode === "step-by-step") {
|
|
169831
|
-
console.warn("Step-by-step mode not fully supported for multi-intent files. Falling back to full generation.");
|
|
169832
169914
|
currentCode = await this.generateFull(currentCode, context, intent.name);
|
|
169833
169915
|
} else {
|
|
169834
169916
|
currentCode = await this.generateFull(currentCode, context, intent.name);
|
|
@@ -169856,18 +169938,21 @@ class AICodeGenerator {
|
|
|
169856
169938
|
throw new Error(`AI generation failed: ${response.error}`);
|
|
169857
169939
|
}
|
|
169858
169940
|
const cleanCode = this.sanitizeAIResponse(response.code);
|
|
169859
|
-
const updatedCode = this.injectImplementation(fileContent,
|
|
169860
|
-
|
|
169941
|
+
const { code: updatedCode, startLine, endLine } = this.injectImplementation(fileContent, functionName, cleanCode);
|
|
169942
|
+
let syntaxErrors = this.validator.validate(updatedCode);
|
|
169943
|
+
syntaxErrors = syntaxErrors.filter((e) => e.line >= startLine + 1 && e.line <= endLine + 1);
|
|
169861
169944
|
if (syntaxErrors.length > 0) {
|
|
169862
169945
|
attempts++;
|
|
169863
169946
|
if (attempts < limit) {
|
|
169864
169947
|
const errorMsg = syntaxErrors.slice(0, 5).map((e) => `Line ${e.line}: ${e.message}`).join(`
|
|
169865
169948
|
`);
|
|
169866
|
-
console.log(`
|
|
169949
|
+
console.log(`
|
|
169950
|
+
⚠️ Validation failed for ${functionName} (Attempt ${attempts}/${limit}):`);
|
|
169867
169951
|
console.log(errorMsg.split(`
|
|
169868
169952
|
`).map((l) => ` ${l}`).join(`
|
|
169869
169953
|
`));
|
|
169870
|
-
console.log(` Retrying with AI auto-correction
|
|
169954
|
+
console.log(` Retrying with AI auto-correction...
|
|
169955
|
+
`);
|
|
169871
169956
|
prompt += `
|
|
169872
169957
|
|
|
169873
169958
|
Validation Failed (Attempt ${attempts}/${limit}).
|
|
@@ -169879,14 +169964,17 @@ ${cleanCode}
|
|
|
169879
169964
|
` + `Errors encountered:
|
|
169880
169965
|
${errorMsg}
|
|
169881
169966
|
|
|
169882
|
-
` + `CRITICAL
|
|
169883
|
-
` + `1.
|
|
169884
|
-
` + `2.
|
|
169967
|
+
` + `CRITICAL: You are fixing a critical syntax/compilation error.
|
|
169968
|
+
` + `1. ANALYZE: Briefly explain why the error happened.
|
|
169969
|
+
` + `2. FIX: Generate the COMPLETE, FIXED function body wrapped in \`\`\`typescript.
|
|
169970
|
+
` + `Do not return partial snippets. Return the full function body.
|
|
169885
169971
|
`;
|
|
169886
169972
|
} else {
|
|
169887
|
-
|
|
169888
|
-
|
|
169889
|
-
|
|
169973
|
+
const errorMsg = syntaxErrors.slice(0, 5).map((e) => `Line ${e.line}: ${e.message}`).join(`
|
|
169974
|
+
`);
|
|
169975
|
+
throw new Error(`Validation failed for ${functionName} after ${limit} attempts.
|
|
169976
|
+
Errors:
|
|
169977
|
+
${errorMsg}`);
|
|
169890
169978
|
}
|
|
169891
169979
|
continue;
|
|
169892
169980
|
}
|
|
@@ -169896,10 +169984,12 @@ ${errorMsg}
|
|
|
169896
169984
|
}
|
|
169897
169985
|
attempts++;
|
|
169898
169986
|
if (attempts < limit) {
|
|
169899
|
-
console.log(`
|
|
169987
|
+
console.log(`
|
|
169988
|
+
\uD83D\uDD0D Logic review found issues for ${functionName} (Attempt ${attempts}/${limit}):`);
|
|
169900
169989
|
console.log(` ${logicIssues.issues.slice(0, 3).join(`
|
|
169901
169990
|
`)}`);
|
|
169902
|
-
console.log(` Retrying with AI auto-correction
|
|
169991
|
+
console.log(` Retrying with AI auto-correction...
|
|
169992
|
+
`);
|
|
169903
169993
|
prompt += `
|
|
169904
169994
|
|
|
169905
169995
|
Logic Review Failed (Attempt ${attempts}/${limit}).
|
|
@@ -169914,17 +170004,23 @@ ${logicIssues.issues.join(`
|
|
|
169914
170004
|
|
|
169915
170005
|
` + `Suggested fix: ${logicIssues.fix}
|
|
169916
170006
|
|
|
169917
|
-
` + `CRITICAL
|
|
170007
|
+
` + `CRITICAL: You are fixing a LOGICAL issue.
|
|
170008
|
+
` + `1. ANALYZE: Briefly explain the logic flaw.
|
|
170009
|
+
` + `2. FIX: Generate the COMPLETE, FIXED function body wrapped in \`\`\`typescript.
|
|
170010
|
+
` + `Ensure every step from the requirements is fully implemented.
|
|
169918
170011
|
`;
|
|
169919
170012
|
} else {
|
|
169920
|
-
|
|
169921
|
-
|
|
170013
|
+
throw new Error(`Logic verification failed for ${functionName} after ${limit} attempts.
|
|
170014
|
+
Issues:
|
|
170015
|
+
${logicIssues.issues.join(`
|
|
170016
|
+
`)}`);
|
|
169922
170017
|
}
|
|
169923
170018
|
}
|
|
169924
170019
|
return fileContent;
|
|
169925
170020
|
}
|
|
169926
170021
|
sanitizeAIResponse(code) {
|
|
169927
170022
|
let sanitized = code.replace(/```typescript\s*/g, "").replace(/```\s*/g, "");
|
|
170023
|
+
sanitized = sanitized.replace(/^(Here is|Sure|I have|Certainly).+$/gim, "");
|
|
169928
170024
|
sanitized = sanitized.replace(/^\s*import\s+.*;?\s*$/gm, "");
|
|
169929
170025
|
return sanitized.trim();
|
|
169930
170026
|
}
|
|
@@ -169968,40 +170064,9 @@ ${logicIssues.issues.join(`
|
|
|
169968
170064
|
}
|
|
169969
170065
|
}
|
|
169970
170066
|
async explainFailure(functionName, code, errors) {
|
|
169971
|
-
|
|
169972
|
-
`);
|
|
169973
|
-
const prompt = `
|
|
169974
|
-
The following TypeScript implementation for '${functionName}' failed validation after multiple self-correction attempts.
|
|
169975
|
-
|
|
169976
|
-
Code:
|
|
169977
|
-
${code}
|
|
169978
|
-
|
|
169979
|
-
Errors:
|
|
169980
|
-
${errorMsg}
|
|
169981
|
-
|
|
169982
|
-
Please explain to the user why this code is failing and what they might need to fix in their .intend file or configuration.
|
|
169983
|
-
Focus on the root cause. Keep it concise.
|
|
169984
|
-
`;
|
|
169985
|
-
try {
|
|
169986
|
-
console.log(` \uD83E\uDD16 Analyzing failure...`);
|
|
169987
|
-
const response = await this.provider.generateCode({
|
|
169988
|
-
systemPrompt: "You are a helpful coding assistant explaining compile errors.",
|
|
169989
|
-
prompt,
|
|
169990
|
-
debug: this.debug
|
|
169991
|
-
});
|
|
169992
|
-
if (response.success) {
|
|
169993
|
-
console.log(`
|
|
169994
|
-
==================================================`);
|
|
169995
|
-
console.log("\uD83E\uDD16 AI DIAGNOSTICS:");
|
|
169996
|
-
console.log(response.code);
|
|
169997
|
-
console.log(`==================================================
|
|
169998
|
-
`);
|
|
169999
|
-
}
|
|
170000
|
-
} catch (err) {
|
|
170001
|
-
console.warn("Failed to generate diagnostics.");
|
|
170002
|
-
}
|
|
170067
|
+
return;
|
|
170003
170068
|
}
|
|
170004
|
-
injectImplementation(fileContent,
|
|
170069
|
+
injectImplementation(fileContent, functionName, implementation) {
|
|
170005
170070
|
const lines = fileContent.split(`
|
|
170006
170071
|
`);
|
|
170007
170072
|
let startLine = -1;
|
|
@@ -170029,8 +170094,12 @@ Focus on the root cause. Keep it concise.
|
|
|
170029
170094
|
}
|
|
170030
170095
|
}
|
|
170031
170096
|
if (!foundStart || endLine === -1) {
|
|
170032
|
-
|
|
170033
|
-
|
|
170097
|
+
throw new Error(`Fatal: Could not filter function body for injection.
|
|
170098
|
+
Function: ${functionName}
|
|
170099
|
+
Regex: ${regex}
|
|
170100
|
+
Start found: ${foundStart}, End found: ${endLine !== -1}
|
|
170101
|
+
|
|
170102
|
+
Possible cause: Formatting mismatch between template and injector.`);
|
|
170034
170103
|
}
|
|
170035
170104
|
const pre = lines.slice(0, startLine + 1).join(`
|
|
170036
170105
|
`);
|
|
@@ -170043,9 +170112,13 @@ Focus on the root cause. Keep it concise.
|
|
|
170043
170112
|
return "";
|
|
170044
170113
|
}).join(`
|
|
170045
170114
|
`);
|
|
170046
|
-
return
|
|
170047
|
-
|
|
170048
|
-
|
|
170115
|
+
return {
|
|
170116
|
+
code: `${pre}
|
|
170117
|
+
${indentedImpl}
|
|
170118
|
+
${post}`,
|
|
170119
|
+
startLine: startLine + 1,
|
|
170120
|
+
endLine: endLine + 1
|
|
170121
|
+
};
|
|
170049
170122
|
}
|
|
170050
170123
|
async testConnection() {
|
|
170051
170124
|
return await this.provider.testConnection();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intend-it/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
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": "^1.
|
|
38
|
+
"@intend-it/parser": "^1.3.1",
|
|
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.
|
|
46
|
+
"@intend-it/parser": ">=1.3.1"
|
|
47
47
|
}
|
|
48
48
|
}
|