MCPcopy Create free account
hub / github.com/ByBrawe/opencode-loop / sessionStatusType

Function sessionStatusType

src/index.js:828–860  ·  view source on GitHub ↗
(client, sessionID, directory, options = {})

Source from the content-addressed store, hash-verified

826 return job
827}
828
829async function maybeCompact(client, sessionID, job) {
830 const dueRuns = job.compactEveryRuns > 0 && (job.runCount || 0) > 0 && (job.runCount || 0) % job.compactEveryRuns === 0 && job.lastCompactRunCount !== job.runCount
831 const dueTime = job.compactEveryMs > 0 && (!job.lastCompactAt || now() - job.lastCompactAt >= job.compactEveryMs)
832 if (!dueRuns && !dueTime) return job
833 if (await compactSession(client, sessionID)) {
834 job.lastCompactAt = now()
835 job.lastCompactRunCount = job.runCount || 0
836 }
837 return job
838}
839
840async function snapshotPaths(directory, files) {
841 const snapshot = {}
842 for (const file of files || []) {
843 try {
844 const stat = await fs.stat(path.resolve(directory, file))
845 snapshot[file] = `${stat.mtimeMs}:${stat.size}`
846 } catch { snapshot[file] = "missing" }
847 }
848 return snapshot
849}
850
851async function watchChanged(directory, job) {
852 if (!job.watchPaths?.length) return false
853 const next = await snapshotPaths(directory, job.watchPaths)
854 const previous = job.watchSnapshot || {}
855 const changed = job.watchPaths.some((file) => previous[file] !== next[file])
856 if (changed) job.watchSnapshot = next
857 return changed
858}
859
860async function fileContains(filePath, needle) {
861 try {
862 const stat = await fs.stat(filePath)
863 if (!stat.isFile() || stat.size > MAX_SCAN_BYTES) return false

Callers 1

sessionIsIdleFunction · 0.85

Calls 3

nowFunction · 0.85
readLiveSessionStatusFunction · 0.85
staleActiveRunFunction · 0.85

Tested by

no test coverage detected