openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines • 5.55 kB
JavaScript
import{i as executeSqliteQuerySync,s as getNodeSqliteKysely}from"./kysely-sync-R08Pt8qn.mjs";import{p as requestSqliteWorkerOperationAdmission}from"./sqlite-worker-operation-admission-BZvXBQev.mjs";import{l as runOpenClawStateWriteTransaction}from"./openclaw-state-db-BlgxYkYw.mjs";import{i as worktreeRegistryPublication,r as withWorktreeRegistryWorkerReceipt}from"./registry-publication-gftE_-qA.mjs";import{a as worktreeGcRevision,i as rowToRecord,n as getRegistryWorktreeInDatabase}from"./registry-read.kernel-Brb6YSSA.mjs";import{a as finalizeWorktreeRemovalInDatabase,c as updateRegistryWorktreeInDatabase,d as reservePendingWorktreeInDatabase,i as deleteRegistryWorktreeInDatabase,l as worktreeRunEndMutation,m as reapWorktreeRunLeasesInDatabase,n as assertWorktreeRegistryPredicates,o as insertRegistryWorktreeInDatabase,r as claimWorktreeRemovalInDatabase,t as abortWorktreeRemovalInDatabase,u as releasePendingWorktreeInDatabase}from"./registry-run-end.worker-CaPUjDnl.mjs";import{r as releaseWorktreeRunLeaseInDatabase,t as admitWorktreeRunLeaseInDatabase}from"./run-lease-store.kernel-CJOQjXGU.mjs";import{n as hasLocalWorkspaceProjectionInDatabase}from"./local-workspace-store.kernel-BE277_Tx.mjs";
//!src/agents/worktrees/provisioned-snapshot.worker.ts
function writeProvisionedSnapshotInDatabase(e,t){const n=getNodeSqliteKysely(e);if(t.kind===`reset`)executeSqliteQuerySync(e,n.deleteFrom(`worktree_provisioned_file_chunks`).where(`worktree_id`,`=`,t.worktreeId));else executeSqliteQuerySync(e,n.insertInto(`worktree_provisioned_file_chunks`).values({worktree_id:t.worktreeId,path:t.path,chunk_index:t.chunkIndex,data:t.data}))}
//!src/agents/worktrees/registry-retirement.worker.ts
function deferWorktreeCleanupInWorker({observed:e,reason:t,retry:n,removalToken:r},i){return runOpenClawStateWriteTransaction(({db:i})=>withWorktreeRegistryWorkerReceipt(i,()=>{requestSqliteWorkerOperationAdmission({stage:`transaction`,facts:void 0});if(r)assertWorktreeRegistryPredicates(i,[{kind:`removal-claim`,id:e.id,token:r}]);const a=getRegistryWorktreeInDatabase(i,e.id);const o=worktreeGcRevision(e);if(!a||worktreeGcRevision(a)!==o)return false;const s=executeSqliteQuerySync(i,getNodeSqliteKysely(i).updateTable(`worktrees`).set({gc_protection_json:t===null?null:JSON.stringify({revision:o,reason:t,retry:n})}).where(`id`,`=`,e.id).returningAll()).rows;worktreeRegistryPublication.rows(i,s);requestSqliteWorkerOperationAdmission({stage:`commit`,facts:void 0});return true}),i,{operationLabel:`worktrees.deferCleanup`})}function retireMissingWorktreeInWorker({observed:e,removedAt:t},n){return runOpenClawStateWriteTransaction(({db:n})=>withWorktreeRegistryWorkerReceipt(n,()=>{requestSqliteWorkerOperationAdmission({stage:`transaction`,facts:void 0});if(hasLocalWorkspaceProjectionInDatabase(n,e.id))return{record:getRegistryWorktreeInDatabase(n,e.id),protection:`local-workspace-projection`};const r=executeSqliteQuerySync(n,getNodeSqliteKysely(n).updateTable(`worktrees`).set({removed_at:t}).where(`id`,`=`,e.id).where(`removed_at`,`is`,null).where(e=>e.or([e(`snapshot_ref`,`is`,null),e(`snapshot_ref`,`not like`,`refs/openclaw/snapshots/exact-%`)])).where(`path`,`=`,e.path).where(`last_active_at`,`=`,e.lastActiveAt).where(`repo_root`,`=`,e.repoRoot).where(`repo_fingerprint`,`=`,e.repoFingerprint).returningAll()).rows[0];worktreeRegistryPublication.rows(n,r?[r]:[]);const i=r?rowToRecord(r):getRegistryWorktreeInDatabase(n,e.id);requestSqliteWorkerOperationAdmission({stage:`commit`,facts:void 0});return{record:i}}),n,{operationLabel:`worktrees.retireMissing`})}
//!src/agents/worktrees/dispatch.worker.ts
const worktreeOperations={"worktrees.assertPredicates":({predicates:e},{open:t})=>assertWorktreeRegistryPredicates(t().db,e),"worktrees.delete":worktreeRunEndMutation(`worktrees.delete`,deleteRegistryWorktreeInDatabase),"worktrees.reservePending":worktreeRunEndMutation(`worktrees.reservePending`,reservePendingWorktreeInDatabase),"worktrees.releasePending":worktreeRunEndMutation(`worktrees.releasePending`,releasePendingWorktreeInDatabase),"worktrees.insert":worktreeRunEndMutation(`worktrees.insert`,insertRegistryWorktreeInDatabase),"worktrees.update":worktreeRunEndMutation(`worktrees.update`,updateRegistryWorktreeInDatabase),"worktrees.claimRemoval":worktreeRunEndMutation(`worktrees.claimRemoval`,claimWorktreeRemovalInDatabase),"worktrees.finalizeRemoval":worktreeRunEndMutation(`worktrees.finalizeRemoval`,finalizeWorktreeRemovalInDatabase),"worktrees.abortRemoval":worktreeRunEndMutation(`worktrees.abortRemoval`,abortWorktreeRemovalInDatabase),"worktrees.writeProvisionedSnapshot":worktreeRunEndMutation(`worktrees.writeProvisionedSnapshot`,writeProvisionedSnapshotInDatabase),"worktrees.retireMissing":(e,{open:t,stateOptions:n})=>retireMissingWorktreeInWorker(e,{...n(),database:t()}),"worktrees.deferCleanup":(e,{open:t,stateOptions:n})=>deferWorktreeCleanupInWorker(e,{...n(),database:t()}),"worktrees.admitRunLease":(e,{writeAdmitted:t})=>t(({db:t})=>withWorktreeRegistryWorkerReceipt(t,()=>admitWorktreeRunLeaseInDatabase(t,e)),{operationLabel:`worktrees.admitRunLease`}),"worktrees.releaseRunLease":({worktreeId:e,token:t},{writeAdmitted:n})=>n(({db:n})=>withWorktreeRegistryWorkerReceipt(n,()=>releaseWorktreeRunLeaseInDatabase(n,e,t)),{operationLabel:`worktrees.releaseRunLease`}),"worktrees.reapRunLeases":({scopes:e},{writeAdmitted:t})=>t(({db:t})=>withWorktreeRegistryWorkerReceipt(t,()=>reapWorktreeRunLeasesInDatabase(t,e)),{operationLabel:`worktrees.reapRunLeases`})};export{worktreeOperations};