MCPcopy Index your code
hub / github.com/ByBrawe/opencode-loop / setGoalComplete

Function setGoalComplete

src/index.js:1051–1067  ·  view source on GitHub ↗
(directory, sessionID, args = {})

Source from the content-addressed store, hash-verified

1049 if (job.maxRuntimeMs > 0 && current - created >= job.maxRuntimeMs) return current
1050 if (job.intervalMs === 0) return current
1051 if (!job.lastRunAt) return current
1052 return job.lastRunAt + (job.intervalMs || 0)
1053}
1054
1055function nextDueDelay(state) {
1056 const current = now()
1057 let soonest = Infinity
1058 for (const job of state.jobs || []) soonest = Math.min(soonest, jobDueAt(job, current))
1059 if (!Number.isFinite(soonest)) return Infinity
1060 return Math.max(0, soonest - current)
1061}
1062
1063async function startWatchdog(directory, client, sessionID) {
1064 if (watchdogTimers.has(sessionID)) return
1065 const timer = setInterval(() => {
1066 Promise.resolve()
1067 .then(async () => {
1068 const state = await readState(directory, sessionID)
1069 const delay = nextDueDelay(state)
1070 const hasJobs = (state.jobs || []).some((job) => job.enabled !== false && !job.paused && (!isGoalJob(job) || !["completed", "blocked", "cleared"].includes(job.goalStatus)))

Callers 2

completeGoalCommandFunction · 0.85
goalToolsFunction · 0.85

Calls 7

readStateFunction · 0.85
pickGoalJobFunction · 0.85
parseGoalToolTextFunction · 0.85
nowFunction · 0.85
writeStateFunction · 0.85
writeGoalReportFunction · 0.85
appendLoopLogFunction · 0.85

Tested by

no test coverage detected