@cat-factory/orchestration 0.192.0 → 0.194.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/container/dependencies.d.ts +5 -1
  2. package/dist/container/dependencies.d.ts.map +1 -1
  3. package/dist/container/engine-collaborators.d.ts.map +1 -1
  4. package/dist/container/engine-collaborators.js +4 -7
  5. package/dist/container/engine-collaborators.js.map +1 -1
  6. package/dist/container/execution-service.d.ts.map +1 -1
  7. package/dist/container/execution-service.js +3 -0
  8. package/dist/container/execution-service.js.map +1 -1
  9. package/dist/container/inline-model-deps.d.ts +20 -0
  10. package/dist/container/inline-model-deps.d.ts.map +1 -0
  11. package/dist/container/inline-model-deps.js +38 -0
  12. package/dist/container/inline-model-deps.js.map +1 -0
  13. package/dist/container/modules.d.ts.map +1 -1
  14. package/dist/container/modules.js +23 -39
  15. package/dist/container/modules.js.map +1 -1
  16. package/dist/container/review-modules.d.ts.map +1 -1
  17. package/dist/container/review-modules.js +10 -28
  18. package/dist/container/review-modules.js.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/inlineBlockModel.d.ts +51 -0
  24. package/dist/inlineBlockModel.d.ts.map +1 -0
  25. package/dist/inlineBlockModel.js +31 -0
  26. package/dist/inlineBlockModel.js.map +1 -0
  27. package/dist/modules/board/BoardService.d.ts +2 -0
  28. package/dist/modules/board/BoardService.d.ts.map +1 -1
  29. package/dist/modules/board/BoardService.js +4 -0
  30. package/dist/modules/board/BoardService.js.map +1 -1
  31. package/dist/modules/board/publicBoardReads.d.ts +12 -0
  32. package/dist/modules/board/publicBoardReads.d.ts.map +1 -1
  33. package/dist/modules/board/publicBoardReads.js +19 -4
  34. package/dist/modules/board/publicBoardReads.js.map +1 -1
  35. package/dist/modules/bugHunt/BugHuntAssessorService.d.ts +8 -4
  36. package/dist/modules/bugHunt/BugHuntAssessorService.d.ts.map +1 -1
  37. package/dist/modules/bugHunt/BugHuntAssessorService.js +6 -10
  38. package/dist/modules/bugHunt/BugHuntAssessorService.js.map +1 -1
  39. package/dist/modules/docInterview/DocInterviewService.d.ts +8 -4
  40. package/dist/modules/docInterview/DocInterviewService.d.ts.map +1 -1
  41. package/dist/modules/docInterview/DocInterviewService.js +4 -13
  42. package/dist/modules/docInterview/DocInterviewService.js.map +1 -1
  43. package/dist/modules/execution/AgentContextBuilder.d.ts +14 -12
  44. package/dist/modules/execution/AgentContextBuilder.d.ts.map +1 -1
  45. package/dist/modules/execution/AgentContextBuilder.js +8 -28
  46. package/dist/modules/execution/AgentContextBuilder.js.map +1 -1
  47. package/dist/modules/execution/AgentDispatchController.d.ts +115 -0
  48. package/dist/modules/execution/AgentDispatchController.d.ts.map +1 -0
  49. package/dist/modules/execution/AgentDispatchController.js +307 -0
  50. package/dist/modules/execution/AgentDispatchController.js.map +1 -0
  51. package/dist/modules/execution/ExecutionService.d.ts +18 -105
  52. package/dist/modules/execution/ExecutionService.d.ts.map +1 -1
  53. package/dist/modules/execution/ExecutionService.js +70 -589
  54. package/dist/modules/execution/ExecutionService.js.map +1 -1
  55. package/dist/modules/execution/ExecutionServiceDependencies.d.ts +19 -3
  56. package/dist/modules/execution/ExecutionServiceDependencies.d.ts.map +1 -1
  57. package/dist/modules/execution/ForkChatService.d.ts +8 -4
  58. package/dist/modules/execution/ForkChatService.d.ts.map +1 -1
  59. package/dist/modules/execution/ForkChatService.js +4 -13
  60. package/dist/modules/execution/ForkChatService.js.map +1 -1
  61. package/dist/modules/execution/IterationCapController.d.ts +57 -0
  62. package/dist/modules/execution/IterationCapController.d.ts.map +1 -0
  63. package/dist/modules/execution/IterationCapController.js +141 -0
  64. package/dist/modules/execution/IterationCapController.js.map +1 -0
  65. package/dist/modules/execution/JudgeService.d.ts +8 -4
  66. package/dist/modules/execution/JudgeService.d.ts.map +1 -1
  67. package/dist/modules/execution/JudgeService.js +4 -13
  68. package/dist/modules/execution/JudgeService.js.map +1 -1
  69. package/dist/modules/execution/RunAdmission.d.ts +1 -1
  70. package/dist/modules/execution/RunAdmission.d.ts.map +1 -1
  71. package/dist/modules/execution/RunAdmission.js +5 -2
  72. package/dist/modules/execution/RunAdmission.js.map +1 -1
  73. package/dist/modules/execution/RunDispatcher.d.ts +31 -195
  74. package/dist/modules/execution/RunDispatcher.d.ts.map +1 -1
  75. package/dist/modules/execution/RunDispatcher.js +47 -313
  76. package/dist/modules/execution/RunDispatcher.js.map +1 -1
  77. package/dist/modules/execution/RunDispatcherDependencies.d.ts +142 -0
  78. package/dist/modules/execution/RunDispatcherDependencies.d.ts.map +1 -0
  79. package/dist/modules/execution/RunDispatcherDependencies.js +27 -0
  80. package/dist/modules/execution/RunDispatcherDependencies.js.map +1 -0
  81. package/dist/modules/execution/RunLifecycleController.d.ts +141 -0
  82. package/dist/modules/execution/RunLifecycleController.d.ts.map +1 -0
  83. package/dist/modules/execution/RunLifecycleController.js +489 -0
  84. package/dist/modules/execution/RunLifecycleController.js.map +1 -0
  85. package/dist/modules/execution/TesterQualityReviewService.d.ts +8 -4
  86. package/dist/modules/execution/TesterQualityReviewService.d.ts.map +1 -1
  87. package/dist/modules/execution/TesterQualityReviewService.js +4 -13
  88. package/dist/modules/execution/TesterQualityReviewService.js.map +1 -1
  89. package/dist/modules/execution/dispatchPromptSettings.d.ts +42 -2
  90. package/dist/modules/execution/dispatchPromptSettings.d.ts.map +1 -1
  91. package/dist/modules/execution/dispatchPromptSettings.js +37 -0
  92. package/dist/modules/execution/dispatchPromptSettings.js.map +1 -1
  93. package/dist/modules/execution/run-action-controllers.d.ts +18 -0
  94. package/dist/modules/execution/run-action-controllers.d.ts.map +1 -0
  95. package/dist/modules/execution/run-action-controllers.js +19 -0
  96. package/dist/modules/execution/run-action-controllers.js.map +1 -0
  97. package/dist/modules/execution/run-context-admission.d.ts +1 -1
  98. package/dist/modules/execution/run-context-admission.d.ts.map +1 -1
  99. package/dist/modules/execution/run-context-admission.js +2 -0
  100. package/dist/modules/execution/run-context-admission.js.map +1 -1
  101. package/dist/modules/initiative/InitiativeInterviewService.d.ts +8 -4
  102. package/dist/modules/initiative/InitiativeInterviewService.d.ts.map +1 -1
  103. package/dist/modules/initiative/InitiativeInterviewService.js +4 -13
  104. package/dist/modules/initiative/InitiativeInterviewService.js.map +1 -1
  105. package/dist/modules/kaizen/KaizenService.d.ts +14 -9
  106. package/dist/modules/kaizen/KaizenService.d.ts.map +1 -1
  107. package/dist/modules/kaizen/KaizenService.js +11 -16
  108. package/dist/modules/kaizen/KaizenService.js.map +1 -1
  109. package/dist/modules/modelPresets/ModelPresetService.d.ts +54 -2
  110. package/dist/modules/modelPresets/ModelPresetService.d.ts.map +1 -1
  111. package/dist/modules/modelPresets/ModelPresetService.js +103 -4
  112. package/dist/modules/modelPresets/ModelPresetService.js.map +1 -1
  113. package/dist/modules/review/IterativeReviewService.d.ts +8 -4
  114. package/dist/modules/review/IterativeReviewService.d.ts.map +1 -1
  115. package/dist/modules/review/IterativeReviewService.js +4 -13
  116. package/dist/modules/review/IterativeReviewService.js.map +1 -1
  117. package/package.json +11 -11
