fix(workspace): align clawd + bootstrap
This commit is contained in:
@@ -36,4 +36,17 @@ describe("ensureAgentWorkspace", () => {
|
||||
await ensureAgentWorkspace({ dir, ensureBootstrapFiles: true });
|
||||
expect(await fs.readFile(agentsPath, "utf-8")).toBe("custom");
|
||||
});
|
||||
|
||||
it("does not recreate BOOTSTRAP.md once workspace exists", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-ws-"));
|
||||
const agentsPath = path.join(dir, "AGENTS.md");
|
||||
const bootstrapPath = path.join(dir, "BOOTSTRAP.md");
|
||||
|
||||
await fs.writeFile(agentsPath, "custom", "utf-8");
|
||||
await fs.rm(bootstrapPath, { force: true });
|
||||
|
||||
await ensureAgentWorkspace({ dir, ensureBootstrapFiles: true });
|
||||
|
||||
await expect(fs.stat(bootstrapPath)).rejects.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -222,6 +222,21 @@ export async function ensureAgentWorkspace(params?: {
|
||||
const userPath = path.join(dir, DEFAULT_USER_FILENAME);
|
||||
const bootstrapPath = path.join(dir, DEFAULT_BOOTSTRAP_FILENAME);
|
||||
|
||||
const isBrandNewWorkspace = await (async () => {
|
||||
const paths = [agentsPath, soulPath, toolsPath, identityPath, userPath];
|
||||
const existing = await Promise.all(
|
||||
paths.map(async (p) => {
|
||||
try {
|
||||
await fs.access(p);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
);
|
||||
return existing.every((v) => !v);
|
||||
})();
|
||||
|
||||
const agentsTemplate = await loadTemplate(
|
||||
DEFAULT_AGENTS_FILENAME,
|
||||
DEFAULT_AGENTS_TEMPLATE,
|
||||
@@ -252,7 +267,9 @@ export async function ensureAgentWorkspace(params?: {
|
||||
await writeFileIfMissing(toolsPath, toolsTemplate);
|
||||
await writeFileIfMissing(identityPath, identityTemplate);
|
||||
await writeFileIfMissing(userPath, userTemplate);
|
||||
await writeFileIfMissing(bootstrapPath, bootstrapTemplate);
|
||||
if (isBrandNewWorkspace) {
|
||||
await writeFileIfMissing(bootstrapPath, bootstrapTemplate);
|
||||
}
|
||||
|
||||
return {
|
||||
dir,
|
||||
|
||||
Reference in New Issue
Block a user