stageflow 0.18.0 → 0.23.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.
- package/README.md +2 -1
- package/dist/agent/activity.d.ts +9 -0
- package/dist/agent/activityObserver.d.ts +3 -0
- package/dist/agent/activityObserver.js +6 -1
- package/dist/agent/claudeAdapter.js +38 -0
- package/dist/agent/fakeAgent.js +3 -1
- package/dist/agent/piAdapter.js +40 -4
- package/dist/agent/port.d.ts +3 -1
- package/dist/agent/providerInspect.d.ts +19 -0
- package/dist/agent/providerInspect.js +35 -0
- package/dist/agent/stageTimeout.d.ts +9 -0
- package/dist/agent/stageTimeout.js +24 -0
- package/dist/agent/streamLogRedact.d.ts +2 -0
- package/dist/agent/streamLogRedact.js +13 -0
- package/dist/cli/artifactCommand.js +2 -2
- package/dist/cli/envelopeCommand.js +2 -2
- package/dist/cli/exportRunCommand.js +2 -2
- package/dist/cli/graphCommand.d.ts +15 -0
- package/dist/cli/graphCommand.js +79 -0
- package/dist/cli/graphRender.d.ts +2 -0
- package/dist/cli/graphRender.js +85 -0
- package/dist/cli/hostClient.d.ts +43 -0
- package/dist/cli/hostClient.js +182 -0
- package/dist/cli/providersCommand.js +5 -3
- package/dist/cli/runCommand.d.ts +6 -5
- package/dist/cli/runCommand.js +23 -31
- package/dist/cli/runOutput.d.ts +1 -1
- package/dist/cli/runsCommand.d.ts +4 -8
- package/dist/cli/runsCommand.js +65 -89
- package/dist/cli.js +13 -5
- package/dist/config/describePipeline.d.ts +26 -0
- package/dist/config/describePipeline.js +37 -0
- package/dist/config/loadPipeline.d.ts +13 -1
- package/dist/config/loadPipeline.js +34 -4
- package/dist/config/mergePipelineIncludes.d.ts +11 -0
- package/dist/config/mergePipelineIncludes.js +75 -0
- package/dist/config/validateCatalog.d.ts +2 -2
- package/dist/config/validateCatalog.js +24 -17
- package/dist/mcp/catalogTools.js +146 -52
- package/dist/mcp/controlTools.js +94 -19
- package/dist/mcp/deps.d.ts +3 -0
- package/dist/mcp/projectMcpTools.d.ts +3 -0
- package/dist/mcp/projectMcpTools.js +25 -0
- package/dist/mcp/providerTools.d.ts +3 -0
- package/dist/mcp/providerTools.js +17 -0
- package/dist/mcp/readArtifact.d.ts +9 -0
- package/dist/mcp/readArtifact.js +11 -0
- package/dist/mcp/server.js +9 -1
- package/dist/mcp/tailStreamLog.d.ts +8 -0
- package/dist/mcp/tailStreamLog.js +28 -0
- package/dist/mcp/toolResults.d.ts +17 -0
- package/dist/mcp/toolResults.js +15 -0
- package/dist/mcp/tools.js +4 -0
- package/dist/mcp/waitRun.js +4 -4
- package/dist/mcp/waitingGates.d.ts +1 -0
- package/dist/mcp/waitingGates.js +3 -2
- package/dist/package-meta.d.ts +1 -1
- package/dist/package-meta.js +1 -1
- package/dist/projection/projectRun.d.ts +3 -0
- package/dist/projection/projectRun.js +7 -0
- package/dist/runstore/port.d.ts +3 -1
- package/dist/runstore/port.js +2 -0
- package/dist/runstore/sqlite/SqliteRunStore.d.ts +2 -1
- package/dist/runstore/sqlite/SqliteRunStore.js +15 -1
- package/dist/runstore/workspaceLayout.d.ts +1 -0
- package/dist/runstore/workspaceLayout.js +3 -0
- package/dist/runtime/feedbackLoopCoordinator.d.ts +9 -1
- package/dist/runtime/feedbackLoopCoordinator.js +50 -20
- package/dist/runtime/feedbackLoopDecision.js +33 -1
- package/dist/runtime/forkGeneration.d.ts +4 -0
- package/dist/runtime/forkGeneration.js +16 -0
- package/dist/runtime/pipelineRunner.d.ts +3 -3
- package/dist/runtime/pipelineRunner.js +3 -1
- package/dist/runtime/pipelineScheduler.js +23 -1
- package/dist/runtime/reopenSkipped.d.ts +13 -0
- package/dist/runtime/reopenSkipped.js +56 -0
- package/dist/runtime/resumeReconstruct.js +2 -2
- package/dist/runtime/resumeTimedOut.d.ts +33 -0
- package/dist/runtime/resumeTimedOut.js +165 -0
- package/dist/runtime/runManager.d.ts +3 -1
- package/dist/runtime/runManager.js +110 -14
- package/dist/runtime/settingsFile.d.ts +2 -0
- package/dist/runtime/settingsFile.js +19 -0
- package/dist/runtime/stageAttemptBootstrap.d.ts +3 -0
- package/dist/runtime/stageAttemptBootstrap.js +8 -2
- package/dist/runtime/stageRecovery.js +2 -2
- package/dist/runtime/stageRunner.js +6 -2
- package/dist/runtime/stageStreamLog.d.ts +17 -0
- package/dist/runtime/stageStreamLog.js +89 -0
- package/dist/runtime/stageWorker.js +2 -1
- package/dist/server/bootstrap.js +9 -2
- package/dist/server/ensureGlobalService.d.ts +35 -0
- package/dist/server/ensureGlobalService.js +138 -0
- package/dist/server/http.d.ts +20 -1
- package/dist/server/http.js +452 -386
- package/dist/server/mcpHost.js +7 -8
- package/dist/server/operatorResults.d.ts +10 -0
- package/dist/server/operatorResults.js +24 -0
- package/dist/server/providerRoutes.d.ts +0 -6
- package/dist/server/providerRoutes.js +10 -18
- package/dist/tools/askOperator.d.ts +1 -0
- package/dist/tools/askOperator.js +14 -11
- package/dist/tools/emitStageEnvelope.d.ts +1 -0
- package/dist/tools/emitStageEnvelope.js +3 -1
- package/dist/tools/prepareToolArguments.d.ts +4 -0
- package/dist/tools/prepareToolArguments.js +79 -0
- package/dist/types/pipeline.d.ts +8 -0
- package/dist/ui/assets/{index-DsgVjLUS.css → index-CSsDued1.css} +1 -1
- package/dist/ui/assets/index-Da5EHU6M.js +119 -0
- package/dist/ui/index.html +2 -2
- package/package.json +1 -1
- package/skills/stageflow/references/control-surface.md +2 -2
- package/skills/stageflow-run/SKILL.md +27 -9
- package/skills/stageflow-run/references/mcp-call.md +1 -1
- package/skills/stageflow-run/scripts/mcp-call.mjs +9 -0
- package/dist/ui/assets/index-DwKGaQvQ.js +0 -119
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PipelineRunResult } from "../runtime/pipelineRunner.js";
|
|
2
|
+
import type { AbandonStageResult, DecideFeedbackLoopResult, StartRunResult, StopManualRecoveryResult } from "../runtime/runManager.js";
|
|
3
|
+
import type { DeliverAnswerResult } from "../runtime/stageHitl.js";
|
|
4
|
+
import type { RetryStageResult } from "../runtime/runRetryCoordinator.js";
|
|
5
|
+
import type { RunDetail, RunStore } from "../runstore/port.js";
|
|
6
|
+
export declare function computeRunDir(runId: string): string;
|
|
7
|
+
export declare function httpReadRun(base: string, runId: string): Promise<RunDetail>;
|
|
8
|
+
/** Thin RunStore-shaped reader backed by the global service, for the CLI output helpers that only need `readRun`. */
|
|
9
|
+
export declare function httpStoreReader(base: string): Pick<RunStore, "readRun">;
|
|
10
|
+
export declare function pollRunUntilTerminal(base: string, runId: string, options?: {
|
|
11
|
+
pollIntervalMs?: number;
|
|
12
|
+
}): Promise<RunDetail>;
|
|
13
|
+
export declare function runDetailToPipelineRunResult(detail: RunDetail): PipelineRunResult;
|
|
14
|
+
export type HttpStartRunInput = {
|
|
15
|
+
pipeline: string;
|
|
16
|
+
task: string;
|
|
17
|
+
checkoutOverride?: string;
|
|
18
|
+
skipGates?: boolean;
|
|
19
|
+
gitSha?: string;
|
|
20
|
+
ciPrUrl?: string;
|
|
21
|
+
ciJobUrl?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function httpStartRun(base: string, input: HttpStartRunInput): Promise<StartRunResult>;
|
|
24
|
+
export declare function httpRerun(base: string, runId: string): Promise<StartRunResult>;
|
|
25
|
+
export declare function httpDeliverAnswer(base: string, runId: string, stageId: string, answer: unknown): Promise<DeliverAnswerResult>;
|
|
26
|
+
export declare function httpDecideFeedbackLoop(base: string, runId: string, stageId: string, input: {
|
|
27
|
+
decision: "extend" | "continue" | "abandon";
|
|
28
|
+
loopId?: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
}): Promise<DecideFeedbackLoopResult>;
|
|
31
|
+
type RetryOrchestrationResult = {
|
|
32
|
+
ok: true;
|
|
33
|
+
pipeline: PipelineRunResult;
|
|
34
|
+
} | Extract<RetryStageResult, {
|
|
35
|
+
ok: false;
|
|
36
|
+
}>;
|
|
37
|
+
export declare function httpRetryStageUntilStop(base: string, runId: string, stageId: string): Promise<RetryOrchestrationResult>;
|
|
38
|
+
export declare function httpResumeTimedOutStage(base: string, runId: string, stageId: string): Promise<RetryStageResult>;
|
|
39
|
+
export declare function httpRecoverManualStageUntilStop(base: string, runId: string, stageId: string, guidance?: string): Promise<RetryOrchestrationResult>;
|
|
40
|
+
export declare function httpStopManualRecovery(base: string, runId: string, stageId: string): Promise<StopManualRecoveryResult>;
|
|
41
|
+
export declare function httpAbandonStage(base: string, runId: string, stageId: string): Promise<AbandonStageResult>;
|
|
42
|
+
export declare function resolveAbsolute(cwd: string, maybeRelative: string): string;
|
|
43
|
+
export {};
|
|
@@ -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,
|
|
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
|
-
|
|
156
|
-
|
|
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;
|
package/dist/cli/runCommand.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RunStore } from "../runstore/port.js";
|
|
2
|
-
import {
|
|
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>;
|
package/dist/cli/runCommand.js
CHANGED
|
@@ -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 {
|
|
5
|
-
import {
|
|
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,
|
|
133
|
+
function defaultStartRun(cwd, base, ensureService) {
|
|
137
134
|
return async (input) => {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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,
|
|
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,
|
package/dist/cli/runOutput.d.ts
CHANGED
|
@@ -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>;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import type { RunStore } from "../runstore/port.js";
|
|
2
|
-
import {
|
|
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]";
|
|
2
|
+
import { type EnsureGlobalServiceResult } from "../server/ensureGlobalService.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 resume --run <runId> --stage <stageId> [--json]\n sf runs abandon --run <runId> --stage <stageId> [--json]\n sf runs rerun --run <runId> [--json]";
|
|
4
4
|
export type RunsCommandIo = {
|
|
5
5
|
log: (line: string) => void;
|
|
6
6
|
error: (line: string) => void;
|
|
7
7
|
};
|
|
8
|
-
export type HostProbeResult = "up" | "down";
|
|
9
|
-
export declare function defaultProbeHost(): Promise<HostProbeResult>;
|
|
10
8
|
export declare function runRunsCommand(args: string[], options?: {
|
|
11
9
|
cwd?: string;
|
|
12
|
-
projectRoot?: string;
|
|
13
|
-
isGitProject?: boolean;
|
|
14
10
|
io?: Partial<RunsCommandIo>;
|
|
15
11
|
store?: RunStore;
|
|
16
|
-
probeHost?: () => Promise<HostProbeResult>;
|
|
17
12
|
stdinIsTTY?: boolean;
|
|
18
13
|
readStdin?: () => string;
|
|
19
14
|
waitSignal?: AbortSignal;
|
|
20
15
|
env?: NodeJS.ProcessEnv;
|
|
21
|
-
|
|
16
|
+
hostBaseUrl?: string;
|
|
17
|
+
ensureService?: () => Promise<EnsureGlobalServiceResult>;
|
|
22
18
|
}): Promise<number>;
|