@@ -0,0 +1,142 @@
1
+ import type { AgentExecutor, Block, BlockRepository, BrainstormSession, ClarityReview, Clock, ExecutionEventPublisher, ExecutionRepository, GateOutcomeRepository, GateRegistry, IdGenerator, IssueWritebackProvider, JudgeAssessor, JudgeRegistry, Logger, ProviderCapabilities, ProviderRegistry, RequirementConcernLevel, RequirementReview, ResolveRunRepoContext, RunInitiatorScope, StepGating, StepResolverRegistry, TicketTrackerProvider, WorkRunner } from '@cat-factory/kernel';
2
+ import type { SettledGate } from '../observability/GateOutcomeRecorder.js';
3
+ import type { AgentKindRegistry } from '@cat-factory/agents';
4
+ import type { BugIntakeService, EnvironmentProvisioningService } from '@cat-factory/integrations';
5
+ import type { SpendService } from '@cat-factory/spend';
6
+ import type { AgentContextBuilder, FragmentBodyResolver } from './AgentContextBuilder.js';
7
+ import type { CompanionController } from './CompanionController.js';
8
+ import type { ForkDecisionController } from './ForkDecisionController.js';
9
+ import type { HumanTestController } from './HumanTestController.js';
10
+ import type { InterviewGateController } from './InterviewGateController.js';
11
+ import type { MergeResolver } from './MergeResolver.js';
12
+ import type { PrReviewController } from './PrReviewController.js';
13
+ import type { PrVerificationReportController } from './PrVerificationReportController.js';
14
+ import type { RalphController } from './RalphController.js';
15
+ import type { ReviewGateController, ReviewKind } from './ReviewGateController.js';
16
+ import type { RunStateMachine } from './RunStateMachine.js';
17
+ import type { StepGraph } from './StepGraph.js';
18
+ import type { TesterController } from './TesterController.js';
19
+ import type { VisualConfirmationController } from './VisualConfirmationController.js';
20
+ import type { BlueprintReconciler } from './ExecutionService.js';
21
+ import type { InitiativeService } from '../initiative/InitiativeService.js';
22
+ import type { NotificationService } from '../notifications/NotificationService.js';
23
+ export /**
24
+ * The task's fully-resolved merge-threshold preset (block pin → workspace default →
25
+ * built-in). The dispatcher only reads the gate-relevant fields; the full shape is kept so
26
+ * a gate's `attemptBudget(preset)` sees every knob. Mirrors {@link ExecutionService.resolveRiskPolicy}.
27
+ */ type ResolvedRiskPolicy = {
28
+ maxComplexity: number;
29
+ maxRisk: number;
30
+ maxImpact: number;
31
+ ciMaxAttempts: number;
32
+ maxRequirementIterations: number;
33
+ maxRequirementConcernAllowed: RequirementConcernLevel;
34
+ judgeMinScore: number;
35
+ judgeMaxBounces: number;
36
+ releaseWatchWindowMinutes: number;
37
+ releaseMaxAttempts: number;
38
+ humanReviewGraceMinutes: number;
39
+ forkDecision?: StepGating | null;
40
+ };
41
+ /** Collaborators + leaf dependencies the {@link RunDispatcher} needs. */
42
+ export interface RunDispatcherDeps {
43
+ blockRepository: BlockRepository;
44
+ executionRepository: ExecutionRepository;
45
+ agentExecutor: AgentExecutor;
46
+ /** App-owned agent-kind registry: a registered kind's step spec + pre/post-op hooks. */
47
+ agentKindRegistry: AgentKindRegistry;
48
+ /** App-owned polling-gate registry (built-ins installed by the facade via `registerBuiltinGates`). */
49
+ gateRegistry: GateRegistry;
50
+ /**
51
+ * The app-owned JUDGE registry (the fourth step-taxonomy bucket) the composition root
52
+ * injected, plus the verdict producer. An absent / disabled assessor makes every judge step
53
+ * a pass-through, which is exactly what a deployment with no model wired (and the
54
+ * conformance/e2e suites) gets. See `docs/initiatives/judge-registry.md`.
55
+ */
56
+ judgeRegistry: JudgeRegistry;
57
+ judgeAssessor?: JudgeAssessor;
58
+ /**
59
+ * The prompt-fragment library, used by the judge driver for ONE thing: resolving a rubric's
60
+ * per-workspace override body (see `JudgeRubric.fragmentId`). Absent ⇒ the registration's
61
+ * default rubric.
62
+ */
63
+ fragmentResolver?: FragmentBodyResolver;
64
+ /** App-owned step-completion-resolver registry (deployment-registered resolvers). */
65
+ stepResolverRegistry: StepResolverRegistry;
66
+ /** App-owned provider registry the gate machine's {@link GateContext} reads (gate data sources). */
67
+ providerRegistry: ProviderRegistry;
68
+ workRunner: WorkRunner;
69
+ events: ExecutionEventPublisher;
70
+ idGenerator: IdGenerator;
71
+ clock: Clock;
72
+ /**
73
+ * Where the dispatcher's best-effort hooks (issue writeback, lease release, repo ops) report
74
+ * their drops. Absent ⇒ `noopLogger`, which is what the engine unit tests construct with.
75
+ */
76
+ logger?: Logger;
77
+ /**
78
+ * Optional settled-gate projection: the gate machine records each terminal verdict into it
79
+ * for the operator dashboard's attempt statistics. Absent ⇒ nothing is recorded.
80
+ */
81
+ gateOutcomeRepository?: GateOutcomeRepository;
82
+ spend: SpendService;
83
+ stepGraph: StepGraph;
84
+ runStateMachine: RunStateMachine;
85
+ contextBuilder: AgentContextBuilder;
86
+ mergeResolver: MergeResolver;
87
+ companionController: CompanionController;
88
+ testerController: TesterController;
89
+ ralphController: RalphController;
90
+ humanTestController: HumanTestController;
91
+ visualConfirmationController: VisualConfirmationController;
92
+ reviewGate: ReviewGateController;
93
+ forkDecisionController: ForkDecisionController;
94
+ prReviewController: PrReviewController;
95
+ requirementsKind: ReviewKind<RequirementReview>;
96
+ clarityKind: ReviewKind<ClarityReview>;
97
+ requirementsBrainstormKind: ReviewKind<BrainstormSession>;
98
+ architectureBrainstormKind: ReviewKind<BrainstormSession>;
99
+ /**
100
+ * The interactive-interviewer gates wired for this deployment (initiative-planning, document
101
+ * interview, …). Each rides the shared {@link InterviewGateController} spine and is routed by
102
+ * the `interview-gate` TRAIT, keyed on its own `agentKind` — so adding a new interviewer wires
103
+ * its controller here, with no new dispatch branch. Absent/unwired kinds pass through.
104
+ */
105
+ interviewControllers?: InterviewGateController<unknown>[];
106
+ /** Keeps the run's verification report current on its PR; a no-op with no publisher wired. */
107
+ prVerificationReport: PrVerificationReportController;
108
+ runInitiatorScope: RunInitiatorScope;
109
+ environmentProvisioning?: EnvironmentProvisioningService;
110
+ ticketTrackerProvider?: TicketTrackerProvider;
111
+ issueWriteback?: IssueWritebackProvider;
112
+ /** The recurring `bug-intake` step's read-and-claim helper; absent → the step is a no-op. */
113
+ bugIntakeService?: BugIntakeService;
114
+ notificationService?: NotificationService;
115
+ blueprintReconciler?: BlueprintReconciler;
116
+ initiativeService?: InitiativeService;
117
+ resolveRunRepoContext?: ResolveRunRepoContext;
118
+ resolveProviderCapabilities?: (workspaceId: string, initiatedBy?: string | null, modelPresetId?: string) => Promise<ProviderCapabilities>;
119
+ /** Resolve a task's merge preset (stays on the engine, shared with the merge subgraph). */
120
+ resolveRiskPolicy: (workspaceId: string, block: Block) => Promise<ResolvedRiskPolicy>;
121
+ /** Whether a resolved model id incurs metered monetary cost (the start gate's predicate). */
122
+ modelIdIsMetered: (id: string | undefined, caps: ProviderCapabilities) => boolean;
123
+ }
124
+ /**
125
+ * The `recordGateOutcome` callback both gate-settling controllers take, or nothing when no
126
+ * projection is wired.
127
+ *
128
+ * Computed ONCE and spread into both: a gate reaches a terminal verdict down two paths, the
129
+ * precheck/exhaustion machine in {@link GateStepController} and the investigate-don't-fix
130
+ * completion in {@link PollRunningController}, and wiring only the first is why the
131
+ * `post-release-health` gate was absent from the statistics entirely. Two call sites, one
132
+ * recorder, so a third settling path has one obvious thing to reach for.
133
+ *
134
+ * A free function rather than an inline branch in the constructor: each controller takes ONE
135
+ * bound callback and must stay independent of the sink's collaborators, and the constructor is
136
+ * already at its statement budget (budgets are split triggers). It lives beside the deps it
137
+ * `Pick`s from, so the dispatcher imports it rather than re-declaring that slice.
138
+ */
139
+ export declare function gateOutcomeRecording(deps: Pick<RunDispatcherDeps, 'gateOutcomeRepository' | 'clock'>, logger: Logger): {
140
+ recordGateOutcome?: (settled: SettledGate) => Promise<void>;
141
+ };
142
+ //# sourceMappingURL=RunDispatcherDependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunDispatcherDependencies.d.ts","sourceRoot":"","sources":["../../../src/modules/execution/RunDispatcherDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,KAAK,EACL,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,MAAM,EACN,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,UAAU,EACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAA;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAA;AACjG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACzF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,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BAAiB,EAAE,uBAAuB,GAAG,OAAO,CAAC,EAChE,MAAM,EAAE,MAAM,GACb;IAAE,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAQjE"}
@@ -0,0 +1,27 @@
1
+ import { GateOutcomeRecorder } from '../observability/GateOutcomeRecorder.js';
2
+ /**
3
+ * The `recordGateOutcome` callback both gate-settling controllers take, or nothing when no
4
+ * projection is wired.
5
+ *
6
+ * Computed ONCE and spread into both: a gate reaches a terminal verdict down two paths, the
7
+ * precheck/exhaustion machine in {@link GateStepController} and the investigate-don't-fix
8
+ * completion in {@link PollRunningController}, and wiring only the first is why the
9
+ * `post-release-health` gate was absent from the statistics entirely. Two call sites, one
10
+ * recorder, so a third settling path has one obvious thing to reach for.
11
+ *
12
+ * A free function rather than an inline branch in the constructor: each controller takes ONE
13
+ * bound callback and must stay independent of the sink's collaborators, and the constructor is
14
+ * already at its statement budget (budgets are split triggers). It lives beside the deps it
15
+ * `Pick`s from, so the dispatcher imports it rather than re-declaring that slice.
16
+ */
17
+ export function gateOutcomeRecording(deps, logger) {
18
+ if (!deps.gateOutcomeRepository)
19
+ return {};
20
+ const recorder = new GateOutcomeRecorder({
21
+ gateOutcomeRepository: deps.gateOutcomeRepository,
22
+ now: () => deps.clock.now(),
23
+ logger,
24
+ });
25
+ return { recordGateOutcome: (settled) => recorder.record(settled) };
26
+ }
27
+ //# sourceMappingURL=RunDispatcherDependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunDispatcherDependencies.js","sourceRoot":"","sources":["../../../src/modules/execution/RunDispatcherDependencies.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AAwI7E;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAgE,EAChE,MAAc;IAEd,IAAI,CAAC,IAAI,CAAC,qBAAqB;QAAE,OAAO,EAAE,CAAA;IAC1C,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC;QACvC,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;QACjD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;QAC3B,MAAM;KACP,CAAC,CAAA;IACF,OAAO,EAAE,iBAAiB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAA;AACrE,CAAC"}
@@ -0,0 +1,141 @@
1
+ import type { AgentFailureKind, Block, BlockRepository, Clock, ExecutionEventPublisher, ExecutionInstance, ExecutionRepository, IdGenerator, PipelineRepository, SubscriptionActivationRepository, WorkRunner } from '@cat-factory/kernel';
2
+ import type { PreloadedBlocks } from '@cat-factory/kernel';
3
+ import type { AgentContextBuilder } from './AgentContextBuilder.js';
4
+ import type { RunAdmission } from './RunAdmission.js';
5
+ import type { RunStateMachine } from './RunStateMachine.js';
6
+ import type { RunStartOptions } from './runStartOptions.js';
7
+ /**
8
+ * What the run-lifecycle surface needs. The two guards (`requireWorkspace` / `requireBlock`) and
9
+ * `failRun` arrive as bound call-backs, so this controller depends on no concrete guard and on no
10
+ * part of the state machine it does not itself drive.
11
+ */
12
+ export interface RunLifecycleDeps {
13
+ admission: RunAdmission;
14
+ blockRepository: BlockRepository;
15
+ clock: Clock;
16
+ contextBuilder: AgentContextBuilder;
17
+ events: ExecutionEventPublisher;
18
+ executionRepository: ExecutionRepository;
19
+ idGenerator: IdGenerator;
20
+ pipelineRepository: PipelineRepository;
21
+ runStateMachine: RunStateMachine;
22
+ workRunner: WorkRunner;
23
+ subscriptionActivations?: SubscriptionActivationRepository;
24
+ requireWorkspace: (workspaceId: string) => Promise<unknown>;
25
+ requireBlock: (workspaceId: string, id: string) => Promise<Block>;
26
+ failRun: (workspaceId: string, executionId: string, message: string, kind?: AgentFailureKind, detail?: string | null, reason?: string | null) => Promise<void>;
27
+ }
28
+ /**
29
+ * A run's LIFECYCLE surface: every entry point that launches one (`start`), re-launches one
30
+ * (`retry` / `restartFromStep`), lifts a spend pause (`resumePaused`), or ends one (`cancel` /
31
+ * `stopRun` / `teardownForBlockTree`).
32
+ *
33
+ * They belong together because all three launch paths write the SAME two things in the SAME order:
34
+ * the atomic live-run claim, then the durable/SPA/outbound hand-off (both owned by `runStart.ts`,
35
+ * reached through the one `runStartDeps` getter below). They differ only in the block patch written
36
+ * between the two and in what each tears down first. Keeping that order in one place is what stops
37
+ * a new entry point from claiming without handing off (a run nothing drives) or announcing before
38
+ * the claim commits.
39
+ *
40
+ * `ExecutionService` keeps thin delegates, so no HTTP call site changed. The per-step machine
41
+ * (`advanceInstance` / `stepInstance`) and the human decision surface (`StepDecisionController`)
42
+ * deliberately stay where they are: those act on a run that is already live.
43
+ */
44
+ export declare class RunLifecycleController {
45
+ private readonly deps;
46
+ constructor(deps: RunLifecycleDeps);
47
+ /** Start a pipeline against a block, replacing any prior run on it. */
48
+ start(workspaceId: string, blockId: string, pipelineId: string, options?: RunStartOptions): Promise<ExecutionInstance>;
49
+ /**
50
+ * Retry a failed run: re-drive the same pipeline on the same block, **resuming
51
+ * from the step that actually failed** rather than restarting from step 0. The
52
+ * steps that already completed are preserved (so a `coder` failure in `pl_full`
53
+ * doesn't re-run the human-gated `requirements`/`architect` steps before it);
54
+ * the failed step and everything after it are reset to a clean, re-runnable
55
+ * state. Only a `failed` run can be retried.
56
+ *
57
+ * A fresh instance id is minted because the durable runner addresses one
58
+ * Workflows instance per execution id and the failed one is terminal — the new
59
+ * instance simply starts with `currentStep` pointed at the failed step, so the
60
+ * driver advances forward from there and never re-issues the completed steps'
61
+ * work. Mirrors {@link BootstrapService.retry}; both are reached via the unified
62
+ * `POST /agent-runs/:id/retry` endpoint.
63
+ */
64
+ retry(workspaceId: string, executionId: string,
65
+ /** The retrying user (their personal subscription is used for individual-usage
66
+ * models). Falls back to the original initiator when omitted. */
67
+ initiatedBy?: string | null,
68
+ /** Mint the per-run personal-credential activation (see {@link start}). */
69
+ activate?: (executionId: string) => Promise<void>): Promise<ExecutionInstance>;
70
+ /**
71
+ * Restart a run from a human-chosen step: re-run from `fromStepIndex` onward,
72
+ * regardless of how far the run had progressed (a `done`, `failed`, `blocked`,
73
+ * `paused` or still-`running` run are all valid sources). Unlike {@link retry}
74
+ * (which resumes at the first FAILURE) this rewinds to an arbitrary step the user
75
+ * picked — so it can re-run steps that already completed.
76
+ *
77
+ * What is preserved vs reset:
78
+ * - Steps BEFORE `fromStepIndex` keep their `output`/approval/timing untouched, so
79
+ * the engine still hands the restarted step its predecessors' work as
80
+ * `priorOutputs` (and their resolved `decisions`) — a useful handoff.
81
+ * - The chosen step and every later one are reset to a clean, re-runnable state,
82
+ * dropping each step's iteration counters (companion attempts, gate/test attempts,
83
+ * eviction recoveries) so the restart starts those loops from zero.
84
+ * - A block's incorporated requirements are NOT touched: they live on the
85
+ * requirement-review record, so a restarted spec-writer/coder still receives the
86
+ * incorporated document (or the base description when none was generated). When the
87
+ * chosen step is the `requirements-review` gate ITSELF, re-running it mints a fresh
88
+ * iteration-1 review (the reviewer's `review()` replaces the prior one), which is
89
+ * exactly the "reset the iterations counter from this step" semantics.
90
+ *
91
+ * Like {@link retry} a fresh instance id is minted (the durable runner addresses one
92
+ * driver per execution id). Any still-live driver/container for the run being
93
+ * replaced is torn down first, so restarting a RUNNING run never orphans a container
94
+ * or a parked Workflows instance.
95
+ */
96
+ restartFromStep(workspaceId: string, executionId: string, fromStepIndex: number,
97
+ /** The restarting user (their personal subscription is used for individual-usage
98
+ * models). Falls back to the original initiator when omitted. */
99
+ initiatedBy?: string | null,
100
+ /** Mint the per-run personal-credential activation (see {@link start}). */
101
+ activate?: (executionId: string) => Promise<void>): Promise<ExecutionInstance>;
102
+ /**
103
+ * The bound callbacks the two run-start funnels (`runStart.ts`) need, so they depend on no
104
+ * concrete repository or service. Those funnels own the ORDER between a run's atomic claim and
105
+ * its hand-off and are documented there; every start path calls both, writing the block state
106
+ * that path owns in between.
107
+ */
108
+ private get runStartDeps();
109
+ /**
110
+ * Resume every run paused by the spend safeguard in this workspace. Flips them
111
+ * back to `running` and re-drives the durable runner. If the budget is still
112
+ * exhausted the spend gate will simply pause them again on their next step.
113
+ */
114
+ resumePaused(workspaceId: string): Promise<ExecutionInstance[]>;
115
+ /** Cancel the run on a block, returning it to `planned`. */
116
+ cancel(workspaceId: string, blockId: string): Promise<Block>;
117
+ /**
118
+ * Explicitly stop a *running* run by id (the unified `POST /agent-runs/:id/stop`
119
+ * surface): kill its per-run container, tear down the durable driver, then record
120
+ * a terminal `cancelled` failure so the board shows the run stopped (with retry)
121
+ * rather than spinning forever. Idempotent — a run already terminal is returned
122
+ * as-is. `opts.reason`/`opts.kind` let the orphan sweep reuse this with its own
123
+ * wording instead of the user-facing default.
124
+ */
125
+ stopRun(workspaceId: string, executionId: string, opts?: {
126
+ reason?: string;
127
+ kind?: AgentFailureKind;
128
+ }): Promise<ExecutionInstance>;
129
+ /**
130
+ * Tear down every run under a block subtree — kill each container, terminate each
131
+ * durable driver, and delete the run record — so deleting a service/module never
132
+ * orphans a container or a Workflows instance. Best-effort and silent: the board
133
+ * delete that follows emits the coarse refresh, so no per-run event is needed.
134
+ *
135
+ * Returns the workspace block list it loaded so the immediately-following `removeBlock`
136
+ * can reuse it instead of re-listing the whole board (this teardown deletes only run
137
+ * records, never blocks, so the list is still current) — see {@link PreloadedBlocks}.
138
+ */
139
+ teardownForBlockTree(workspaceId: string, rootId: string): Promise<PreloadedBlocks>;
140
+ }
141
+ //# sourceMappingURL=RunLifecycleController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunLifecycleController.d.ts","sourceRoot":"","sources":["../../../src/modules/execution/RunLifecycleController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,eAAe,EACf,KAAK,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,kBAA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