stageflow 0.8.0 → 0.12.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 (159) hide show
  1. package/README.md +24 -14
  2. package/dist/agent/activity.d.ts +9 -0
  3. package/dist/agent/agentBackend.d.ts +32 -0
  4. package/dist/agent/agentBackend.js +38 -0
  5. package/dist/agent/claudeActivity.d.ts +15 -0
  6. package/dist/agent/claudeActivity.js +58 -0
  7. package/dist/agent/claudeAdapter.d.ts +5 -0
  8. package/dist/agent/claudeAdapter.js +301 -0
  9. package/dist/agent/claudeSession.d.ts +18 -0
  10. package/dist/agent/claudeSession.js +54 -0
  11. package/dist/agent/claudeTools.d.ts +89 -0
  12. package/dist/agent/claudeTools.js +135 -0
  13. package/dist/agent/fakeAgent.js +24 -4
  14. package/dist/agent/piAdapter.d.ts +6 -3
  15. package/dist/agent/piAdapter.js +129 -21
  16. package/dist/agent/port.d.ts +50 -1
  17. package/dist/agent/resolveAgentPort.d.ts +26 -0
  18. package/dist/agent/resolveAgentPort.js +39 -0
  19. package/dist/cli/runCommand.js +2 -2
  20. package/dist/cli/runsCommand.d.ts +22 -0
  21. package/dist/cli/runsCommand.js +773 -0
  22. package/dist/cli/validateOutput.d.ts +2 -2
  23. package/dist/cli/validateOutput.js +2 -2
  24. package/dist/cli.d.ts +1 -1
  25. package/dist/cli.js +43 -5
  26. package/dist/config/browseCatalog.js +1 -1
  27. package/dist/config/createPipeline.d.ts +2 -1
  28. package/dist/config/createPipeline.js +34 -9
  29. package/dist/config/createStage.js +14 -9
  30. package/dist/config/loadPipeline.js +10 -1
  31. package/dist/config/loadStage.js +138 -2
  32. package/dist/config/loadStageflowManifest.js +14 -1
  33. package/dist/config/mergePipelineIncludes.d.ts +1 -0
  34. package/dist/config/mergePipelineIncludes.js +14 -1
  35. package/dist/config/normalizePipelineStageEntry.d.ts +7 -2
  36. package/dist/config/normalizePipelineStageEntry.js +49 -6
  37. package/dist/config/parseCompletionContract.d.ts +8 -0
  38. package/dist/config/parseCompletionContract.js +218 -0
  39. package/dist/config/parsePreEmitChecks.d.ts +3 -0
  40. package/dist/config/parsePreEmitChecks.js +65 -0
  41. package/dist/config/pipelineNeeds.d.ts +19 -0
  42. package/dist/config/pipelineNeeds.js +151 -0
  43. package/dist/config/pipelineStageKeys.js +16 -1
  44. package/dist/config/resolveForkEmitContext.d.ts +6 -2
  45. package/dist/config/resolveForkEmitContext.js +9 -2
  46. package/dist/config/resolvePipelineDag.d.ts +2 -1
  47. package/dist/config/resolvePipelineDag.js +182 -39
  48. package/dist/config/validateCatalog.d.ts +1 -1
  49. package/dist/config/validateCompletionContract.d.ts +4 -0
  50. package/dist/config/validateCompletionContract.js +52 -0
  51. package/dist/envelope/check.d.ts +1 -1
  52. package/dist/envelope/check.js +86 -13
  53. package/dist/envelope/cloneForks.d.ts +1 -1
  54. package/dist/envelope/cloneForks.js +24 -9
  55. package/dist/envelope/feedbackLoop.d.ts +4 -0
  56. package/dist/envelope/feedbackLoop.js +31 -0
  57. package/dist/envelope/payloadSchema.d.ts +7 -1
  58. package/dist/envelope/payloadSchema.js +170 -13
  59. package/dist/envelope/preEmitChecks.d.ts +29 -0
  60. package/dist/envelope/preEmitChecks.js +57 -0
  61. package/dist/hitl/qaTrail.d.ts +25 -0
  62. package/dist/hitl/qaTrail.js +51 -0
  63. package/dist/index.d.ts +1 -1
  64. package/dist/index.js +1 -1
  65. package/dist/mcp/catalogTools.js +4 -2
  66. package/dist/mcp/controlTools.js +72 -0
  67. package/dist/mcp/waitingGates.d.ts +2 -1
  68. package/dist/mcp/waitingGates.js +17 -1
  69. package/dist/package-meta.d.ts +1 -0
  70. package/dist/package-meta.js +1 -0
  71. package/dist/projection/projectRun.d.ts +4 -1
  72. package/dist/projection/projectRun.js +7 -0
  73. package/dist/prompt/feedbackLoopContext.d.ts +2 -0
  74. package/dist/prompt/feedbackLoopContext.js +17 -0
  75. package/dist/prompt/priorEnvelope.d.ts +2 -2
  76. package/dist/prompt/priorEnvelope.js +4 -1
  77. package/dist/runstore/pipelineDagSnapshot.d.ts +1 -0
  78. package/dist/runstore/pipelineDagSnapshot.js +51 -11
  79. package/dist/runstore/port.d.ts +185 -3
  80. package/dist/runstore/port.js +42 -3
  81. package/dist/runstore/runProjection.d.ts +7 -3
  82. package/dist/runstore/runProjection.js +30 -15
  83. package/dist/runstore/sqlite/SqliteRunStore.d.ts +25 -1
  84. package/dist/runstore/sqlite/SqliteRunStore.js +626 -8
  85. package/dist/runstore/sqlite/schema.d.ts +1 -1
  86. package/dist/runstore/sqlite/schema.js +99 -0
  87. package/dist/runstore/stageInstanceId.d.ts +1 -1
  88. package/dist/runstore/stageInstanceId.js +3 -2
  89. package/dist/runstore/trackProjection.js +59 -27
  90. package/dist/runstore/verificationHistory.d.ts +19 -0
  91. package/dist/runstore/verificationHistory.js +30 -0
  92. package/dist/runtime/cloneSchedule.d.ts +40 -4
  93. package/dist/runtime/cloneSchedule.js +212 -28
  94. package/dist/runtime/completionCheckRunner.d.ts +137 -0
  95. package/dist/runtime/completionCheckRunner.js +365 -0
  96. package/dist/runtime/completionCheckoutBaseline.d.ts +3 -0
  97. package/dist/runtime/completionCheckoutBaseline.js +44 -0
  98. package/dist/runtime/envelopeRouting.d.ts +10 -3
  99. package/dist/runtime/envelopeRouting.js +146 -5
  100. package/dist/runtime/feedbackLoopCoordinator.d.ts +74 -0
  101. package/dist/runtime/feedbackLoopCoordinator.js +446 -0
  102. package/dist/runtime/feedbackLoopDecision.d.ts +44 -0
  103. package/dist/runtime/feedbackLoopDecision.js +207 -0
  104. package/dist/runtime/feedbackLoopRoute.d.ts +5 -0
  105. package/dist/runtime/feedbackLoopRoute.js +13 -0
  106. package/dist/runtime/feedbackLoopSchedule.d.ts +38 -0
  107. package/dist/runtime/feedbackLoopSchedule.js +72 -0
  108. package/dist/runtime/forkGeneration.d.ts +72 -0
  109. package/dist/runtime/forkGeneration.js +295 -0
  110. package/dist/runtime/gitCheckoutCapability.d.ts +7 -0
  111. package/dist/runtime/gitCheckoutCapability.js +97 -0
  112. package/dist/runtime/manualRecoveryState.d.ts +40 -0
  113. package/dist/runtime/manualRecoveryState.js +73 -0
  114. package/dist/runtime/pipelineScheduler.d.ts +13 -1
  115. package/dist/runtime/pipelineScheduler.js +328 -45
  116. package/dist/runtime/replayLifecycle.d.ts +107 -0
  117. package/dist/runtime/replayLifecycle.js +168 -0
  118. package/dist/runtime/runManager.d.ts +61 -1
  119. package/dist/runtime/runManager.js +501 -7
  120. package/dist/runtime/runRetryCoordinator.d.ts +8 -1
  121. package/dist/runtime/runRetryCoordinator.js +47 -10
  122. package/dist/runtime/stageAttemptBootstrap.d.ts +3 -1
  123. package/dist/runtime/stageAttemptBootstrap.js +79 -1
  124. package/dist/runtime/stageProcessLauncher.d.ts +1 -1
  125. package/dist/runtime/stageRecovery.js +1 -1
  126. package/dist/runtime/stageRunner.d.ts +4 -1
  127. package/dist/runtime/stageRunner.js +29 -3
  128. package/dist/runtime/stageWorker.js +69 -2
  129. package/dist/runtime/stageWorkerProtocol.d.ts +1 -1
  130. package/dist/runtime/verifiedStageExecution.d.ts +29 -0
  131. package/dist/runtime/verifiedStageExecution.js +119 -0
  132. package/dist/server/bootstrap.js +1 -0
  133. package/dist/server/http.js +114 -0
  134. package/dist/server/operatorResults.js +2 -0
  135. package/dist/tools/askOperator.d.ts +161 -5
  136. package/dist/tools/askOperator.js +58 -25
  137. package/dist/tools/emitStageEnvelope.d.ts +12 -12
  138. package/dist/tools/emitStageEnvelope.js +112 -24
  139. package/dist/types/completion.d.ts +43 -0
  140. package/dist/types/completion.js +1 -0
  141. package/dist/types/envelope.d.ts +18 -0
  142. package/dist/types/forkChoice.d.ts +9 -4
  143. package/dist/types/forkChoice.js +1 -1
  144. package/dist/types/pipeline.d.ts +39 -2
  145. package/dist/types/preEmitCheck.d.ts +18 -0
  146. package/dist/types/preEmitCheck.js +1 -0
  147. package/dist/types/stage.d.ts +13 -0
  148. package/dist/types/stageflowManifest.d.ts +2 -0
  149. package/dist/ui/assets/index-CXGz4nL7.js +118 -0
  150. package/dist/ui/assets/{index-C3N7MXAC.css → index-uVHiae8s.css} +1 -1
  151. package/dist/ui/index.html +2 -2
  152. package/package.json +2 -1
  153. package/skills/stageflow/references/control-surface.md +4 -2
  154. package/skills/stageflow-author/references/catalog-mapping.md +26 -2
  155. package/skills/stageflow-author/references/catalog-write-conventions.md +1 -1
  156. package/skills/stageflow-run/SKILL.md +56 -25
  157. package/skills/stageflow-run/references/mcp-call.md +2 -2
  158. package/skills/stageflow-run/references/native-question-ui.md +78 -0
  159. package/dist/ui/assets/index-CSoGDA3A.js +0 -118
