Commit b542c952 authored by xuchentao's avatar xuchentao

移除 Agent 修改规模限制

parent bb9d04f4
# 开发规范
## Node.js 运行时
- 执行安装、测试、类型检查、构建或启动等项目命令前,必须先运行 `nvm use 24`
- 在非交互式 Shell 中,先运行 `source /Users/mac/.nvm/nvm.sh`,再运行 `nvm use 24` 和后续项目命令。
- 不使用系统自带 Node.js 或其他 Node.js 版本执行项目命令。
......@@ -43,7 +43,4 @@ export const DEFAULT_AGENT_POLICY: AgentToolPolicy = {
export const AGENT_LIMITS = {
timeoutMs: 600_000,
maxTurns: 20,
maxFiles: 30,
maxDiffBytes: 1_048_576,
maxFileBytes: 262_144,
} as const;
......@@ -41,3 +41,20 @@ test("AgentDiffValidator accepts source edits and rejects protected files", asyn
await rm(root, { recursive: true, force: true });
}
});
test("AgentDiffValidator does not limit changed file count, file size, or diff size", async () => {
const root = await workspace();
try {
await writeFile(path.join(root, "src", "large.ts"), `export default ${JSON.stringify("x".repeat(1_100_000))};\n`);
await Promise.all(Array.from({ length: 30 }, (_, index) => (
writeFile(path.join(root, "src", `extra-${index}.ts`), `export const value${index} = ${index};\n`)
)));
const result = await new AgentDiffValidator().validate(root);
assert.equal(result.passed, true);
assert.ok(result.files.length > 30);
assert.ok(result.totalBytes > 1_048_576);
} finally {
await rm(root, { recursive: true, force: true });
}
});
import path from "node:path";
import { lstat, realpath } from "node:fs/promises";
import { execa } from "execa";
import { AGENT_LIMITS } from "./contracts.js";
export interface AgentDiffValidation {
passed: boolean;
......@@ -27,10 +26,8 @@ export class AgentDiffValidator {
return raw.includes(" -> ") ? raw.split(" -> ").at(-1)! : raw;
}))].sort();
const violations: string[] = [];
let fileBytes = 0;
const root = await realpath(workspace);
if (!files.length) violations.push("Agent 没有产生文件修改");
if (files.length > AGENT_LIMITS.maxFiles) violations.push(`修改文件数 ${files.length} 超过限制 ${AGENT_LIMITS.maxFiles}`);
for (const file of files) {
if (file.includes("..") || file.startsWith("/") || file.includes("\\")) {
violations.push(`不安全路径: ${file}`);
......@@ -46,8 +43,6 @@ export class AgentDiffValidator {
if (info.isFile()) {
const resolved = await realpath(candidate);
if (!resolved.startsWith(root + path.sep)) violations.push(`文件解析到工作区外: ${file}`);
if (info.size > AGENT_LIMITS.maxFileBytes) violations.push(`文件超过 ${AGENT_LIMITS.maxFileBytes} 字节: ${file}`);
fileBytes += info.size;
}
} catch { /* deleted file */ }
}
......@@ -58,7 +53,6 @@ export class AgentDiffValidator {
]);
if (checkResult.exitCode !== 0) violations.push("git diff --check 未通过: " + checkResult.stdout.slice(-1000));
const totalBytes = Buffer.byteLength(diffResult.stdout);
if (totalBytes > AGENT_LIMITS.maxDiffBytes) violations.push(`Diff 超过 ${AGENT_LIMITS.maxDiffBytes} 字节`);
return { passed: violations.length === 0, diff: diffResult.stdout, files, totalBytes: Math.max(totalBytes, fileBytes), violations };
return { passed: violations.length === 0, diff: diffResult.stdout, files, totalBytes, violations };
}
}
......@@ -20,7 +20,6 @@ export async function validatePatch(patch: SitePatch, workspacePath: string): Pr
if (!allowedPatterns.some((pattern) => pattern.test(normalized))) throw new Error("Patch 路径不在白名单中: " + normalized);
if (seen.has(normalized)) throw new Error("Patch 中存在重复路径: " + normalized);
seen.add(normalized);
if (operation.type === "write" && Buffer.byteLength(operation.content, "utf8") > 256 * 1024) throw new Error("单文件不能超过 256 KiB");
const destination = path.resolve(workspacePath, normalized);
if (!destination.startsWith(path.resolve(workspacePath) + path.sep)) throw new Error("Patch 路径越界");
const existing = await lstat(destination).catch(() => null);
......
......@@ -27,7 +27,7 @@ Qwen Code 使用 `OPENAI_API_KEY`、`OPENAI_BASE_URL`、`OPENAI_MODEL` 的 OpenA
- Agent 只能读取工作草稿,写入限制在 `src/**`;shell 只允许三条只读 Git 自检命令。
- 禁止访问 `.env*``.git/**`、依赖、构建产物、package/lockfile、网络和发布工具。
- Provider 完成后,系统仍会独立检查路径、符号链接、文件数、文件大小、diff 大小`git diff --check`
- Provider 完成后,系统仍会独立检查路径、符号链接和 `git diff --check`
- 系统独立执行网站构建;构建通过后只原子替换未保存草稿的测试预览,不创建 Git 提交。后续 Agent 任务继续使用同一草稿,因此多轮修改可以累积。
- 用户在左侧“版本”中填写说明并手动保存时,系统再次构建草稿,通过后才创建一个 Git 提交并将其设为当前保存版本。
- 用户可以放弃未保存草稿;系统会先确认当前保存版本可重新构建,再删除草稿,避免因构建异常丢失修改。
......
......@@ -23,4 +23,4 @@
平台能力内核 `src/_platform/**`、内容协议 `src/content.config.ts` 和外置文章映射 `src/content/articles/**` 由 WebAgent 维护,Agent 不得修改。页面、布局、组件和样式仍可自由调整。
禁止路径包括 `.git``node_modules``dist``.astro`、依赖清单和 Astro 配置。单次最多 5 个操作,单文件不超过 256 KiB;不允许路径穿越、绝对路径、符号链接写入或模型生成 Shell。
禁止路径包括 `.git``node_modules``dist``.astro`、依赖清单和 Astro 配置。单次最多 5 个操作;不允许路径穿越、绝对路径、符号链接写入或模型生成 Shell。
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment