@relayflows/sdk 2.0.30 → 2.0.32
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/dist/agent-artifacts.d.ts.map +1 -1
- package/dist/agent-artifacts.js +2 -9
- package/dist/agent-artifacts.js.map +1 -1
- package/dist/agent-cwd.d.ts +69 -0
- package/dist/agent-cwd.d.ts.map +1 -0
- package/dist/agent-cwd.js +140 -0
- package/dist/agent-cwd.js.map +1 -0
- package/dist/artifact-scan-policy.d.ts +35 -0
- package/dist/artifact-scan-policy.d.ts.map +1 -0
- package/dist/artifact-scan-policy.js +49 -0
- package/dist/artifact-scan-policy.js.map +1 -0
- package/dist/authored-completion-record.d.ts +35 -0
- package/dist/authored-completion-record.d.ts.map +1 -0
- package/dist/authored-completion-record.js +92 -0
- package/dist/authored-completion-record.js.map +1 -0
- package/dist/authored-completion.d.ts +99 -0
- package/dist/authored-completion.d.ts.map +1 -0
- package/dist/authored-completion.js +184 -0
- package/dist/authored-completion.js.map +1 -0
- package/dist/authored-flow-error.d.ts +13 -1
- package/dist/authored-flow-error.d.ts.map +1 -1
- package/dist/authored-flow-error.js +12 -0
- package/dist/authored-flow-error.js.map +1 -1
- package/dist/authored-flow-executor.d.ts +7 -30
- package/dist/authored-flow-executor.d.ts.map +1 -1
- package/dist/authored-flow-executor.js +54 -47
- package/dist/authored-flow-executor.js.map +1 -1
- package/dist/authored-human.d.ts.map +1 -1
- package/dist/authored-human.js +1 -3
- package/dist/authored-human.js.map +1 -1
- package/dist/authored-node-entry.js +4 -1
- package/dist/authored-node-entry.js.map +1 -1
- package/dist/authored-node-runner.d.ts +9 -1
- package/dist/authored-node-runner.d.ts.map +1 -1
- package/dist/authored-node-runner.js +92 -17
- package/dist/authored-node-runner.js.map +1 -1
- package/dist/authored-preflight.d.ts +4 -0
- package/dist/authored-preflight.d.ts.map +1 -0
- package/dist/authored-preflight.js +50 -0
- package/dist/authored-preflight.js.map +1 -0
- package/dist/authored-root.d.ts +5 -0
- package/dist/authored-root.d.ts.map +1 -1
- package/dist/authored-root.js +20 -2
- package/dist/authored-root.js.map +1 -1
- package/dist/authored-step-output.d.ts +35 -10
- package/dist/authored-step-output.d.ts.map +1 -1
- package/dist/authored-step-output.js +108 -40
- package/dist/authored-step-output.js.map +1 -1
- package/dist/authored-verdict.d.ts +28 -0
- package/dist/authored-verdict.d.ts.map +1 -0
- package/dist/authored-verdict.js +79 -0
- package/dist/authored-verdict.js.map +1 -0
- package/dist/authored-worker-step.d.ts +5 -2
- package/dist/authored-worker-step.d.ts.map +1 -1
- package/dist/authored-worker-step.js +51 -13
- package/dist/authored-worker-step.js.map +1 -1
- package/dist/cli/check-worker-surface.d.ts +27 -0
- package/dist/cli/check-worker-surface.d.ts.map +1 -0
- package/dist/cli/check-worker-surface.js +63 -0
- package/dist/cli/check-worker-surface.js.map +1 -0
- package/dist/cli/check.d.ts +28 -3
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +27 -140
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/cli-probe.d.ts +20 -0
- package/dist/cli/cli-probe.d.ts.map +1 -0
- package/dist/cli/cli-probe.js +166 -0
- package/dist/cli/cli-probe.js.map +1 -0
- package/dist/cli/cloud-format.d.ts +9 -0
- package/dist/cli/cloud-format.d.ts.map +1 -0
- package/dist/cli/cloud-format.js +77 -0
- package/dist/cli/cloud-format.js.map +1 -0
- package/dist/cli/cloud-live.d.ts +39 -0
- package/dist/cli/cloud-live.d.ts.map +1 -0
- package/dist/cli/cloud-live.js +325 -0
- package/dist/cli/cloud-live.js.map +1 -0
- package/dist/cli/cloud-mirror-session.d.ts +97 -0
- package/dist/cli/cloud-mirror-session.d.ts.map +1 -0
- package/dist/cli/cloud-mirror-session.js +264 -0
- package/dist/cli/cloud-mirror-session.js.map +1 -0
- package/dist/cli/cloud-read.d.ts +3 -7
- package/dist/cli/cloud-read.d.ts.map +1 -1
- package/dist/cli/cloud-read.js +14 -266
- package/dist/cli/cloud-read.js.map +1 -1
- package/dist/cli/cloud-refusal.d.ts +39 -0
- package/dist/cli/cloud-refusal.d.ts.map +1 -0
- package/dist/cli/cloud-refusal.js +95 -0
- package/dist/cli/cloud-refusal.js.map +1 -0
- package/dist/cli/cloud-status-view.d.ts +7 -0
- package/dist/cli/cloud-status-view.d.ts.map +1 -0
- package/dist/cli/cloud-status-view.js +214 -0
- package/dist/cli/cloud-status-view.js.map +1 -0
- package/dist/cli/direct-run.d.ts.map +1 -1
- package/dist/cli/direct-run.js +16 -2
- package/dist/cli/direct-run.js.map +1 -1
- package/dist/cli/hn-monitor.d.ts +0 -13
- package/dist/cli/hn-monitor.d.ts.map +1 -1
- package/dist/cli/hn-monitor.js +2 -1
- package/dist/cli/hn-monitor.js.map +1 -1
- package/dist/cli/local-agent-remedy.d.ts +80 -0
- package/dist/cli/local-agent-remedy.d.ts.map +1 -0
- package/dist/cli/local-agent-remedy.js +116 -0
- package/dist/cli/local-agent-remedy.js.map +1 -0
- package/dist/cli/observer-session.d.ts +41 -0
- package/dist/cli/observer-session.d.ts.map +1 -0
- package/dist/cli/observer-session.js +78 -0
- package/dist/cli/observer-session.js.map +1 -0
- package/dist/cli/run.d.ts +30 -2
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +186 -24
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/status.d.ts +9 -0
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +31 -2
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/step-evidence.d.ts +90 -0
- package/dist/cli/step-evidence.d.ts.map +1 -0
- package/dist/cli/step-evidence.js +259 -0
- package/dist/cli/step-evidence.js.map +1 -0
- package/dist/cli/step-failure.d.ts +14 -4
- package/dist/cli/step-failure.d.ts.map +1 -1
- package/dist/cli/step-failure.js +41 -76
- package/dist/cli/step-failure.js.map +1 -1
- package/dist/cli-commands.d.ts +12 -0
- package/dist/cli-commands.d.ts.map +1 -1
- package/dist/cli-commands.js +3 -0
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli.d.ts +17 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +134 -57
- package/dist/cli.js.map +1 -1
- package/dist/cloud-deploy.d.ts +1 -1
- package/dist/cloud-deploy.d.ts.map +1 -1
- package/dist/cloud-deploy.js +24 -8
- package/dist/cloud-deploy.js.map +1 -1
- package/dist/cloud-mirror-ledger.d.ts +40 -0
- package/dist/cloud-mirror-ledger.d.ts.map +1 -0
- package/dist/cloud-mirror-ledger.js +142 -0
- package/dist/cloud-mirror-ledger.js.map +1 -0
- package/dist/cloud-mirror-step.d.ts +168 -0
- package/dist/cloud-mirror-step.d.ts.map +1 -0
- package/dist/cloud-mirror-step.js +504 -0
- package/dist/cloud-mirror-step.js.map +1 -0
- package/dist/cloud-mirror-transport.d.ts +94 -0
- package/dist/cloud-mirror-transport.d.ts.map +1 -0
- package/dist/cloud-mirror-transport.js +163 -0
- package/dist/cloud-mirror-transport.js.map +1 -0
- package/dist/cloud-mirror.d.ts +132 -0
- package/dist/cloud-mirror.d.ts.map +1 -0
- package/dist/cloud-mirror.js +556 -0
- package/dist/cloud-mirror.js.map +1 -0
- package/dist/cloud-read.d.ts +15 -0
- package/dist/cloud-read.d.ts.map +1 -1
- package/dist/cloud-read.js +20 -1
- package/dist/cloud-read.js.map +1 -1
- package/dist/cloud-run-record.d.ts +27 -0
- package/dist/cloud-run-record.d.ts.map +1 -0
- package/dist/cloud-run-record.js +56 -0
- package/dist/cloud-run-record.js.map +1 -0
- package/dist/cloud-run.d.ts +2 -9
- package/dist/cloud-run.d.ts.map +1 -1
- package/dist/cloud-run.js +3 -20
- package/dist/cloud-run.js.map +1 -1
- package/dist/communication/local.d.ts.map +1 -1
- package/dist/communication/local.js +2 -1
- package/dist/communication/local.js.map +1 -1
- package/dist/communication/worker.d.ts +1 -1
- package/dist/communication/worker.d.ts.map +1 -1
- package/dist/communication/worker.js +13 -5
- package/dist/communication/worker.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +28 -6
- package/dist/compile.js.map +1 -1
- package/dist/direct-input.d.ts.map +1 -1
- package/dist/direct-input.js +21 -1
- package/dist/direct-input.js.map +1 -1
- package/dist/failure-kinds.d.ts +96 -6
- package/dist/failure-kinds.d.ts.map +1 -1
- package/dist/failure-kinds.js +29 -2
- package/dist/failure-kinds.js.map +1 -1
- package/dist/flow-requirements.d.ts.map +1 -1
- package/dist/flow-requirements.js +24 -9
- package/dist/flow-requirements.js.map +1 -1
- package/dist/gate-contract.d.ts +7 -0
- package/dist/gate-contract.d.ts.map +1 -1
- package/dist/gate-contract.js +6 -1
- package/dist/gate-contract.js.map +1 -1
- package/dist/helper-preflight.d.ts.map +1 -1
- package/dist/helper-preflight.js +10 -3
- package/dist/helper-preflight.js.map +1 -1
- package/dist/helper-reference.d.ts +25 -0
- package/dist/helper-reference.d.ts.map +1 -0
- package/dist/helper-reference.js +129 -0
- package/dist/helper-reference.js.map +1 -0
- package/dist/hosted-extension-runtime.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/journal-client.d.ts +3 -1
- package/dist/journal-client.d.ts.map +1 -1
- package/dist/journal-client.js +17 -2
- package/dist/journal-client.js.map +1 -1
- package/dist/journal-projection.d.ts +16 -0
- package/dist/journal-projection.d.ts.map +1 -0
- package/dist/journal-projection.js +108 -0
- package/dist/journal-projection.js.map +1 -0
- package/dist/llm-worker.js +1 -1
- package/dist/llm-worker.js.map +1 -1
- package/dist/local-agent.d.ts +1 -1
- package/dist/local-agent.d.ts.map +1 -1
- package/dist/local-agent.js +4 -3
- package/dist/local-agent.js.map +1 -1
- package/dist/named-gate-lowering.js +35 -5
- package/dist/named-gate-lowering.js.map +1 -1
- package/dist/named-gate-preflight.d.ts +27 -0
- package/dist/named-gate-preflight.d.ts.map +1 -0
- package/dist/named-gate-preflight.js +47 -0
- package/dist/named-gate-preflight.js.map +1 -0
- package/dist/named-gates.d.ts +1 -1
- package/dist/named-gates.d.ts.map +1 -1
- package/dist/named-gates.js +3 -0
- package/dist/named-gates.js.map +1 -1
- package/dist/observer-link.d.ts +7 -0
- package/dist/observer-link.d.ts.map +1 -1
- package/dist/observer-link.js +3 -1
- package/dist/observer-link.js.map +1 -1
- package/dist/package-version.d.ts +10 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +22 -0
- package/dist/package-version.js.map +1 -0
- package/dist/preflight.d.ts +14 -0
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +25 -3
- package/dist/preflight.js.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/redact.d.ts +42 -0
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +128 -0
- package/dist/redact.js.map +1 -1
- package/dist/relay-cli.d.ts.map +1 -1
- package/dist/relay-cli.js +1 -21
- package/dist/relay-cli.js.map +1 -1
- package/dist/run-projection.d.ts +83 -0
- package/dist/run-projection.d.ts.map +1 -0
- package/dist/run-projection.js +199 -0
- package/dist/run-projection.js.map +1 -0
- package/dist/shell-word.d.ts +19 -0
- package/dist/shell-word.d.ts.map +1 -0
- package/dist/shell-word.js +23 -0
- package/dist/shell-word.js.map +1 -0
- package/dist/spec.d.ts +52 -3
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/step-fields.d.ts +1 -1
- package/dist/step-fields.js +1 -1
- package/dist/step-fields.js.map +1 -1
- package/dist/steps-green.d.ts +27 -0
- package/dist/steps-green.d.ts.map +1 -0
- package/dist/steps-green.js +164 -0
- package/dist/steps-green.js.map +1 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +39 -8
- package/dist/validate.js.map +1 -1
- package/dist/worker-lease.d.ts +8 -1
- package/dist/worker-lease.d.ts.map +1 -1
- package/dist/worker-lease.js +34 -4
- package/dist/worker-lease.js.map +1 -1
- package/dist/worker.d.ts +8 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +17 -9
- package/dist/worker.js.map +1 -1
- package/package.json +3 -7
- package/src/agent-artifacts.ts +2 -10
- package/src/agent-cwd.ts +139 -0
- package/src/artifact-scan-policy.ts +51 -0
- package/src/authored-completion-record.ts +119 -0
- package/src/authored-completion.ts +203 -0
- package/src/authored-flow-error.ts +13 -1
- package/src/authored-flow-executor.ts +91 -58
- package/src/authored-human.ts +1 -4
- package/src/authored-node-entry.ts +4 -1
- package/src/authored-node-runner.ts +96 -22
- package/src/authored-preflight.ts +46 -0
- package/src/authored-root.ts +20 -2
- package/src/authored-step-output.ts +139 -42
- package/src/authored-verdict.ts +87 -0
- package/src/authored-worker-step.ts +63 -14
- package/src/cli/check-worker-surface.ts +66 -0
- package/src/cli/check.ts +59 -166
- package/src/cli/cli-probe.ts +194 -0
- package/src/cli/cloud-format.ts +82 -0
- package/src/cli/cloud-live.ts +366 -0
- package/src/cli/cloud-mirror-session.ts +329 -0
- package/src/cli/cloud-read.ts +13 -282
- package/src/cli/cloud-refusal.ts +113 -0
- package/src/cli/cloud-status-view.ts +213 -0
- package/src/cli/direct-run.ts +19 -2
- package/src/cli/hn-monitor.ts +2 -1
- package/src/cli/local-agent-remedy.ts +160 -0
- package/src/cli/observer-session.ts +107 -0
- package/src/cli/run.ts +233 -28
- package/src/cli/status.ts +59 -3
- package/src/cli/step-evidence.ts +310 -0
- package/src/cli/step-failure.ts +57 -81
- package/src/cli-commands.ts +3 -0
- package/src/cli.ts +155 -60
- package/src/cloud-deploy.ts +26 -8
- package/src/cloud-mirror-ledger.ts +161 -0
- package/src/cloud-mirror-step.ts +618 -0
- package/src/cloud-mirror-transport.ts +261 -0
- package/src/cloud-mirror.ts +633 -0
- package/src/cloud-read.ts +25 -1
- package/src/cloud-run-record.ts +64 -0
- package/src/cloud-run.ts +5 -24
- package/src/communication/local.ts +2 -1
- package/src/communication/worker.ts +13 -5
- package/src/compile.ts +28 -6
- package/src/direct-input.ts +22 -1
- package/src/failure-kinds.ts +104 -2
- package/src/flow-requirements.ts +24 -9
- package/src/gate-contract.ts +13 -1
- package/src/helper-preflight.ts +10 -3
- package/src/helper-reference.ts +130 -0
- package/src/hosted-extension-runtime.ts +1 -1
- package/src/index.ts +2 -0
- package/src/journal-client.ts +19 -2
- package/src/journal-projection.ts +106 -0
- package/src/llm-worker.ts +1 -1
- package/src/local-agent.ts +4 -2
- package/src/named-gate-lowering.ts +35 -5
- package/src/named-gate-preflight.ts +47 -0
- package/src/named-gates.ts +3 -0
- package/src/observer-link.ts +10 -1
- package/src/package-version.ts +23 -0
- package/src/preflight.ts +38 -7
- package/src/protocol.ts +2 -0
- package/src/redact.ts +111 -0
- package/src/relay-cli.ts +1 -24
- package/src/run-projection.ts +247 -0
- package/src/shell-word.ts +24 -0
- package/src/spec.ts +54 -3
- package/src/step-fields.ts +1 -1
- package/src/steps-green.ts +168 -0
- package/src/validate.ts +35 -8
- package/src/worker-lease.ts +35 -5
- package/src/worker.ts +27 -11
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// The Cloud half of `flows run` / `flows resume`: also put this local run on
|
|
2
|
+
// the Cloud dashboard.
|
|
3
|
+
//
|
|
4
|
+
// Opt-in, and deliberately the only opt-in thing on this path.
|
|
5
|
+
//
|
|
6
|
+
// A local run is already watchable by default: `observer-session.ts` beside
|
|
7
|
+
// this one projects the run into its own channel and prints a read-only link,
|
|
8
|
+
// off a workspace key, for free. That is the right default — it is a step
|
|
9
|
+
// projection, it costs nothing, and a run that never joins a workspace is not
|
|
10
|
+
// a defect (RFC-0001 settled decision 7).
|
|
11
|
+
//
|
|
12
|
+
// The dashboard is the richer, hosted view of the same run: the flow source,
|
|
13
|
+
// every step's transcript, the run graph, the logs, and the run sitting in the
|
|
14
|
+
// same history as the hosted ones. It is also the one that *stores* all of
|
|
15
|
+
// that. So it is asked for — `--cloud-mirror`, or `FLOWS_CLOUD_MIRROR=1` for a
|
|
16
|
+
// shell — and never turned on by a login happening to be present. Mirroring
|
|
17
|
+
// someone's local runs because they once signed in is not a default anyone
|
|
18
|
+
// consented to.
|
|
19
|
+
//
|
|
20
|
+
// Best-effort once it is on, like the observer: a registration failure is one
|
|
21
|
+
// labeled stderr line, and nothing here can change a run's exit code or its
|
|
22
|
+
// journal. But it is a *louder* line than it used to be, because the run asked
|
|
23
|
+
// for this and did not get it.
|
|
24
|
+
|
|
25
|
+
import { readFile } from 'node:fs/promises';
|
|
26
|
+
import type { CliIo } from '../cli.js';
|
|
27
|
+
import { canonicalize } from '../canonical.js';
|
|
28
|
+
import { cloudConnection, CloudFlowError } from '../cloud-http.js';
|
|
29
|
+
import { recordMirroredRun, readMirroredRun } from '../cloud-mirror-ledger.js';
|
|
30
|
+
import { createRunMirror, readJournalEvents, type RunMirror } from '../cloud-mirror.js';
|
|
31
|
+
import { MirrorClient, registerLocalRun, type MirrorRunSource } from '../cloud-mirror-transport.js';
|
|
32
|
+
import { parseDigestReference } from '../bundle-transport.js';
|
|
33
|
+
import { isAuthoredFlowPath, parseDirectInput } from '../direct-input.js';
|
|
34
|
+
import type { ProgressEvent } from '../progress.js';
|
|
35
|
+
import type { RunReport } from './run.js';
|
|
36
|
+
|
|
37
|
+
/** `FLOWS_CLOUD_MIRROR=1|true|on` turns the mirror on for a whole shell. */
|
|
38
|
+
export const MIRROR_ENV = 'FLOWS_CLOUD_MIRROR';
|
|
39
|
+
|
|
40
|
+
/** What the mirror knows about this run on Cloud, once it is registered. */
|
|
41
|
+
export interface CloudMirrorReceipt {
|
|
42
|
+
/** Cloud's run id — the argument `flows status --cloud` and `flows logs` take. */
|
|
43
|
+
cloudRunId: string;
|
|
44
|
+
dashboardUrl: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface CloudMirrorSession {
|
|
48
|
+
/** The root run is admitted: the mirror can start reading its journal. */
|
|
49
|
+
onRunStarted(run: { runId: string }): void;
|
|
50
|
+
/**
|
|
51
|
+
* The registration, once it lands. Resolves to nothing when the mirror is
|
|
52
|
+
* off, was refused, or the run never started.
|
|
53
|
+
*
|
|
54
|
+
* Awaiting it is what lets `--json` carry the same handle the terminal line
|
|
55
|
+
* carries: registration is one request made when the run is admitted, so by
|
|
56
|
+
* the time a run has a report it has long since settled — and a consumer of
|
|
57
|
+
* a machine-readable report can wait for a request that has already
|
|
58
|
+
* happened.
|
|
59
|
+
*/
|
|
60
|
+
receipt(): Promise<CloudMirrorReceipt | undefined>;
|
|
61
|
+
/** A journaled entry; the first one names the run for a declarative flow. */
|
|
62
|
+
onJournalEntry(entry: { run_id: string }): void;
|
|
63
|
+
/** Step transitions, pushed as lifecycle events the run page's stream shows. */
|
|
64
|
+
onProgress(event: ProgressEvent): void;
|
|
65
|
+
/** Publish the final report and the terminal status. Never rejects. */
|
|
66
|
+
finish(report: RunReport): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface CloudMirrorDeps {
|
|
70
|
+
register?: typeof registerLocalRun;
|
|
71
|
+
createMirror?: typeof createRunMirror;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface CloudMirrorRequest {
|
|
75
|
+
/**
|
|
76
|
+
* The flow's source and input, exactly as `flows run --cloud` would send
|
|
77
|
+
* them. Resolved lazily, once the run id exists: a `resume` has no flow
|
|
78
|
+
* path at all and has to read what ran out of the journal.
|
|
79
|
+
*/
|
|
80
|
+
source: (runId: string) => Promise<MirrorRunSource>;
|
|
81
|
+
dataDir: string;
|
|
82
|
+
/** Lines the CLI has printed for this run, uploaded as the run's `runner.log`. */
|
|
83
|
+
log: () => readonly string[];
|
|
84
|
+
/** How the dashboard was asked for, so a refusal can name the right switch. */
|
|
85
|
+
requested: 'flag' | 'env';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Whether this shell asked for the dashboard.
|
|
90
|
+
*
|
|
91
|
+
* Only an affirmative turns it on. Anything else — unset, empty, `0`, or a
|
|
92
|
+
* value nobody meant as a switch — leaves the run local, because the cost of
|
|
93
|
+
* reading a stray value as consent is someone's runs being uploaded.
|
|
94
|
+
*/
|
|
95
|
+
export function cloudMirrorRequested(env: NodeJS.ProcessEnv): boolean {
|
|
96
|
+
const value = env[MIRROR_ENV]?.trim().toLowerCase();
|
|
97
|
+
return value === '1' || value === 'true' || value === 'on' || value === 'yes';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Open the session. Registration is deferred until the run id exists, so a
|
|
102
|
+
* refused flow never reaches Cloud at all: `flows run` on a spec that does not
|
|
103
|
+
* compile creates no dashboard row, the same as today.
|
|
104
|
+
*/
|
|
105
|
+
export function createCloudMirrorSession(
|
|
106
|
+
request: CloudMirrorRequest,
|
|
107
|
+
io: CliIo,
|
|
108
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
109
|
+
deps: CloudMirrorDeps = {},
|
|
110
|
+
): CloudMirrorSession {
|
|
111
|
+
const register = deps.register ?? registerLocalRun;
|
|
112
|
+
const createMirror = deps.createMirror ?? createRunMirror;
|
|
113
|
+
let opening: Promise<RunMirror | undefined> | undefined;
|
|
114
|
+
let receipt: CloudMirrorReceipt | undefined;
|
|
115
|
+
|
|
116
|
+
const open = (runId: string): Promise<RunMirror | undefined> => opening ??= request.source(runId)
|
|
117
|
+
.then(register)
|
|
118
|
+
.then(registration => {
|
|
119
|
+
const mirror = createMirror({
|
|
120
|
+
client: new MirrorClient(registration),
|
|
121
|
+
dataDir: request.dataDir,
|
|
122
|
+
env,
|
|
123
|
+
diagnostic: message => io.stderr(`[cloud] ${message}`),
|
|
124
|
+
});
|
|
125
|
+
receipt = { cloudRunId: registration.runId, dashboardUrl: registration.runUrl };
|
|
126
|
+
// So a later `flows resume` of this same journal can name this attempt
|
|
127
|
+
// as its predecessor. The credential is deliberately not written; a
|
|
128
|
+
// resume mints its own.
|
|
129
|
+
void recordMirroredRun(request.dataDir, runId, {
|
|
130
|
+
cloudRunId: registration.runId, apiUrl: registration.apiUrl,
|
|
131
|
+
});
|
|
132
|
+
// The page, and the command that follows the same run from a terminal.
|
|
133
|
+
// The id is Cloud's, not the journal's, and nothing else in this
|
|
134
|
+
// invocation prints it — without it a reader has to pick it out of the
|
|
135
|
+
// URL to use any of the hosted read verbs.
|
|
136
|
+
io.stderr(`Dashboard: ${mirror.runUrl} · flows status --cloud --watch ${registration.runId}`);
|
|
137
|
+
mirror.start(runId);
|
|
138
|
+
return mirror;
|
|
139
|
+
})
|
|
140
|
+
.catch((error: unknown) => {
|
|
141
|
+
io.stderr(`[cloud] ${mirrorRefusal(error, request.requested)}`);
|
|
142
|
+
return undefined;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
onRunStarted(run) {
|
|
147
|
+
void open(run.runId);
|
|
148
|
+
},
|
|
149
|
+
onJournalEntry(entry) {
|
|
150
|
+
void open(entry.run_id);
|
|
151
|
+
},
|
|
152
|
+
async receipt() {
|
|
153
|
+
if (opening === undefined) return undefined;
|
|
154
|
+
await opening;
|
|
155
|
+
return receipt;
|
|
156
|
+
},
|
|
157
|
+
onProgress(event) {
|
|
158
|
+
// Fire-and-forget, and only for transitions: a `step.running` tick
|
|
159
|
+
// arrives every second and would say nothing the snapshot does not.
|
|
160
|
+
if (opening === undefined) return;
|
|
161
|
+
if (event.type !== 'step.started' && event.type !== 'step.completed') return;
|
|
162
|
+
void opening.then(mirror => mirror?.event({
|
|
163
|
+
eventType: `relayflow.${event.type}`,
|
|
164
|
+
stepName: event.stepId,
|
|
165
|
+
payload: { stepType: event.stepType },
|
|
166
|
+
}));
|
|
167
|
+
},
|
|
168
|
+
async finish(report) {
|
|
169
|
+
const mirror = opening === undefined ? undefined : await opening;
|
|
170
|
+
if (mirror === undefined) return;
|
|
171
|
+
await mirror.finish({
|
|
172
|
+
status: report.completionReason === 'canceled'
|
|
173
|
+
? 'cancelled'
|
|
174
|
+
: report.ok ? 'completed' : 'failed',
|
|
175
|
+
result: completionReport(report),
|
|
176
|
+
...(report.completionReason === undefined ? {} : { completionReason: report.completionReason }),
|
|
177
|
+
...(terminalError(report) === undefined ? {} : { error: terminalError(report)! }),
|
|
178
|
+
log: request.log(),
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* What `flows run` mirrors: the flow file's exact bytes, and — for an authored
|
|
186
|
+
* flow — the input it was invoked with.
|
|
187
|
+
*
|
|
188
|
+
* The same source `flows run --cloud` would submit, so a run mirrored from a
|
|
189
|
+
* terminal and the same run launched hosted are recorded identically. It is
|
|
190
|
+
* read here rather than taken from the compiled spec because the compiled
|
|
191
|
+
* form is not what the author wrote, and the run page shows source.
|
|
192
|
+
*/
|
|
193
|
+
export function mirrorSourceFromPath(
|
|
194
|
+
path: string,
|
|
195
|
+
inputArgument: string | undefined,
|
|
196
|
+
dataDir: string,
|
|
197
|
+
): (runId: string) => Promise<MirrorRunSource> {
|
|
198
|
+
const fromJournal = mirrorSourceFromJournal(dataDir);
|
|
199
|
+
return async (runId) => {
|
|
200
|
+
// `flows run <flow>@sha256:<digest>` names a bundle, not a file on this
|
|
201
|
+
// disk: the runner fetches it before executing. Reading the argument as a
|
|
202
|
+
// path there refused the registration and left a perfectly good run off
|
|
203
|
+
// the dashboard, so fall back to what the journal recorded — the same
|
|
204
|
+
// source a resume mirrors.
|
|
205
|
+
if (parseDigestReference(path)) return fromJournal(runId);
|
|
206
|
+
const workflow = await readFile(path, 'utf8');
|
|
207
|
+
if (!isAuthoredFlowPath(path)) return { workflow, fileType: 'yaml' };
|
|
208
|
+
return { workflow, fileType: 'ts', inputs: parseDirectInput(inputArgument) };
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* What `flows resume` mirrors: the kernel spec the journal recorded at
|
|
214
|
+
* `run.spawned`, canonicalized.
|
|
215
|
+
*
|
|
216
|
+
* A resume names a run id, not a file — the flow it continues may have been
|
|
217
|
+
* edited or deleted since. The journal is the record of what actually ran, so
|
|
218
|
+
* that is what the mirror publishes, as canonical JSON (a YAML subset, the
|
|
219
|
+
* same representation `runInCloud` sends for a declarative flow).
|
|
220
|
+
*
|
|
221
|
+
* Each resume registers its own Cloud run, and that is deliberate rather than
|
|
222
|
+
* a shortcut: a mirrored run goes terminal on Cloud when the CLI exits, and
|
|
223
|
+
* Cloud refuses to move a terminal run back to `running`. Cloud's own v2
|
|
224
|
+
* resume is likewise a new attempt row, so one dashboard row per invocation is
|
|
225
|
+
* the shape the control plane already has — and it costs no credential stored
|
|
226
|
+
* on disk between invocations.
|
|
227
|
+
*/
|
|
228
|
+
export function mirrorSourceFromJournal(dataDir: string): (runId: string) => Promise<MirrorRunSource> {
|
|
229
|
+
return async (runId) => {
|
|
230
|
+
// The predecessor, if this journal has been mirrored before. Read against
|
|
231
|
+
// the deployment this invocation will actually register with, so a run
|
|
232
|
+
// mirrored to staging never claims to continue an id that means something
|
|
233
|
+
// else in production.
|
|
234
|
+
const resumedFromRunId = await readMirroredRun(dataDir, runId, cloudConnection({}).baseUrl)
|
|
235
|
+
.catch(() => undefined);
|
|
236
|
+
// Through the retrying reader: a resume reads this journal while the
|
|
237
|
+
// daemon is writing to it, and a single `journal_busy` used to abandon
|
|
238
|
+
// the registration and leave the resumed run off the dashboard entirely.
|
|
239
|
+
for (const event of await readJournalEvents(runId, dataDir)) {
|
|
240
|
+
if (event.entry_type !== 'run.spawned') continue;
|
|
241
|
+
const payload = event.payload as { spec?: unknown } | null;
|
|
242
|
+
if (payload?.spec === undefined) break;
|
|
243
|
+
return {
|
|
244
|
+
workflow: canonicalize(payload.spec),
|
|
245
|
+
fileType: 'yaml',
|
|
246
|
+
...(resumedFromRunId === undefined ? {} : { resumedFromRunId }),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
throw new CloudFlowError('invalid_input',
|
|
250
|
+
`Run "${runId}" journals no spec to mirror; the run is unaffected.`);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Diagnostics one completion report carries; the rest are counted. */
|
|
255
|
+
const MAX_REPORT_DIAGNOSTICS = 20;
|
|
256
|
+
/** One diagnostic message, in code points. */
|
|
257
|
+
const MAX_DIAGNOSTIC_CHARS = 2_000;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The run's completion report, as the terminal callback stores it.
|
|
261
|
+
*
|
|
262
|
+
* Cloud reconciles a v2 run's reported status against this document: a
|
|
263
|
+
* `completed` callback whose report does not carry `ok`, `status`,
|
|
264
|
+
* `completionReason` and `runId` together is recorded as `failed`. That guard
|
|
265
|
+
* exists so a sandbox whose bootstrap exits cleanly cannot report a run that
|
|
266
|
+
* died at step 1 as green — and it cuts the other way too, so a mirror that
|
|
267
|
+
* omits the report turns a finished local run red. Those four fields are the
|
|
268
|
+
* contract; everything else here is what a reader of the run page gets for
|
|
269
|
+
* free, since the run list extracts `completionReason` from the same document.
|
|
270
|
+
*
|
|
271
|
+
* Diagnostics are bounded and their messages clipped. They are the one part of
|
|
272
|
+
* a report that is unbounded free text, and this document is stored whole.
|
|
273
|
+
*/
|
|
274
|
+
function completionReport(report: RunReport): Record<string, unknown> {
|
|
275
|
+
const diagnostics = report.diagnostics.slice(0, MAX_REPORT_DIAGNOSTICS).map(entry => ({
|
|
276
|
+
severity: 'severity' in entry ? entry.severity : 'refusal',
|
|
277
|
+
kind: entry.kind,
|
|
278
|
+
message: [...entry.message].slice(0, MAX_DIAGNOSTIC_CHARS).join(''),
|
|
279
|
+
}));
|
|
280
|
+
return {
|
|
281
|
+
ok: report.ok,
|
|
282
|
+
command: report.command,
|
|
283
|
+
...(report.runId === undefined ? {} : { runId: report.runId }),
|
|
284
|
+
...(report.rootRunId === undefined ? {} : { rootRunId: report.rootRunId }),
|
|
285
|
+
...(report.status === undefined ? {} : { status: report.status }),
|
|
286
|
+
...(report.completionReason === undefined ? {} : { completionReason: report.completionReason }),
|
|
287
|
+
...(report.completionDetail === undefined ? {} : { completionDetail: report.completionDetail }),
|
|
288
|
+
...(report.completedSteps === undefined ? {} : { completedSteps: report.completedSteps }),
|
|
289
|
+
...(report.parkedStep === undefined ? {} : { parkedStep: report.parkedStep }),
|
|
290
|
+
...(report.parkCause === undefined ? {} : { parkCause: report.parkCause }),
|
|
291
|
+
...(report.next === undefined ? {} : { next: report.next }),
|
|
292
|
+
...(diagnostics.length === 0 ? {} : { diagnostics }),
|
|
293
|
+
...(report.diagnostics.length > diagnostics.length
|
|
294
|
+
? { diagnosticsOmitted: report.diagnostics.length - diagnostics.length }
|
|
295
|
+
: {}),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Why the dashboard is not getting this run, in one line a reader can act on.
|
|
301
|
+
*
|
|
302
|
+
* Every one of these is a request that was not honoured — the run asked for
|
|
303
|
+
* the dashboard and is not on it — so none of them read as an aside. The
|
|
304
|
+
* missing-login case is the common one and names the two commands that fix
|
|
305
|
+
* it: sign in, or stop asking.
|
|
306
|
+
*/
|
|
307
|
+
function mirrorRefusal(error: unknown, requested: 'flag' | 'env'): string {
|
|
308
|
+
const asked = requested === 'flag' ? '--cloud-mirror' : `${MIRROR_ENV}=1`;
|
|
309
|
+
if (error instanceof CloudFlowError && error.code === 'configuration') {
|
|
310
|
+
return error.reason === 'auth_missing'
|
|
311
|
+
? `${asked} asked for the Cloud dashboard, but there is no Cloud login, so this run stays local. `
|
|
312
|
+
+ `Sign in with \`agent-relay cloud login\`, or drop ${asked}.`
|
|
313
|
+
: `${asked} asked for the Cloud dashboard, but this run stays local: ${error.message}`;
|
|
314
|
+
}
|
|
315
|
+
if (error instanceof CloudFlowError && error.status === 404) {
|
|
316
|
+
return `${asked} asked for the Cloud dashboard, but this deployment does not accept local runs; `
|
|
317
|
+
+ 'the run itself is unaffected.';
|
|
318
|
+
}
|
|
319
|
+
return `${asked} asked for the Cloud dashboard, but this run could not be registered (${
|
|
320
|
+
error instanceof Error ? error.message : String(error)}); the run itself is unaffected.`;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** The run's own failure text, bounded by the mirror's transport, or nothing. */
|
|
324
|
+
function terminalError(report: RunReport): string | undefined {
|
|
325
|
+
if (report.ok) return undefined;
|
|
326
|
+
const diagnostic = report.diagnostics.find(entry =>
|
|
327
|
+
'severity' in entry && (entry.severity === 'failure' || entry.severity === 'refusal'));
|
|
328
|
+
return diagnostic?.message;
|
|
329
|
+
}
|