Skip to content

Commit 4f0dccf

Browse files
committed
feat: enforce template write-protection in simple code generator
1 parent ff3a302 commit 4f0dccf

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

worker/agents/core/simpleGeneratorAgent.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,13 @@ export class SimpleCodeGeneratorAgent extends Agent<Env, CodeGenState> {
16841684
if (!sandboxInstanceId) {
16851685
throw new Error('No sandbox instance available');
16861686
}
1687+
const templateDetails = this.getTemplateDetails();
1688+
if (templateDetails && templateDetails.dontTouchFiles && templateDetails.dontTouchFiles.includes(path)) {
1689+
return {
1690+
path,
1691+
diff: '<WRITE PROTECTED - TEMPLATE FILE, CANNOT MODIFY - SKIPPED - NO CHANGES MADE>'
1692+
};
1693+
}
16871694
// Prefer local file manager; fallback to sandbox
16881695
let fileContents = '';
16891696
let filePurpose = '';
@@ -1728,6 +1735,22 @@ export class SimpleCodeGeneratorAgent extends Agent<Env, CodeGenState> {
17281735
phaseName
17291736
});
17301737

1738+
let skippedFiles: { path: string; purpose: string; diff: string }[] = [];
1739+
1740+
// Enforce template donttouch constraints
1741+
const templateDetails = this.getTemplateDetails();
1742+
if (templateDetails && templateDetails.dontTouchFiles) {
1743+
const dontTouchFiles = new Set<string>(templateDetails.dontTouchFiles);
1744+
files = files.filter(file => {
1745+
if (dontTouchFiles.has(file.path)) {
1746+
this.logger().info('Skipping dont-touch file', { filePath: file.path });
1747+
skippedFiles.push({ path: file.path, purpose: `WRITE-PROTECTED FILE, CANNOT MODIFY`, diff: "<WRITE PROTECTED - TEMPLATE FILE, CANNOT MODIFY - SKIPPED - NO CHANGES MADE>" });
1748+
return false;
1749+
}
1750+
return true;
1751+
});
1752+
}
1753+
17311754
const operation = new SimpleCodeGenerationOperation();
17321755
const result = await operation.execute(
17331756
{
@@ -1771,13 +1794,18 @@ export class SimpleCodeGeneratorAgent extends Agent<Env, CodeGenState> {
17711794

17721795
await this.deployToSandbox(savedFiles, false);
17731796

1774-
return { files: savedFiles.map(f => {
1775-
return {
1776-
path: f.filePath,
1777-
purpose: f.filePurpose || '',
1778-
diff: f.lastDiff || ''
1779-
};
1780-
}) };
1797+
return {
1798+
files: [
1799+
...skippedFiles,
1800+
...savedFiles.map(f => {
1801+
return {
1802+
path: f.filePath,
1803+
purpose: f.filePurpose || '',
1804+
diff: f.lastDiff || ''
1805+
};
1806+
})
1807+
]
1808+
};
17811809
}
17821810

17831811
async deployToSandbox(files: FileOutputType[] = [], redeploy: boolean = false, commitMessage?: string, clearLogs: boolean = false): Promise<PreviewType | null> {

0 commit comments

Comments
 (0)