mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 02:00:52 +01:00
Add sandbox work-folder persistence and shared lifecycle
Introduce company-scoped task, agent, user and project files, recoverable trash, object-backed repository checkpoints, and a shared 180-second lifecycle for sandbox execution. Wire file browsing and save status into the owner surfaces. This is an implementation checkpoint; staging acceptance and the complete merge gate remain outstanding.
This commit is contained in:
1 parent
392ab26b1e
commit
a13bb6b395
51 files changed
+176079
-37
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { WORK_FOLDER_SYNC_INTERVAL_MS } from "@paperclipai/shared";
|
||||
|
||||
/** One scheduler for both execution generations. A tick never queues a backlog. */
|
||||
export function startWorkFolderCheckpointer(input: {
|
||||
checkpoint(): Promise<void>;
|
||||
onError(error: unknown): Promise<void>;
|
||||
}) {
|
||||
let active: Promise<void> | null = null;
|
||||
let stopped = false;
|
||||
function checkpoint() {
|
||||
const pending = (async () => {
|
||||
try { await input.checkpoint(); }
|
||||
catch (error) { await input.onError(error); throw error; }
|
||||
})();
|
||||
active = pending;
|
||||
void pending.finally(() => { if (active === pending) active = null; }).catch(() => {});
|
||||
return pending;
|
||||
}
|
||||
const timer = setInterval(() => {
|
||||
if (!stopped && !active) void checkpoint().catch(() => {});
|
||||
}, WORK_FOLDER_SYNC_INTERVAL_MS);
|
||||
timer.unref();
|
||||
// Explicit flushes serialize too. They must checkpoint once more after an
|
||||
// in-flight tick, since the agent may have edited during that tick.
|
||||
let flushTail: Promise<void> = Promise.resolve();
|
||||
function flush() {
|
||||
const pending = flushTail.catch(() => {}).then(async () => {
|
||||
await active?.catch(() => {});
|
||||
await checkpoint();
|
||||
});
|
||||
flushTail = pending;
|
||||
return pending;
|
||||
}
|
||||
return {
|
||||
flush,
|
||||
async stop() { stopped = true; clearInterval(timer); await flush(); },
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user