stageflow 0.19.0 → 0.25.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 (120) hide show
  1. package/README.md +16 -3
  2. package/dist/a2a/configDiscovery.d.ts +9 -0
  3. package/dist/a2a/configDiscovery.js +18 -0
  4. package/dist/a2a/contracts.d.ts +93 -0
  5. package/dist/a2a/contracts.js +163 -0
  6. package/dist/a2a/limits.d.ts +14 -0
  7. package/dist/a2a/limits.js +29 -0
  8. package/dist/a2a/registry.d.ts +44 -0
  9. package/dist/a2a/registry.js +159 -0
  10. package/dist/a2a/server.d.ts +29 -0
  11. package/dist/a2a/server.js +341 -0
  12. package/dist/a2a/service.d.ts +97 -0
  13. package/dist/a2a/service.js +496 -0
  14. package/dist/a2a/store.d.ts +106 -0
  15. package/dist/a2a/store.js +245 -0
  16. package/dist/agent/activity.d.ts +5 -0
  17. package/dist/agent/activityObserver.d.ts +3 -0
  18. package/dist/agent/activityObserver.js +6 -1
  19. package/dist/agent/piAdapter.js +7 -3
  20. package/dist/agent/port.d.ts +2 -0
  21. package/dist/agent/providerInspect.d.ts +19 -0
  22. package/dist/agent/providerInspect.js +35 -0
  23. package/dist/agent/streamLogRedact.d.ts +2 -0
  24. package/dist/agent/streamLogRedact.js +13 -0
  25. package/dist/cli/a2aCommand.d.ts +8 -0
  26. package/dist/cli/a2aCommand.js +131 -0
  27. package/dist/cli/artifactCommand.js +2 -2
  28. package/dist/cli/envelopeCommand.js +2 -2
  29. package/dist/cli/exportRunCommand.js +2 -2
  30. package/dist/cli/hostClient.d.ts +43 -0
  31. package/dist/cli/hostClient.js +182 -0
  32. package/dist/cli/providersCommand.js +5 -3
  33. package/dist/cli/runCommand.d.ts +6 -5
  34. package/dist/cli/runCommand.js +23 -31
  35. package/dist/cli/runOutput.d.ts +1 -1
  36. package/dist/cli/runStageCommand.d.ts +33 -0
  37. package/dist/cli/runStageCommand.js +407 -0
  38. package/dist/cli/runsCommand.d.ts +3 -7
  39. package/dist/cli/runsCommand.js +33 -94
  40. package/dist/cli.js +20 -5
  41. package/dist/config/describePipeline.d.ts +26 -0
  42. package/dist/config/describePipeline.js +37 -0
  43. package/dist/config/loadPipeline.d.ts +13 -1
  44. package/dist/config/loadPipeline.js +34 -4
  45. package/dist/config/mergePipelineIncludes.d.ts +11 -0
  46. package/dist/config/mergePipelineIncludes.js +75 -0
  47. package/dist/config/validateCatalog.d.ts +2 -2
  48. package/dist/config/validateCatalog.js +24 -17
  49. package/dist/mcp/catalogTools.js +285 -52
  50. package/dist/mcp/controlTools.js +77 -19
  51. package/dist/mcp/deps.d.ts +3 -0
  52. package/dist/mcp/projectMcpTools.d.ts +3 -0
  53. package/dist/mcp/projectMcpTools.js +25 -0
  54. package/dist/mcp/providerTools.d.ts +3 -0
  55. package/dist/mcp/providerTools.js +17 -0
  56. package/dist/mcp/readArtifact.d.ts +9 -0
  57. package/dist/mcp/readArtifact.js +11 -0
  58. package/dist/mcp/server.js +9 -1
  59. package/dist/mcp/tailStreamLog.d.ts +8 -0
  60. package/dist/mcp/tailStreamLog.js +28 -0
  61. package/dist/mcp/toolResults.d.ts +17 -0
  62. package/dist/mcp/toolResults.js +15 -0
  63. package/dist/mcp/tools.js +4 -0
  64. package/dist/mcp/waitRun.js +4 -4
  65. package/dist/mcp/waitingGates.d.ts +1 -0
  66. package/dist/mcp/waitingGates.js +3 -2
  67. package/dist/package-meta.d.ts +1 -1
  68. package/dist/package-meta.js +1 -1
  69. package/dist/projection/projectRun.d.ts +3 -0
  70. package/dist/projection/projectRun.js +7 -0
  71. package/dist/runstore/createStore.d.ts +10 -0
  72. package/dist/runstore/createStore.js +13 -4
  73. package/dist/runstore/port.d.ts +17 -2
  74. package/dist/runstore/sqlite/SqliteRunStore.d.ts +11 -1
  75. package/dist/runstore/sqlite/SqliteRunStore.js +81 -26
  76. package/dist/runstore/sqlite/schema.d.ts +1 -1
  77. package/dist/runstore/sqlite/schema.js +6 -0
  78. package/dist/runstore/submission.d.ts +11 -0
  79. package/dist/runstore/submission.js +7 -0
  80. package/dist/runstore/workspaceLayout.d.ts +1 -0
  81. package/dist/runstore/workspaceLayout.js +3 -0
  82. package/dist/runtime/feedbackLoopCoordinator.d.ts +9 -1
  83. package/dist/runtime/feedbackLoopCoordinator.js +50 -20
  84. package/dist/runtime/feedbackLoopDecision.js +33 -1
  85. package/dist/runtime/pipelineRunner.d.ts +5 -3
  86. package/dist/runtime/pipelineRunner.js +6 -1
  87. package/dist/runtime/pipelineScheduler.js +32 -15
  88. package/dist/runtime/reloadRunCatalog.js +7 -1
  89. package/dist/runtime/resolveEnvelopeRef.d.ts +30 -0
  90. package/dist/runtime/resolveEnvelopeRef.js +79 -0
  91. package/dist/runtime/resumeReconstruct.js +2 -2
  92. package/dist/runtime/runManager.d.ts +24 -2
  93. package/dist/runtime/runManager.js +83 -19
  94. package/dist/runtime/settingsFile.d.ts +2 -0
  95. package/dist/runtime/settingsFile.js +19 -0
  96. package/dist/runtime/stageAttemptBootstrap.d.ts +3 -0
  97. package/dist/runtime/stageAttemptBootstrap.js +8 -2
  98. package/dist/runtime/stageStreamLog.d.ts +17 -0
  99. package/dist/runtime/stageStreamLog.js +89 -0
  100. package/dist/runtime/stageWorker.js +2 -1
  101. package/dist/server/bootstrap.d.ts +2 -0
  102. package/dist/server/bootstrap.js +22 -4
  103. package/dist/server/createHttpHost.js +6 -0
  104. package/dist/server/ensureGlobalService.d.ts +35 -0
  105. package/dist/server/ensureGlobalService.js +138 -0
  106. package/dist/server/http.d.ts +20 -1
  107. package/dist/server/http.js +450 -402
  108. package/dist/server/mcpHost.js +7 -8
  109. package/dist/server/operatorResults.d.ts +10 -0
  110. package/dist/server/operatorResults.js +24 -0
  111. package/dist/server/providerRoutes.d.ts +0 -6
  112. package/dist/server/providerRoutes.js +10 -18
  113. package/dist/types/pipeline.d.ts +8 -0
  114. package/dist/ui/assets/{index-DMVdl1qB.js → index-Da5EHU6M.js} +5 -5
  115. package/dist/ui/index.html +1 -1
  116. package/package.json +2 -1
  117. package/skills/stageflow/references/control-surface.md +2 -2
  118. package/skills/stageflow-run/SKILL.md +27 -9
  119. package/skills/stageflow-run/references/mcp-call.md +1 -1
  120. package/skills/stageflow-run/scripts/mcp-call.mjs +9 -0