@@ -1,11 +1,47 @@
1
- import type { StageEnvelope } from "../types/envelope.js";
1
+ import type { StageEnvelope, TerminalEnvelope } from "../types/envelope.js";
2
+ import type { CompletionContract } from "../types/completion.js";
2
3
  import type { CloneEmitContext, ForkEmitContext } from "../types/forkChoice.js";
3
4
  import type { StageConfig } from "../types/stage.js";
5
+ import type { FeedbackLoopConfig } from "../types/pipeline.js";
4
6
  import type { TaskFile } from "../types/task.js";
5
7
  import type { StageActivityEvent } from "./activity.js";
6
8
  import type { StageRoots } from "../runtime/stageRoots.js";
9
+ import type { QaExchange } from "../hitl/qaTrail.js";
7
10
  /** Opaque to runtime; adapters interpret. */
8
11
  export type StageResumeToken = string;
12
+ export type StageSessionMode = "fresh" | "waiting_resume" | "feedback_resume" | "new_session";
13
+ export type StageRepairContext = {
14
+ prior_attempt: number;
15
+ /** Operator-authored instructions for an explicitly approved manual retry. */
16
+ operator_guidance?: string;
17
+ failed_checks?: Array<{
18
+ id: string;
19
+ type: string;
20
+ evidence_preview?: string;
21
+ }>;
22
+ };
23
+ export type FeedbackLoopContext = {
24
+ loop_id: string;
25
+ replay_id: string;
26
+ source_stage_id: string;
27
+ target_stage_id: string;
28
+ /** Original send-back envelope from the source (feedback + artifacts). */
29
+ feedback_envelope: StageEnvelope;
30
+ /** One-based replay number for this send-back. */
31
+ replay_number: number;
32
+ max_replays: number;
33
+ remaining_replays: number;
34
+ is_final_replay: boolean;
35
+ replay_session: "resume" | "new_session";
36
+ /** Persistent stages on the active target→source route, forward order. */
37
+ route_stage_ids: string[];
38
+ /** Prior pass/session identity for THIS stage when resuming, if any. */
39
+ prior_stage_attempt?: number;
40
+ prior_pass_status?: string;
41
+ /** Active fork generation for this stage's parent fan-out, if any. */
42
+ active_fork_generation_id?: string;
43
+ active_fork_clone_stage_ids?: string[];
44
+ };
9
45
  export type StageRunInput = {
10
46
  roots: StageRoots;
11
47
  stage: StageConfig;
@@ -14,13 +50,26 @@ export type StageRunInput = {
14
50
  task: TaskFile;
15
51
  priorEnvelope: StageEnvelope | null;
16
52
  priorEnvelopes?: StageEnvelope[];
53
+ priorEnvelopesByStage?: Record<string, TerminalEnvelope | TerminalEnvelope[]>;
17
54
  timeoutMs?: number;
18
55
  resumeToken?: StageResumeToken;
56
+ /** Launch/session mode; omitted is treated as `"fresh"`. */
57
+ sessionMode?: StageSessionMode;
19
58
  /** Optional observe hook; HITL wait/answer uses openStage beside this. */
20
59
  onActivity?: (event: StageActivityEvent) => void;
21
60
  skillFilePath?: string;
22
61
  forkEmitContext?: ForkEmitContext;
23
62
  cloneEmitContext?: CloneEmitContext;
63
+ /** Declared source policy; successful emits must continue or send work back. */
64
+ feedbackLoopEmitContext?: FeedbackLoopConfig;
65
+ /** Replay context for stages being replayed (and typically the source on send-back). */
66
+ feedbackLoopContext?: FeedbackLoopContext;
67
+ /** Frozen pipeline-owned checks that must pass before Stageflow advances. */
68
+ completionContract?: CompletionContract;
69
+ /** Compact evidence from the failed verification that triggered this repair. */
70
+ repairContext?: StageRepairContext;
71
+ /** Live attempt-scoped QA trail; read at emit execute time, not bootstrap time. */
72
+ readQaTrail?: () => QaExchange[] | Promise<QaExchange[]>;
24
73
  };
25
74
  export declare function runtimeStageId(input: Pick<StageRunInput, "stage" | "stageId">): string;
26
75
  export type StageRunResult = {
@@ -0,0 +1,26 @@
1
+ import { type AgentBackendId } from "./agentBackend.js";
2
+ import type { AgentPort } from "./port.js";
3
+ import type { LoadedManifest } from "../types/stageflowManifest.js";
4
+ export type AgentSelection = {
5
+ /** stageflow.yaml top-level `agent`. */
6
+ global?: AgentBackendId;
7
+ /** Pipeline yaml top-level `agent`; overrides global. */
8
+ pipeline?: AgentBackendId;
9
+ /** Stage yaml `agent`; would override pipeline/global once enabled. */
10
+ stage?: AgentBackendId;
11
+ };
12
+ /** stage > pipeline > global > "pi", with stage gated off for now. */
13
+ export declare function resolveAgentBackend(selection?: AgentSelection): AgentBackendId;
14
+ export declare function resolveAgentPort(selection?: AgentSelection): AgentPort;
15
+ /** The global tier's backend id from an already-loaded manifest, or undefined for missing/invalid/unset. */
16
+ export declare function globalAgentBackendFromManifest(manifest: LoadedManifest | null): AgentBackendId | undefined;
17
+ /**
18
+ * Resolves an AgentPort using only the global (stageflow.yaml) tier — for
19
+ * the three call sites that construct an agent before any pipeline is
20
+ * known (`cli.ts`'s ui/mcp servers, `runCommand.ts`, `runsCommand.ts`).
21
+ * Named explicitly so it's clear these sites are scoped to the global tier
22
+ * on purpose, not by omission: production stage execution always goes
23
+ * through `stageWorker.ts`, which resolves the full stage > pipeline >
24
+ * global chain once it has loaded the specific pipeline and stage.
25
+ */
26
+ export declare function resolveGlobalOnlyAgentPort(projectRoot: string): Promise<AgentPort>;
@@ -0,0 +1,39 @@
1
+ import { asAgentBackendId, STAGE_LEVEL_AGENT_OVERRIDE_ENABLED, } from "./agentBackend.js";
2
+ import { PiAgentAdapter } from "./piAdapter.js";
3
+ import { ClaudeAgentAdapter } from "./claudeAdapter.js";
4
+ import { loadStageflowManifestOutcome } from "../config/loadStageflowManifest.js";
5
+ /** stage > pipeline > global > "pi", with stage gated off for now. */
6
+ export function resolveAgentBackend(selection = {}) {
7
+ if (STAGE_LEVEL_AGENT_OVERRIDE_ENABLED && selection.stage !== undefined) {
8
+ return selection.stage;
9
+ }
10
+ return selection.pipeline ?? selection.global ?? "pi";
11
+ }
12
+ export function resolveAgentPort(selection = {}) {
13
+ const backend = resolveAgentBackend(selection);
14
+ switch (backend) {
15
+ case "pi":
16
+ return new PiAgentAdapter();
17
+ case "claude":
18
+ return new ClaudeAgentAdapter();
19
+ }
20
+ }
21
+ /** The global tier's backend id from an already-loaded manifest, or undefined for missing/invalid/unset. */
22
+ export function globalAgentBackendFromManifest(manifest) {
23
+ return manifest ? asAgentBackendId(manifest.manifest.agent) : undefined;
24
+ }
25
+ /**
26
+ * Resolves an AgentPort using only the global (stageflow.yaml) tier — for
27
+ * the three call sites that construct an agent before any pipeline is
28
+ * known (`cli.ts`'s ui/mcp servers, `runCommand.ts`, `runsCommand.ts`).
29
+ * Named explicitly so it's clear these sites are scoped to the global tier
30
+ * on purpose, not by omission: production stage execution always goes
31
+ * through `stageWorker.ts`, which resolves the full stage > pipeline >
32
+ * global chain once it has loaded the specific pipeline and stage.
33
+ */
34
+ export async function resolveGlobalOnlyAgentPort(projectRoot) {
35
+ const outcome = await loadStageflowManifestOutcome(projectRoot);
36
+ return resolveAgentPort({
37
+ global: outcome.ok ? globalAgentBackendFromManifest(outcome.value) : undefined,
38
+ });
39
+ }
@@ -1,4 +1,4 @@
1
- import { PiAgentAdapter } from "../agent/piAdapter.js";
1
+ import { resolveGlobalOnlyAgentPort } from "../agent/resolveAgentPort.js";
2
2
  import { createRunStore } from "../runstore/createStore.js";
3
3
  import { PipelineValidationError } from "../runtime/pipelineRunner.js";
4
4
  import { RunManager } from "../runtime/runManager.js";
@@ -137,7 +137,7 @@ function defaultStartRun(cwd, projectRoot, isGitProject, operatorCatalog) {
137
137
  return async (input) => {
138
138
  const store = createRunStore({ rootDir: projectRoot });
139
139
  const manager = new RunManager({
140
- agent: new PiAgentAdapter(),
140
+ agent: await resolveGlobalOnlyAgentPort(projectRoot),
141
141
  store,
142
142
  cwd,
143
143
  projectRoot,
@@ -0,0 +1,22 @@
1
+ import type { RunStore } from "../runstore/port.js";
2
+ import { RunManager } from "../runtime/runManager.js";
3
+ export declare const RUNS_USAGE = "Usage:\n sf runs list [--status created|running|succeeded|failed] [--since <iso>] [--pipeline <id-or-path>] [--json]\n sf runs show --run <runId> [--from <sf-run.json>] [--json]\n sf runs verify --run <runId> --stage <stageId> [--json]\n sf runs recover --run <runId> --stage <stageId> [--guidance <text>] [--stop] [--json]\n sf runs waiting [--run <runId>] [--json]\n sf runs wait --run <runId> [--from <sf-run.json>] [--until any|waiting|terminal] [--timeout-ms <n>] [--json]\n sf runs answer --run <runId> --stage <stageId> [--answer '<json>'] [--json]\n sf runs feedback-decide --run <runId> --stage <sourceStageId> [--loop <loopId>] --decision extend|continue|abandon [--reason <text>] [--json]\n sf runs retry --run <runId> --stage <stageId> [--json]\n sf runs abandon --run <runId> --stage <stageId> [--json]\n sf runs rerun --run <runId> [--json]";
4
+ export type RunsCommandIo = {
5
+ log: (line: string) => void;
6
+ error: (line: string) => void;
7
+ };
8
+ export type HostProbeResult = "up" | "down";
9
+ export declare function defaultProbeHost(): Promise<HostProbeResult>;
10
+ export declare function runRunsCommand(args: string[], options?: {
11
+ cwd?: string;
12
+ projectRoot?: string;
13
+ isGitProject?: boolean;
14
+ io?: Partial<RunsCommandIo>;
15
+ store?: RunStore;
16
+ probeHost?: () => Promise<HostProbeResult>;
17
+ stdinIsTTY?: boolean;
18
+ readStdin?: () => string;
19
+ waitSignal?: AbortSignal;
20
+ env?: NodeJS.ProcessEnv;
21
+ createManager?: (store: RunStore) => RunManager;
22
+ }): Promise<number>;