fix: merge corrected TF files instead of replacing all
- fmTf now merges new code blocks with existing S.tfFiles: updated files are replaced by name, untouched files are preserved, new files are added - System prompt changed: model generates ONLY the files that need fixing instead of all 25 files, drastically reducing output size - Prevents model from discarding existing work when correcting errors
This commit is contained in:
@@ -736,15 +736,31 @@ function fmTf(t){
|
||||
return '<div class="tf-plan-block"><div class="tf-plan-header">'+TF_ICON+' Resource Plan — '+S.tfPlan.length+' resource(s)</div><div class="tf-plan-list">'+
|
||||
S.tfPlan.map(x=>'<div class="tf-plan-item"><span class="tf-plan-add">+</span><span class="tf-plan-type">'+escHtml(x.type)+'</span><span class="tf-plan-desc">'+escHtml(x.desc)+'</span></div>').join('')+'</div></div>';
|
||||
});
|
||||
// Build files list — merge blocks with same filename, keep separate files
|
||||
// Build files list — merge new blocks with existing files (corrections preserve untouched files)
|
||||
if(codeBlocks.length){
|
||||
const fileMap={};
|
||||
const newMap={};
|
||||
codeBlocks.forEach(b=>{
|
||||
if(fileMap[b.name])fileMap[b.name]+='\n\n'+b.content;
|
||||
else fileMap[b.name]=b.content;
|
||||
if(newMap[b.name])newMap[b.name]+='\n\n'+b.content;
|
||||
else newMap[b.name]=b.content;
|
||||
});
|
||||
S.tfFiles=Object.entries(fileMap).map(([name,content])=>({name,content,size:content.length,type:'hcl'}));
|
||||
// Set tfCode to combined content for backward compat
|
||||
// If existing files: merge (update matched, keep unmatched)
|
||||
if(S.tfFiles.length){
|
||||
const merged=[];
|
||||
const usedNew=new Set();
|
||||
// Update existing files with new content if name matches
|
||||
for(const f of S.tfFiles){
|
||||
if(newMap[f.name]!=null){merged.push({name:f.name,content:newMap[f.name],size:newMap[f.name].length,type:'hcl'});usedNew.add(f.name)}
|
||||
else{merged.push(f)}
|
||||
}
|
||||
// Add any truly new files
|
||||
for(const[name,content] of Object.entries(newMap)){
|
||||
if(!usedNew.has(name))merged.push({name,content,size:content.length,type:'hcl'})
|
||||
}
|
||||
S.tfFiles=merged;
|
||||
}else{
|
||||
// First generation: set all
|
||||
S.tfFiles=Object.entries(newMap).map(([name,content])=>({name,content,size:content.length,type:'hcl'}));
|
||||
}
|
||||
S.tfCode=S.tfFiles.map(f=>'// filename: '+f.name+'\n'+f.content).join('\n\n');
|
||||
}
|
||||
r=r.replace(/\*\*(.*?)\*\*/g,'<strong>$1</strong>').replace(/`(.*?)`/g,'<code>$1</code>').replace(/\n/g,'<br>');
|
||||
|
||||
Reference in New Issue
Block a user