@@ -0,0 +1,182 @@
1
+ import path from "node:path";
2
+ import { globalStageflowHome } from "../project/globalHome.js";
3
+ import { PipelineValidationError } from "../runtime/pipelineValidationError.js";
4
+ import { runWorkspaceDir, storeRootFor } from "../runstore/paths.js";
5
+ async function postJson(base, urlPath, body) {
6
+ const res = await fetch(`${base}${urlPath}`, {
7
+ method: "POST",
8
+ headers: { "Content-Type": "application/json" },
9
+ body: JSON.stringify(body ?? {}),
10
+ });
11
+ return { status: res.status, body: await parseJsonBody(res) };
12
+ }
13
+ async function getJson(base, urlPath) {
14
+ const res = await fetch(`${base}${urlPath}`);
15
+ return { status: res.status, body: await parseJsonBody(res) };
16
+ }
17
+ async function parseJsonBody(res) {
18
+ const text = await res.text();
19
+ if (text.length === 0)
20
+ return undefined;
21
+ try {
22
+ return JSON.parse(text);
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ function extractError(body, status) {
29
+ if (body && typeof body === "object" && typeof body.error === "string") {
30
+ return body.error;
31
+ }
32
+ return `request to global Stageflow service failed (status ${status})`;
33
+ }
34
+ function enc(value) {
35
+ return encodeURIComponent(value);
36
+ }
37
+ export function computeRunDir(runId) {
38
+ return runWorkspaceDir(storeRootFor(globalStageflowHome()), runId);
39
+ }
40
+ export async function httpReadRun(base, runId) {
41
+ const { status, body } = await getJson(base, `/api/runs/${enc(runId)}`);
42
+ if (status !== 200) {
43
+ throw new Error(extractError(body, status));
44
+ }
45
+ return body;
46
+ }
47
+ /** Thin RunStore-shaped reader backed by the global service, for the CLI output helpers that only need `readRun`. */
48
+ export function httpStoreReader(base) {
49
+ return { readRun: (runId) => httpReadRun(base, runId) };
50
+ }
51
+ function isRunTerminal(detail) {
52
+ return (detail.status === "succeeded" ||
53
+ detail.status === "failed" ||
54
+ (detail.status === "running" && detail.waiting_stage_id !== undefined));
55
+ }
56
+ function sleep(ms) {
57
+ return new Promise((resolve) => setTimeout(resolve, ms));
58
+ }
59
+ export async function pollRunUntilTerminal(base, runId, options) {
60
+ const pollIntervalMs = options?.pollIntervalMs ?? 500;
61
+ for (;;) {
62
+ const detail = await httpReadRun(base, runId);
63
+ if (isRunTerminal(detail))
64
+ return detail;
65
+ await sleep(pollIntervalMs);
66
+ }
67
+ }
68
+ export function runDetailToPipelineRunResult(detail) {
69
+ const outcome = detail.status === "succeeded"
70
+ ? "succeeded"
71
+ : detail.status === "failed"
72
+ ? "failed"
73
+ : "waiting";
74
+ return {
75
+ ok: outcome === "succeeded",
76
+ outcome,
77
+ runId: detail.run_id,
78
+ runDir: computeRunDir(detail.run_id),
79
+ ...(outcome === "failed" && detail.failed_reason !== undefined
80
+ ? { reason: detail.failed_reason }
81
+ : {}),
82
+ };
83
+ }
84
+ function toStartFailure(status, body) {
85
+ const rest = body && typeof body === "object" ? { ...body } : {};
86
+ const error = typeof rest.error === "string" ? rest.error : undefined;
87
+ delete rest.error;
88
+ return {
89
+ ok: false,
90
+ reason: error ?? extractError(body, status),
91
+ status,
92
+ ...rest,
93
+ };
94
+ }
95
+ function validationResultFrom(body) {
96
+ if (body && typeof body === "object" && "validation" in body) {
97
+ return body.validation;
98
+ }
99
+ return undefined;
100
+ }
101
+ export async function httpStartRun(base, input) {
102
+ const { status, body } = await postJson(base, "/api/runs", input);
103
+ if (status === 400) {
104
+ const validation = validationResultFrom(body);
105
+ if (validation !== undefined)
106
+ throw new PipelineValidationError(validation);
107
+ }
108
+ if (status !== 202)
109
+ return toStartFailure(status, body);
110
+ const runId = body.runId;
111
+ return {
112
+ ok: true,
113
+ runId,
114
+ done: pollRunUntilTerminal(base, runId).then(runDetailToPipelineRunResult),
115
+ };
116
+ }
117
+ export async function httpRerun(base, runId) {
118
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/rerun`, {});
119
+ if (status !== 202)
120
+ return toStartFailure(status, body);
121
+ const newRunId = body.runId;
122
+ return {
123
+ ok: true,
124
+ runId: newRunId,
125
+ done: pollRunUntilTerminal(base, newRunId).then(runDetailToPipelineRunResult),
126
+ };
127
+ }
128
+ export async function httpDeliverAnswer(base, runId, stageId, answer) {
129
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/answer`, answer);
130
+ if (status === 202)
131
+ return { ok: true };
132
+ return { ok: false, reason: extractError(body, status), status: status };
133
+ }
134
+ export async function httpDecideFeedbackLoop(base, runId, stageId, input) {
135
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/feedback-decision`, input);
136
+ if (status === 202) {
137
+ const parsed = body;
138
+ return { ok: true, effect: parsed.effect, loopId: parsed.loopId };
139
+ }
140
+ return { ok: false, reason: extractError(body, status), status };
141
+ }
142
+ export async function httpRetryStageUntilStop(base, runId, stageId) {
143
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/retry`, {});
144
+ if (status !== 202) {
145
+ return { ok: false, reason: extractError(body, status), status };
146
+ }
147
+ const detail = await pollRunUntilTerminal(base, runId);
148
+ return { ok: true, pipeline: runDetailToPipelineRunResult(detail) };
149
+ }
150
+ export async function httpResumeTimedOutStage(base, runId, stageId) {
151
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/resume`, {});
152
+ if (status === 202) {
153
+ const parsed = body;
154
+ return { ok: true, runId: parsed.runId, stageId: parsed.stageId, attemptIndex: parsed.attemptIndex };
155
+ }
156
+ return { ok: false, reason: extractError(body, status), status };
157
+ }
158
+ export async function httpRecoverManualStageUntilStop(base, runId, stageId, guidance) {
159
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/recovery`, guidance !== undefined ? { guidance } : {});
160
+ if (status !== 202) {
161
+ return { ok: false, reason: extractError(body, status), status };
162
+ }
163
+ const detail = await pollRunUntilTerminal(base, runId);
164
+ return { ok: true, pipeline: runDetailToPipelineRunResult(detail) };
165
+ }
166
+ export async function httpStopManualRecovery(base, runId, stageId) {
167
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/recovery/stop`, {});
168
+ if (status === 202)
169
+ return body;
170
+ return { ok: false, reason: extractError(body, status), status };
171
+ }
172
+ export async function httpAbandonStage(base, runId, stageId) {
173
+ const { status, body } = await postJson(base, `/api/runs/${enc(runId)}/stages/${enc(stageId)}/abandon`, {});
174
+ if (status === 202) {
175
+ const parsed = body;
176
+ return { ok: true, runId: parsed.runId, stageId: parsed.stageId };
177
+ }
178
+ return { ok: false, reason: extractError(body, status), status };
179
+ }
180
+ export function resolveAbsolute(cwd, maybeRelative) {
181
+ return path.resolve(cwd, maybeRelative);
182
+ }
@@ -1,4 +1,5 @@
1
- import { defaultContext, detectPiHome, getAuthStatus, getCredentialSourceSettings, listProviders, loginWithApiKey, loginWithOauth, logoutProvider, ProviderAuthError, setCredentialSource, } from "../agent/providerAuth.js";
1
+ import { defaultContext, detectPiHome, getAuthStatus, getCredentialSourceSettings, listProviders, loginWithApiKey, loginWithOauth, logoutProvider, setCredentialSource, } from "../agent/providerAuth.js";
2
+ import { mapProviderAuthError } from "../agent/providerInspect.js";
2
3
  import { createTerminalAuthInteraction } from "./terminalAuthInteraction.js";
3
4
  import { promptSecret, readApiKeyFromEnv } from "./terminalSecret.js";
4
5
  export const PROVIDERS_USAGE = `Usage:
@@ -152,8 +153,9 @@ export async function runProvidersCommand(args, cwd, io = {}, ctx = defaultConte
152
153
  return 0;
153
154
  }
154
155
  catch (err) {
155
- if (err instanceof ProviderAuthError && err.status === 404) {
156
- out.error("Provider not found");
156
+ const mapped = mapProviderAuthError(err);
157
+ if (mapped.status === 404) {
158
+ out.error(mapped.body.error);
157
159
  return 1;
158
160
  }
159
161
  throw err;
@@ -1,5 +1,6 @@
1
1
  import type { RunStore } from "../runstore/port.js";
2
- import { type StartRunResult } from "../runtime/runManager.js";
2
+ import type { StartRunResult } from "../runtime/runManager.js";
3
+ import { type EnsureGlobalServiceResult } from "../server/ensureGlobalService.js";
3
4
  import { type CliRunReportIo } from "./runOutput.js";
4
5
  export declare const RUN_USAGE = "Usage:\n sf run --task <path> --pipeline <path> [--checkout <path>] [--json] [--include stages] [--skip-gates] [--git-sha <sha>] [--ci-pr-url <url>] [--ci-job-url <url>] [--operator-cwd <path>] [--operator-agent-dir <path>]";
5
6
  export type RunCommandIo = CliRunReportIo;
@@ -16,15 +17,15 @@ export declare function completeCliRun(started: Extract<StartRunResult, {
16
17
  ok: true;
17
18
  }>, io?: RunCommandIo, options?: {
18
19
  json?: boolean;
19
- store?: RunStore;
20
+ store?: Pick<RunStore, "readRun">;
20
21
  includeStages?: boolean;
21
22
  }): Promise<number>;
22
23
  export declare function runRunCommand(args: string[], options?: {
23
24
  cwd?: string;
24
- projectRoot?: string;
25
- isGitProject?: boolean;
26
25
  io?: Partial<RunCommandIo>;
27
26
  startRun?: StartRunFn;
28
- store?: RunStore;
27
+ store?: Pick<RunStore, "readRun">;
29
28
  env?: Record<string, string | undefined>;
29
+ hostBaseUrl?: string;
30
+ ensureService?: () => Promise<EnsureGlobalServiceResult>;
30
31
  }): Promise<number>;
@@ -1,11 +1,8 @@
1
- import { resolveGlobalOnlyAgentPort } from "../agent/resolveAgentPort.js";
2
- import { createRunStore } from "../runstore/createStore.js";
3
1
  import { PipelineValidationError } from "../runtime/pipelineRunner.js";
4
- import { RunManager } from "../runtime/runManager.js";
5
- import { readStageExecutionMode } from "../runtime/stageConcurrency.js";
2
+ import { ensureGlobalService, hostBaseUrl, } from "../server/ensureGlobalService.js";
3
+ import { httpStartRun, httpStoreReader, resolveAbsolute } from "./hostClient.js";
6
4
  import { reportCliRun, } from "./runOutput.js";
7
5
  import { resolveCiIdentity } from "./ciIdentity.js";
8
- import { resolveOperatorCatalog } from "./operatorCatalog.js";
9
6
  import { exitCodeForValidation, formatValidationHuman, formatValidationJson, } from "./validateOutput.js";
10
7
  export const RUN_USAGE = `Usage:
11
8
  sf run --task <path> --pipeline <path> [--checkout <path>] [--json] [--include stages] [--skip-gates] [--git-sha <sha>] [--ci-pr-url <url>] [--ci-job-url <url>] [--operator-cwd <path>] [--operator-agent-dir <path>]`;
@@ -133,19 +130,23 @@ function parseRunArgs(args) {
133
130
  operatorAgentDir,
134
131
  };
135
132
  }
136
- function defaultStartRun(cwd, projectRoot, isGitProject, operatorCatalog) {
133
+ function defaultStartRun(cwd, base, ensureService) {
137
134
  return async (input) => {
138
- const store = createRunStore({ rootDir: projectRoot });
139
- const manager = new RunManager({
140
- agent: await resolveGlobalOnlyAgentPort(projectRoot),
141
- store,
142
- cwd,
143
- projectRoot,
144
- isGitProject,
145
- operatorCatalog,
146
- executionMode: readStageExecutionMode(process.env, "process"),
135
+ const ensured = await ensureService();
136
+ if (!ensured.ok) {
137
+ return { ok: false, reason: ensured.message, status: 503 };
138
+ }
139
+ return httpStartRun(base, {
140
+ pipeline: resolveAbsolute(cwd, input.pipeline),
141
+ task: resolveAbsolute(cwd, input.task),
142
+ ...(input.checkoutOverride !== undefined
143
+ ? { checkoutOverride: resolveAbsolute(cwd, input.checkoutOverride) }
144
+ : {}),
145
+ ...(input.skipGates !== undefined ? { skipGates: input.skipGates } : {}),
146
+ ...(input.gitSha !== undefined ? { gitSha: input.gitSha } : {}),
147
+ ...(input.ciPrUrl !== undefined ? { ciPrUrl: input.ciPrUrl } : {}),
148
+ ...(input.ciJobUrl !== undefined ? { ciJobUrl: input.ciJobUrl } : {}),
147
149
  });
148
- return manager.startRun(input);
149
150
  };
150
151
  }
151
152
  export async function completeCliRun(started, io = defaultIo, options = {}) {
@@ -159,9 +160,8 @@ export async function completeCliRun(started, io = defaultIo, options = {}) {
159
160
  }
160
161
  export async function runRunCommand(args, options = {}) {
161
162
  const cwd = options.cwd ?? process.cwd();
162
- const projectRoot = options.projectRoot ?? cwd;
163
- const isGitProject = options.isGitProject ?? false;
164
163
  const out = { ...defaultIo, ...options.io };
164
+ const base = options.hostBaseUrl ?? hostBaseUrl();
165
165
  let parsed;
166
166
  try {
167
167
  parsed = parseRunArgs(args);
@@ -185,16 +185,11 @@ export async function runRunCommand(args, options = {}) {
185
185
  out.error("error: --include stages requires --json");
186
186
  return 1;
187
187
  }
188
- const operatorCatalog = resolveOperatorCatalog({
189
- flags: {
190
- operatorCwd: parsed.operatorCwd,
191
- operatorAgentDir: parsed.operatorAgentDir,
192
- },
193
- env: options.env ?? process.env,
194
- defaultCwd: cwd,
195
- });
188
+ if (parsed.operatorCwd !== undefined || parsed.operatorAgentDir !== undefined) {
189
+ out.error("warning: --operator-cwd/--operator-agent-dir have no effect on `sf run` now that pipelines execute in the shared global Stageflow service; set STAGEFLOW_OPERATOR_CWD/STAGEFLOW_OPERATOR_AGENT_DIR before that service first starts instead.");
190
+ }
196
191
  const startRun = options.startRun ??
197
- defaultStartRun(cwd, projectRoot, isGitProject, operatorCatalog);
192
+ defaultStartRun(cwd, base, options.ensureService ?? (() => ensureGlobalService()));
198
193
  const identity = resolveCiIdentity({
199
194
  flags: {
200
195
  gitSha: parsed.gitSha,
@@ -203,10 +198,7 @@ export async function runRunCommand(args, options = {}) {
203
198
  },
204
199
  env: options.env ?? process.env,
205
200
  });
206
- const store = options.store ??
207
- (parsed.includeStages
208
- ? createRunStore({ rootDir: projectRoot })
209
- : undefined);
201
+ const store = options.store ?? (parsed.includeStages ? httpStoreReader(base) : undefined);
210
202
  try {
211
203
  const started = await startRun({
212
204
  task: parsed.task,
@@ -17,6 +17,6 @@ export type CliRunReportEvent = {
17
17
  export declare function reportCliRun(event: CliRunReportEvent, options: {
18
18
  json?: boolean;
19
19
  io: CliRunReportIo;
20
- store?: RunStore;
20
+ store?: Pick<RunStore, "readRun">;
21
21
  includeStages?: boolean;
22
22
  }): Promise<number>;
@@ -0,0 +1,33 @@
1
+ import { type EnsureGlobalServiceResult } from "../server/ensureGlobalService.js";
2
+ export declare const RUN_STAGE_USAGE = "Usage:\n sf run-stage (--stage <path> | --stage-inline '<json>') (--task <path> | --task-inline '<json>' | --envelope-ref <runId>:<stageId>[:<attempt>] [--envelope-ref ...]) [--checkout <path>] [--model <id>] [--blocking] [--timeout-ms <n>] [--json]\n\nRun a single stage directly against the shared Stageflow service, without authoring a pipeline file. Distinct from the internal-only, worker-process-only `sf internal run-stage`.\n --stage <path> Filesystem path to a catalog stage YAML file\n --stage-inline <json> Inline stage body object ({ id, system_prompt, io, ... } \u2014 no uses:/route/pipeline wrapper)\n --task <path> Filesystem path to a catalog task YAML file\n --task-inline <json> Inline task object ({ id, goal, ... })\n --envelope-ref <ref> Resolve a previously stored StageEnvelope as this stage's input instead of a task: <runId>:<stageId>[:<attempt>]. Repeat to pass more than one \u2014 each resolved payload is namespaced under its stageId in input (disambiguated by runId on a stageId collision), and summaries are combined into goal.\n --checkout <path> Optional checkout to use with --envelope-ref (--task/--task-inline carry their own checkout)\n --model <id> Override the model/backend for this call only, ahead of the stage's own declared model\n --blocking Wait for the run to reach a terminal or waiting state and print the result in this same call, instead of returning immediately with just the run id\n --timeout-ms <n> Wait budget in ms when --blocking is set\n --json Machine-readable JSON output";
3
+ export type RunStageEnvelopeRef = {
4
+ runId: string;
5
+ stageId: string;
6
+ attempt?: number;
7
+ };
8
+ export type RunStageToolArgs = {
9
+ stage: string | Record<string, unknown>;
10
+ task_path?: string;
11
+ task?: Record<string, unknown>;
12
+ envelope_ref?: RunStageEnvelopeRef | RunStageEnvelopeRef[];
13
+ checkout?: string;
14
+ model?: string;
15
+ blocking?: boolean;
16
+ timeout_ms?: number;
17
+ };
18
+ export type RunStageToolResult = {
19
+ isError: boolean;
20
+ payload: Record<string, unknown> | null;
21
+ };
22
+ export type RunStageCallFn = (args: RunStageToolArgs) => Promise<RunStageToolResult>;
23
+ export type RunStageCommandIo = {
24
+ log: (line: string) => void;
25
+ error: (line: string) => void;
26
+ };
27
+ export declare function runRunStageCommand(args: string[], options?: {
28
+ cwd?: string;
29
+ io?: Partial<RunStageCommandIo>;
30
+ callTool?: RunStageCallFn;
31
+ hostBaseUrl?: string;
32
+ ensureService?: () => Promise<EnsureGlobalServiceResult>;
33
+ }): Promise<number>;