{"version":3,"file":"delegation.cjs","names":[],"sources":["../src/schemas/team/delegation.ts"],"sourcesContent":["/**\n * Subagent delegation - a cross-extension event protocol.\n *\n * Delegation lets another extension ask this runtime to run a subagent without\n * depending on its internals: the requester emits a request event and receives\n * started/update/response events back over the host event bus.\n *\n * Two generations coexist. V1 correlates purely by `requestId`. V2 adds\n * `ownerRunId` and `nodeId` so one owner can fan out to many nodes and have each\n * reply routed back, and it carries a typed `result` request.\n *\n * PROTOCOL COMPATIBILITY (do not change):\n * The event names and version numbers below are shared with doom-pi-subagents\n * and with doom-task and agiflow-pi-extension, which speak this protocol today.\n * The event names deliberately keep their `prompt-template:` prefix: that is the\n * established transport, and renaming it would silently stop delivery. Pinned by\n * contract tests.\n *\n * AVOID:\n * - Adding a required field to an existing version; add a version instead\n */\n\nexport const SUBAGENT_DELEGATION_PROTOCOL_VERSION = 1 as const;\nexport const SUBAGENT_DELEGATION_V2_PROTOCOL_VERSION = 2 as const;\n\n// This is the established extension-to-extension transport. The public API\n// intentionally reuses it instead of adding a second event protocol.\nexport const SUBAGENT_DELEGATION_REQUEST_EVENT = 'prompt-template:subagent:request';\nexport const SUBAGENT_DELEGATION_STARTED_EVENT = 'prompt-template:subagent:started';\nexport const SUBAGENT_DELEGATION_UPDATE_EVENT = 'prompt-template:subagent:update';\nexport const SUBAGENT_DELEGATION_RESPONSE_EVENT = 'prompt-template:subagent:response';\nexport const SUBAGENT_DELEGATION_CANCEL_EVENT = 'prompt-template:subagent:cancel';\n\nexport interface SubagentDelegationTurnBudget {\n  maxTurns: number;\n  graceTurns?: number;\n}\n\nexport interface SubagentDelegationToolBudget {\n  soft?: number;\n  hard: number;\n  block?: string[] | '*';\n}\n\nexport interface SubagentDelegationAgentContract {\n  version: 1;\n}\n\nexport type SubagentDelegationJsonSchemaObject = Record<string, unknown>;\n\nexport interface SubagentDelegationExecutionResult {\n  status: 'completed' | 'failed' | 'paused' | 'stopped' | 'detached';\n  success: boolean;\n  exitCode: number;\n  error?: string;\n  interrupted?: boolean;\n  timedOut?: boolean;\n  stopped?: boolean;\n  detached?: boolean;\n}\n\nexport interface SubagentDelegationReviewResult {\n  status: 'not-requested' | 'review-required' | 'reviewed' | 'blockers';\n  findings?: Array<{ severity: 'blocker' | 'non-blocking'; file?: string; issue: string; rationale: string }>;\n}\n\nexport interface SubagentDelegationEffectsResult {\n  fileMutation?: {\n    status: 'not-requested' | 'not-applicable' | 'observed' | 'missing';\n    expected: boolean;\n    attempted: boolean;\n    message?: string;\n  };\n}\n\nexport type SubagentDelegationAcceptanceEvidence =\n  | 'changed-files'\n  | 'tests-added'\n  | 'commands-run'\n  | 'validation-output'\n  | 'residual-risks'\n  | 'no-staged-files'\n  | 'diff-summary'\n  | 'review-findings'\n  | 'manual-notes';\n\nexport interface SubagentDelegationAcceptanceCriterion {\n  id: string;\n  must: string;\n  evidence?: SubagentDelegationAcceptanceEvidence[];\n  severity?: 'required' | 'recommended';\n}\n\nexport interface SubagentDelegationAcceptanceVerifyCommand {\n  id: string;\n  command: string;\n  timeoutMs?: number;\n  cwd?: string;\n  env?: Record<string, string>;\n  allowFailure?: boolean;\n}\n\nexport interface SubagentDelegationAcceptanceReview {\n  agent?: string;\n  focus?: string;\n  required?: boolean;\n}\n\ninterface SubagentDelegationAcceptanceFields {\n  criteria?: Array<string | SubagentDelegationAcceptanceCriterion>;\n  evidence?: SubagentDelegationAcceptanceEvidence[];\n  verify?: SubagentDelegationAcceptanceVerifyCommand[];\n  review?: SubagentDelegationAcceptanceReview | false;\n  stopRules?: string[];\n}\n\nexport type SubagentDelegationAcceptanceConfig = SubagentDelegationAcceptanceFields &\n  ({ level: 'none'; reason: string } | { level?: 'auto' | 'attested' | 'checked' | 'verified'; reason?: string });\n\nexport type SubagentDelegationAcceptance =\n  | 'auto'\n  | 'attested'\n  | 'checked'\n  | 'verified'\n  | false\n  | SubagentDelegationAcceptanceConfig;\n\nexport interface SubagentDelegationRequest {\n  version: typeof SUBAGENT_DELEGATION_PROTOCOL_VERSION;\n  requestId: string;\n  agent: string;\n  task: string;\n  context: 'fresh' | 'fork';\n  cwd: string;\n  model?: string;\n  timeoutMs?: number;\n  turnBudget?: SubagentDelegationTurnBudget;\n  toolBudget?: SubagentDelegationToolBudget;\n  skill?: string | string[] | boolean;\n  output?: string | boolean;\n  outputMode?: 'inline' | 'file-only';\n  outputSchema?: SubagentDelegationJsonSchemaObject;\n  agentContract?: SubagentDelegationAgentContract;\n  acceptance?: SubagentDelegationAcceptance;\n  artifacts?: boolean;\n  /** Foreground remains the compatibility default. */\n  runMode?: 'foreground' | 'detached';\n  /** Optional task identity shown to active root-session teammates. */\n  teamTask?: { id: string; subject: string };\n}\n\nexport interface SubagentDelegationStarted {\n  version: typeof SUBAGENT_DELEGATION_PROTOCOL_VERSION;\n  requestId: string;\n  runId?: string;\n}\n\nexport interface SubagentDelegationUpdate extends SubagentDelegationStarted {\n  runId?: string;\n  currentTool?: string;\n  currentToolArgs?: string;\n  recentOutput?: string;\n  recentOutputLines?: string[];\n  recentTools?: Array<{ tool: string; args: string }>;\n  model?: string;\n  toolCount?: number;\n  durationMs?: number;\n  tokens?: number;\n}\n\nexport type SubagentDelegationStatus =\n  | 'completed'\n  | 'failed'\n  | 'timed_out'\n  | 'cancelled'\n  | 'interrupted'\n  | 'turn_budget_exhausted'\n  | 'tool_budget_exhausted'\n  | 'structured_output_failed'\n  | 'acceptance_failed'\n  | 'invalid_request'\n  | 'unavailable_context';\n\nexport type SubagentDelegationAcceptanceStatus =\n  | 'pending'\n  | 'not-required'\n  | 'claimed'\n  | 'attested'\n  | 'checked'\n  | 'verified'\n  | 'review-required'\n  | 'reviewed'\n  | 'accepted'\n  | 'rejected';\n\nexport interface SubagentDelegationAcceptanceResult {\n  status: SubagentDelegationAcceptanceStatus;\n  evidenceStatus: Exclude<SubagentDelegationAcceptanceStatus, 'review-required' | 'reviewed' | 'accepted'>;\n  explicit: boolean;\n}\n\nexport interface SubagentDelegationResponse extends SubagentDelegationStarted {\n  status: SubagentDelegationStatus;\n  error?: string;\n  runId?: string;\n  childIndex?: number;\n  agent?: string;\n  model?: string;\n  exitCode?: number;\n  execution?: SubagentDelegationExecutionResult;\n  output?: string;\n  outputPath?: string;\n  sessionFile?: string;\n  acceptance?: SubagentDelegationAcceptanceResult;\n  review?: SubagentDelegationReviewResult;\n  effects?: SubagentDelegationEffectsResult;\n  turns?: number;\n  toolCount?: number;\n  durationMs?: number;\n  tokens?: number;\n  warnings?: string[];\n}\n\nexport interface SubagentDelegationCancel extends SubagentDelegationStarted {}\n\nexport type SubagentDelegationV2Thinking = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n\nexport type SubagentDelegationV2ResultRequest =\n  | { kind: 'text' }\n  | { kind: 'structured'; schema: SubagentDelegationJsonSchemaObject };\n\nexport interface SubagentDelegationV2Request {\n  version: typeof SUBAGENT_DELEGATION_V2_PROTOCOL_VERSION;\n  requestId: string;\n  ownerRunId: string;\n  nodeId: string;\n  agent: string;\n  task: string;\n  context: 'fresh' | 'fork';\n  cwd: string;\n  model?: string;\n  thinking?: SubagentDelegationV2Thinking;\n  timeoutMs?: number;\n  turnBudget?: SubagentDelegationTurnBudget;\n  toolBudget?: SubagentDelegationToolBudget;\n  skill?: string | string[] | boolean;\n  artifacts?: boolean;\n  result: SubagentDelegationV2ResultRequest;\n}\n\nexport interface SubagentDelegationV2Started {\n  version: typeof SUBAGENT_DELEGATION_V2_PROTOCOL_VERSION;\n  requestId: string;\n  ownerRunId: string;\n  nodeId: string;\n}\n\nexport interface SubagentDelegationV2Update extends SubagentDelegationV2Started {\n  runId?: string;\n  currentTool?: string;\n  currentToolArgs?: string;\n  recentOutput?: string;\n  recentOutputLines?: string[];\n  recentTools?: Array<{ tool: string; args: string }>;\n  model?: string;\n  toolCount?: number;\n  durationMs?: number;\n  tokens?: number;\n}\n\nexport type SubagentDelegationV2Status = SubagentDelegationStatus | 'duplicate_node';\n\nexport type SubagentDelegationV2Value = { kind: 'text'; text: string } | { kind: 'structured'; value: unknown };\n\nexport interface SubagentDelegationV2Usage {\n  input: number;\n  output: number;\n  cacheRead: number;\n  cacheWrite: number;\n  cost: number;\n  turns: number;\n  toolCalls: number;\n  durationMs: number;\n}\n\nexport interface SubagentDelegationV2TerminalResponse extends SubagentDelegationV2Started {\n  status: Exclude<SubagentDelegationV2Status, 'invalid_request'>;\n  error?: string;\n  runId?: string;\n  agent?: string;\n  model?: string;\n  thinking?: string;\n  exitCode?: number;\n  launchContractDigest?: string;\n  result?: SubagentDelegationV2Value;\n  usage?: SubagentDelegationV2Usage;\n}\n\n/** A malformed V2 request can only be correlated by the valid identity fields it supplied. */\nexport interface SubagentDelegationV2InvalidResponse {\n  version: typeof SUBAGENT_DELEGATION_V2_PROTOCOL_VERSION;\n  requestId: string;\n  ownerRunId?: string;\n  nodeId?: string;\n  status: 'invalid_request';\n  error?: string;\n}\n\nexport type SubagentDelegationV2Response = SubagentDelegationV2TerminalResponse | SubagentDelegationV2InvalidResponse;\n\nexport interface SubagentDelegationV2Cancel extends SubagentDelegationV2Started {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,uCAAuC;AACpD,MAAa,0CAA0C;AAIvD,MAAa,oCAAoC;AACjD,MAAa,oCAAoC;AACjD,MAAa,mCAAmC;AAChD,MAAa,qCAAqC;AAClD,MAAa,mCAAmC"}