MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / requestManagedAutonomyFlowCancel

Function requestManagedAutonomyFlowCancel

src/utils/autonomyFlows.ts:937–1009  ·  view source on GitHub ↗
(params: {
  flowId: string
  rootDir?: string
  nowMs?: number
})

Source from the content-addressed store, hash-verified

935}
936
937export async function requestManagedAutonomyFlowCancel(params: {
938 flowId: string
939 rootDir?: string
940 nowMs?: number
941}): Promise<ManagedAutonomyFlowCancelResult | null> {
942 const rootDir = resolve(params.rootDir ?? getProjectRoot())
943 const nowMs = params.nowMs ?? Date.now()
944 return withAutonomyPersistenceLock(rootDir, async () => {
945 const flows = await listAutonomyFlows(rootDir)
946 const index = flows.findIndex(flow => flow.flowId === params.flowId)
947 if (index === -1) {
948 return null
949 }
950 const current = cloneFlowRecord(flows[index]!)
951 const queuedRunIds =
952 current.stateJson?.steps
953 .filter(
954 step => step.status === 'queued' && typeof step.runId === 'string',
955 )
956 .map(step => step.runId!) ?? []
957
958 if (!isManagedFlowStatusActive(current.status)) {
959 return {
960 flow: current,
961 queuedRunIds,
962 accepted: false,
963 }
964 }
965
966 const state = cloneManagedState(current.stateJson)
967 if (!state) {
968 return {
969 flow: current,
970 queuedRunIds,
971 accepted: false,
972 }
973 }
974
975 const next =
976 current.status === 'running'
977 ? normalizeFlowRecord({
978 ...current,
979 revision: current.revision + 1,
980 updatedAt: nowMs,
981 cancelRequestedAt: current.cancelRequestedAt ?? nowMs,
982 })
983 : normalizeFlowRecord({
984 ...current,
985 revision: current.revision + 1,
986 status: 'cancelled',
987 updatedAt: nowMs,
988 endedAt: nowMs,
989 currentStep: undefined,
990 waitJson: undefined,
991 stateJson: (() => {
992 markRemainingStepsCancelled(state, state.currentStepIndex, nowMs)
993 return state
994 })(),

Callers 2

cancelAutonomyFlowTextFunction · 0.85

Calls 11

getProjectRootFunction · 0.85
listAutonomyFlowsFunction · 0.85
cloneFlowRecordFunction · 0.85
cloneManagedStateFunction · 0.85
normalizeFlowRecordFunction · 0.85
writeAutonomyFlowsFunction · 0.85
nowMethod · 0.80
resolveFunction · 0.70

Tested by

no test coverage detected