MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getCheckpointService

Function getCheckpointService

src/core/checkpoints/index.ts:28–130  ·  view source on GitHub ↗
(task: Task, { interval = 250 }: { interval?: number } = {})

Source from the content-addressed store, hash-verified

26}
27
28export async function getCheckpointService(task: Task, { interval = 250 }: { interval?: number } = {}) {
29 if (!task.enableCheckpoints) {
30 return undefined
31 }
32
33 if (task.checkpointService) {
34 return task.checkpointService
35 }
36
37 const provider = task.providerRef.deref()
38
39 // Get checkpoint timeout from task settings (converted to milliseconds)
40 const checkpointTimeoutMs = task.checkpointTimeout * 1000
41
42 const log = (message: string) => {
43 console.log(message)
44
45 try {
46 provider?.log(message)
47 } catch (err) {
48 // NO-OP
49 }
50 }
51
52 console.log("[Task#getCheckpointService] initializing checkpoints service")
53
54 try {
55 const workspaceDir = task.cwd || getWorkspacePath()
56
57 if (!workspaceDir) {
58 log("[Task#getCheckpointService] workspace folder not found, disabling checkpoints")
59 task.enableCheckpoints = false
60 return undefined
61 }
62
63 const globalStorageDir = provider?.context.globalStorageUri.fsPath
64
65 if (!globalStorageDir) {
66 log("[Task#getCheckpointService] globalStorageDir not found, disabling checkpoints")
67 task.enableCheckpoints = false
68 return undefined
69 }
70
71 const options: CheckpointServiceOptions = {
72 taskId: task.taskId,
73 workspaceDir,
74 shadowDir: globalStorageDir,
75 log,
76 }
77
78 if (task.checkpointServiceInitializing) {
79 const checkpointInitStartTime = Date.now()
80 let warningShown = false
81
82 await pWaitFor(
83 () => {
84 const elapsed = Date.now() - checkpointInitStartTime
85

Callers 5

initiateTaskLoopMethod · 0.90
checkpoint.test.tsFile · 0.90
checkpointSaveFunction · 0.85
checkpointRestoreFunction · 0.85
checkpointDiffFunction · 0.85

Calls 6

getWorkspacePathFunction · 0.90
sendCheckpointInitWarnFunction · 0.85
checkGitInstallationFunction · 0.85
logFunction · 0.70
logMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected