mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
Guard LLM wiki log appends
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
b8097eaf83
commit
2ea28f8221
2 files changed
+36
-11
No files matched your search
@@ -2863,23 +2863,20 @@ export async function registerWikiTools(ctx: PluginContext) {
|
||||
}, async (params: unknown): Promise<ToolResult> => {
|
||||
const input = params as ToolParams;
|
||||
const companyId = requireString(input.companyId, "companyId");
|
||||
const wikiId = normalizeWikiId(input.wikiId);
|
||||
const entry = requireString(input.entry, "entry");
|
||||
let current = "";
|
||||
try {
|
||||
current = await ctx.localFolders.readText(companyId, WIKI_ROOT_FOLDER_KEY, "wiki/log.md");
|
||||
} catch {
|
||||
current = "# Log\n\nAppend-only chronological record of wiki operations.\n";
|
||||
}
|
||||
const next = `${current.trimEnd()}\n\n- ${new Date().toISOString()} ${entry}\n`;
|
||||
await ctx.localFolders.writeTextAtomic(companyId, WIKI_ROOT_FOLDER_KEY, "wiki/log.md", next);
|
||||
await upsertPageMetadata(ctx, {
|
||||
const current = await readCurrentWithHash(ctx, companyId, "wiki/log.md");
|
||||
const base = current.contents ?? "# Log\n\nAppend-only chronological record of wiki operations.\n";
|
||||
const next = `${base.trimEnd()}\n\n- ${new Date().toISOString()} ${entry}\n`;
|
||||
const result = await writeWikiPage(ctx, {
|
||||
companyId,
|
||||
wikiId: normalizeWikiId(input.wikiId),
|
||||
wikiId,
|
||||
path: "wiki/log.md",
|
||||
contents: next,
|
||||
expectedHash: current.hash,
|
||||
summary: "Append log entry",
|
||||
});
|
||||
return { content: "Appended log entry", data: { companyId, wikiId: normalizeWikiId(input.wikiId), hash: contentHash(next) } };
|
||||
return { content: "Appended log entry", data: result };
|
||||
});
|
||||
|
||||
ctx.tools.register("wiki_update_index", {
|
||||
|
||||
@@ -2210,6 +2210,34 @@ Route sidebar state stays attached to the selected wiki page.
|
||||
expect(harness.dbExecutes.some((execute) => execute.sql.includes("wiki_page_revisions"))).toBe(true);
|
||||
});
|
||||
|
||||
it("guards wiki log appends against stale concurrent writes", async () => {
|
||||
const harness = createTestHarness({ manifest });
|
||||
const reads: string[] = [
|
||||
"# Log\n\n- Existing entry\n",
|
||||
"# Log\n\n- Existing entry\n- Concurrent entry\n",
|
||||
];
|
||||
const writes: string[] = [];
|
||||
harness.ctx.localFolders.readText = async (_companyId, _folderKey, relativePath) => {
|
||||
if (relativePath !== "wiki/log.md") throw new Error("missing");
|
||||
const value = reads.shift();
|
||||
if (value == null) throw new Error("missing");
|
||||
return value;
|
||||
};
|
||||
harness.ctx.localFolders.writeTextAtomic = async (_companyId, _folderKey, relativePath, contents) => {
|
||||
writes.push(`${relativePath}:${contents}`);
|
||||
return harness.ctx.localFolders.status(COMPANY_ID, "wiki-root");
|
||||
};
|
||||
|
||||
await plugin.definition.setup(harness.ctx);
|
||||
await expect(harness.executeTool("wiki_append_log", {
|
||||
companyId: COMPANY_ID,
|
||||
wikiId: "default",
|
||||
entry: "New entry",
|
||||
})).rejects.toThrow("Refusing to overwrite wiki/log.md");
|
||||
|
||||
expect(writes).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("blocks agent-tool writes to AGENTS.md but allows explicit board edits", async () => {
|
||||
const harness = createTestHarness({ manifest });
|
||||
const files = new Map<string, string>([
|
||||
|
||||
Reference in new issue
Block a user