MCPcopy
hub / github.com/KeygraphHQ/shannon / restoreGitCheckpoint

Function restoreGitCheckpoint

apps/worker/src/temporal/activities.ts:919–964  ·  view source on GitHub ↗
(
  repoPath: string,
  checkpointHash: string,
  incompleteAgents: AgentName[],
  deliverablesSubdir?: string,
)

Source from the content-addressed store, hash-verified

917 * Operates on the private git inside workspace deliverables, not the user's repo.
918 */
919export async function restoreGitCheckpoint(
920 repoPath: string,
921 checkpointHash: string,
922 incompleteAgents: AgentName[],
923 deliverablesSubdir?: string,
924): Promise<void> {
925 const deliverablesPath = deliverablesDir(repoPath, deliverablesSubdir);
926 const logger = createActivityLogger();
927 logger.info(`Restoring deliverables to ${checkpointHash}...`);
928
929 // Validate hash exists in this clone before attempting reset
930 try {
931 await executeGitCommandWithRetry(
932 ['git', 'rev-parse', '--verify', checkpointHash],
933 repoPath,
934 'verify checkpoint hash exists',
935 );
936 } catch {
937 logger.info(`Checkpoint hash not found in clone, skipping git reset: ${checkpointHash}`);
938 return;
939 }
940
941 await executeGitCommandWithRetry(
942 ['git', 'reset', '--hard', checkpointHash],
943 deliverablesPath,
944 'reset deliverables to checkpoint',
945 );
946 await executeGitCommandWithRetry(['git', 'clean', '-fd'], deliverablesPath, 'clean untracked deliverables');
947
948 // Explicitly delete partial deliverables for incomplete agents
949 for (const agentName of incompleteAgents) {
950 const deliverableFilename = AGENTS[agentName].deliverableFilename;
951 const deliverablePath = path.join(deliverablesPath, deliverableFilename);
952 try {
953 const exists = await fileExists(deliverablePath);
954 if (exists) {
955 logger.warn(`Cleaning partial deliverable: ${agentName}`);
956 await fs.unlink(deliverablePath);
957 }
958 } catch (error) {
959 logger.info(`Note: Failed to delete ${deliverablePath}: ${error}`);
960 }
961 }
962
963 logger.info('Deliverables restored to clean state');
964}
965
966/**
967 * Record a resume attempt in session.json and write resume header to workflow.log.

Callers

nothing calls this directly

Calls 6

deliverablesDirFunction · 0.85
createActivityLoggerFunction · 0.85
fileExistsFunction · 0.85
infoMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected