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

Function startManagedAutonomyFlow

src/utils/autonomyFlows.ts:469–563  ·  view source on GitHub ↗
(params: {
  trigger: AutonomyTriggerKind
  goal: string
  steps: ManagedAutonomyFlowStepDefinition[]
  rootDir?: string
  currentDir?: string
  ownerKey?: string
  sourceId?: string
  sourceLabel?: string
  boundary?: string[]
  nowMs?: number
})

Source from the content-addressed store, hash-verified

467}
468
469export async function startManagedAutonomyFlow(params: {
470 trigger: AutonomyTriggerKind
471 goal: string
472 steps: ManagedAutonomyFlowStepDefinition[]
473 rootDir?: string
474 currentDir?: string
475 ownerKey?: string
476 sourceId?: string
477 sourceLabel?: string
478 boundary?: string[]
479 nowMs?: number
480}): Promise<ManagedAutonomyFlowStartResult | null> {
481 if (params.steps.length === 0) {
482 return null
483 }
484 const rootDir = resolve(params.rootDir ?? getProjectRoot())
485 const currentDir = resolve(params.currentDir ?? rootDir)
486 const source = defaultFlowSource(params)
487 const flowKey = createManagedAutonomyFlowKey({
488 trigger: params.trigger,
489 sourceId: source.sourceId,
490 sourceLabel: source.sourceLabel,
491 goal: params.goal,
492 })
493 const nowMs = params.nowMs ?? Date.now()
494
495 return withAutonomyPersistenceLock(rootDir, async () => {
496 const flows = await listAutonomyFlows(rootDir)
497 const index = flows.findIndex(flow => flow.flowKey === flowKey)
498 const current = index === -1 ? null : flows[index]!
499
500 if (current && isManagedFlowStatusActive(current.status)) {
501 return {
502 flow: current,
503 started: false,
504 }
505 }
506
507 const stateJson = buildManagedState(params.steps)
508 const firstStep = stateJson.steps[0]!
509 const boundary =
510 normalizeBoundary(params.boundary) ?? normalizeBoundary(current?.boundary)
511 const waiting =
512 firstStep.waitFor != null
513 ? {
514 reason: firstStep.waitFor,
515 stepId: firstStep.stepId,
516 stepName: firstStep.name,
517 stepIndex: 0,
518 }
519 : undefined
520
521 const next: AutonomyFlowRecord = normalizeFlowRecord({
522 flowId: current?.flowId ?? randomUUID(),
523 flowKey,
524 syncMode: 'managed',
525 ownerKey:
526 params.ownerKey ?? current?.ownerKey ?? DEFAULT_AUTONOMY_OWNER_KEY,

Calls 13

getProjectRootFunction · 0.85
defaultFlowSourceFunction · 0.85
listAutonomyFlowsFunction · 0.85
buildManagedStateFunction · 0.85
normalizeBoundaryFunction · 0.85
normalizeFlowRecordFunction · 0.85
writeAutonomyFlowsFunction · 0.85
buildQueueInstructionFunction · 0.85
nowMethod · 0.80

Tested by

no test coverage detected