@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.
Files changed (347) hide show
  1. package/dist/agent-artifacts.d.ts.map +1 -1
  2. package/dist/agent-artifacts.js +2 -9
  3. package/dist/agent-artifacts.js.map +1 -1
  4. package/dist/agent-cwd.d.ts +69 -0
  5. package/dist/agent-cwd.d.ts.map +1 -0
  6. package/dist/agent-cwd.js +140 -0
  7. package/dist/agent-cwd.js.map +1 -0
  8. package/dist/artifact-scan-policy.d.ts +35 -0
  9. package/dist/artifact-scan-policy.d.ts.map +1 -0
  10. package/dist/artifact-scan-policy.js +49 -0
  11. package/dist/artifact-scan-policy.js.map +1 -0
  12. package/dist/authored-completion-record.d.ts +35 -0
  13. package/dist/authored-completion-record.d.ts.map +1 -0
  14. package/dist/authored-completion-record.js +92 -0
  15. package/dist/authored-completion-record.js.map +1 -0
  16. package/dist/authored-completion.d.ts +99 -0
  17. package/dist/authored-completion.d.ts.map +1 -0
  18. package/dist/authored-completion.js +184 -0
  19. package/dist/authored-completion.js.map +1 -0
  20. package/dist/authored-flow-error.d.ts +13 -1
  21. package/dist/authored-flow-error.d.ts.map +1 -1
  22. package/dist/authored-flow-error.js +12 -0
  23. package/dist/authored-flow-error.js.map +1 -1
  24. package/dist/authored-flow-executor.d.ts +7 -30
  25. package/dist/authored-flow-executor.d.ts.map +1 -1
  26. package/dist/authored-flow-executor.js +54 -47
  27. package/dist/authored-flow-executor.js.map +1 -1
  28. package/dist/authored-human.d.ts.map +1 -1
  29. package/dist/authored-human.js +1 -3
  30. package/dist/authored-human.js.map +1 -1
  31. package/dist/authored-node-entry.js +4 -1
  32. package/dist/authored-node-entry.js.map +1 -1
  33. package/dist/authored-node-runner.d.ts +9 -1
  34. package/dist/authored-node-runner.d.ts.map +1 -1
  35. package/dist/authored-node-runner.js +92 -17
  36. package/dist/authored-node-runner.js.map +1 -1
  37. package/dist/authored-preflight.d.ts +4 -0
  38. package/dist/authored-preflight.d.ts.map +1 -0
  39. package/dist/authored-preflight.js +50 -0
  40. package/dist/authored-preflight.js.map +1 -0
  41. package/dist/authored-root.d.ts +5 -0
  42. package/dist/authored-root.d.ts.map +1 -1
  43. package/dist/authored-root.js +20 -2
  44. package/dist/authored-root.js.map +1 -1
  45. package/dist/authored-step-output.d.ts +35 -10
  46. package/dist/authored-step-output.d.ts.map +1 -1
  47. package/dist/authored-step-output.js +108 -40
  48. package/dist/authored-step-output.js.map +1 -1
  49. package/dist/authored-verdict.d.ts +28 -0
  50. package/dist/authored-verdict.d.ts.map +1 -0
  51. package/dist/authored-verdict.js +79 -0
  52. package/dist/authored-verdict.js.map +1 -0
  53. package/dist/authored-worker-step.d.ts +5 -2
  54. package/dist/authored-worker-step.d.ts.map +1 -1
  55. package/dist/authored-worker-step.js +51 -13
  56. package/dist/authored-worker-step.js.map +1 -1
  57. package/dist/cli/check-worker-surface.d.ts +27 -0
  58. package/dist/cli/check-worker-surface.d.ts.map +1 -0
  59. package/dist/cli/check-worker-surface.js +63 -0
  60. package/dist/cli/check-worker-surface.js.map +1 -0
  61. package/dist/cli/check.d.ts +28 -3
  62. package/dist/cli/check.d.ts.map +1 -1
  63. package/dist/cli/check.js +27 -140
  64. package/dist/cli/check.js.map +1 -1
  65. package/dist/cli/cli-probe.d.ts +20 -0
  66. package/dist/cli/cli-probe.d.ts.map +1 -0
  67. package/dist/cli/cli-probe.js +166 -0
  68. package/dist/cli/cli-probe.js.map +1 -0
  69. package/dist/cli/cloud-format.d.ts +9 -0
  70. package/dist/cli/cloud-format.d.ts.map +1 -0
  71. package/dist/cli/cloud-format.js +77 -0
  72. package/dist/cli/cloud-format.js.map +1 -0
  73. package/dist/cli/cloud-live.d.ts +39 -0
  74. package/dist/cli/cloud-live.d.ts.map +1 -0
  75. package/dist/cli/cloud-live.js +325 -0
  76. package/dist/cli/cloud-live.js.map +1 -0
  77. package/dist/cli/cloud-mirror-session.d.ts +97 -0
  78. package/dist/cli/cloud-mirror-session.d.ts.map +1 -0
  79. package/dist/cli/cloud-mirror-session.js +264 -0
  80. package/dist/cli/cloud-mirror-session.js.map +1 -0
  81. package/dist/cli/cloud-read.d.ts +3 -7
  82. package/dist/cli/cloud-read.d.ts.map +1 -1
  83. package/dist/cli/cloud-read.js +14 -266
  84. package/dist/cli/cloud-read.js.map +1 -1
  85. package/dist/cli/cloud-refusal.d.ts +39 -0
  86. package/dist/cli/cloud-refusal.d.ts.map +1 -0
  87. package/dist/cli/cloud-refusal.js +95 -0
  88. package/dist/cli/cloud-refusal.js.map +1 -0
  89. package/dist/cli/cloud-status-view.d.ts +7 -0
  90. package/dist/cli/cloud-status-view.d.ts.map +1 -0
  91. package/dist/cli/cloud-status-view.js +214 -0
  92. package/dist/cli/cloud-status-view.js.map +1 -0
  93. package/dist/cli/direct-run.d.ts.map +1 -1
  94. package/dist/cli/direct-run.js +16 -2
  95. package/dist/cli/direct-run.js.map +1 -1
  96. package/dist/cli/hn-monitor.d.ts +0 -13
  97. package/dist/cli/hn-monitor.d.ts.map +1 -1
  98. package/dist/cli/hn-monitor.js +2 -1
  99. package/dist/cli/hn-monitor.js.map +1 -1
  100. package/dist/cli/local-agent-remedy.d.ts +80 -0
  101. package/dist/cli/local-agent-remedy.d.ts.map +1 -0
  102. package/dist/cli/local-agent-remedy.js +116 -0
  103. package/dist/cli/local-agent-remedy.js.map +1 -0
  104. package/dist/cli/observer-session.d.ts +41 -0
  105. package/dist/cli/observer-session.d.ts.map +1 -0
  106. package/dist/cli/observer-session.js +78 -0
  107. package/dist/cli/observer-session.js.map +1 -0
  108. package/dist/cli/run.d.ts +30 -2
  109. package/dist/cli/run.d.ts.map +1 -1
  110. package/dist/cli/run.js +186 -24
  111. package/dist/cli/run.js.map +1 -1
  112. package/dist/cli/status.d.ts +9 -0
  113. package/dist/cli/status.d.ts.map +1 -1
  114. package/dist/cli/status.js +31 -2
  115. package/dist/cli/status.js.map +1 -1
  116. package/dist/cli/step-evidence.d.ts +90 -0
  117. package/dist/cli/step-evidence.d.ts.map +1 -0
  118. package/dist/cli/step-evidence.js +259 -0
  119. package/dist/cli/step-evidence.js.map +1 -0
  120. package/dist/cli/step-failure.d.ts +14 -4
  121. package/dist/cli/step-failure.d.ts.map +1 -1
  122. package/dist/cli/step-failure.js +41 -76
  123. package/dist/cli/step-failure.js.map +1 -1
  124. package/dist/cli-commands.d.ts +12 -0
  125. package/dist/cli-commands.d.ts.map +1 -1
  126. package/dist/cli-commands.js +3 -0
  127. package/dist/cli-commands.js.map +1 -1
  128. package/dist/cli.d.ts +17 -0
  129. package/dist/cli.d.ts.map +1 -1
  130. package/dist/cli.js +134 -57
  131. package/dist/cli.js.map +1 -1
  132. package/dist/cloud-deploy.d.ts +1 -1
  133. package/dist/cloud-deploy.d.ts.map +1 -1
  134. package/dist/cloud-deploy.js +24 -8
  135. package/dist/cloud-deploy.js.map +1 -1
  136. package/dist/cloud-mirror-ledger.d.ts +40 -0
  137. package/dist/cloud-mirror-ledger.d.ts.map +1 -0
  138. package/dist/cloud-mirror-ledger.js +142 -0
  139. package/dist/cloud-mirror-ledger.js.map +1 -0
  140. package/dist/cloud-mirror-step.d.ts +168 -0
  141. package/dist/cloud-mirror-step.d.ts.map +1 -0
  142. package/dist/cloud-mirror-step.js +504 -0
  143. package/dist/cloud-mirror-step.js.map +1 -0
  144. package/dist/cloud-mirror-transport.d.ts +94 -0
  145. package/dist/cloud-mirror-transport.d.ts.map +1 -0
  146. package/dist/cloud-mirror-transport.js +163 -0
  147. package/dist/cloud-mirror-transport.js.map +1 -0
  148. package/dist/cloud-mirror.d.ts +132 -0
  149. package/dist/cloud-mirror.d.ts.map +1 -0
  150. package/dist/cloud-mirror.js +556 -0
  151. package/dist/cloud-mirror.js.map +1 -0
  152. package/dist/cloud-read.d.ts +15 -0
  153. package/dist/cloud-read.d.ts.map +1 -1
  154. package/dist/cloud-read.js +20 -1
  155. package/dist/cloud-read.js.map +1 -1
  156. package/dist/cloud-run-record.d.ts +27 -0
  157. package/dist/cloud-run-record.d.ts.map +1 -0
  158. package/dist/cloud-run-record.js +56 -0
  159. package/dist/cloud-run-record.js.map +1 -0
  160. package/dist/cloud-run.d.ts +2 -9
  161. package/dist/cloud-run.d.ts.map +1 -1
  162. package/dist/cloud-run.js +3 -20
  163. package/dist/cloud-run.js.map +1 -1
  164. package/dist/communication/local.d.ts.map +1 -1
  165. package/dist/communication/local.js +2 -1
  166. package/dist/communication/local.js.map +1 -1
  167. package/dist/communication/worker.d.ts +1 -1
  168. package/dist/communication/worker.d.ts.map +1 -1
  169. package/dist/communication/worker.js +13 -5
  170. package/dist/communication/worker.js.map +1 -1
  171. package/dist/compile.d.ts.map +1 -1
  172. package/dist/compile.js +28 -6
  173. package/dist/compile.js.map +1 -1
  174. package/dist/direct-input.d.ts.map +1 -1
  175. package/dist/direct-input.js +21 -1
  176. package/dist/direct-input.js.map +1 -1
  177. package/dist/failure-kinds.d.ts +96 -6
  178. package/dist/failure-kinds.d.ts.map +1 -1
  179. package/dist/failure-kinds.js +29 -2
  180. package/dist/failure-kinds.js.map +1 -1
  181. package/dist/flow-requirements.d.ts.map +1 -1
  182. package/dist/flow-requirements.js +24 -9
  183. package/dist/flow-requirements.js.map +1 -1
  184. package/dist/gate-contract.d.ts +7 -0
  185. package/dist/gate-contract.d.ts.map +1 -1
  186. package/dist/gate-contract.js +6 -1
  187. package/dist/gate-contract.js.map +1 -1
  188. package/dist/helper-preflight.d.ts.map +1 -1
  189. package/dist/helper-preflight.js +10 -3
  190. package/dist/helper-preflight.js.map +1 -1
  191. package/dist/helper-reference.d.ts +25 -0
  192. package/dist/helper-reference.d.ts.map +1 -0
  193. package/dist/helper-reference.js +129 -0
  194. package/dist/helper-reference.js.map +1 -0
  195. package/dist/hosted-extension-runtime.js +1 -1
  196. package/dist/index.d.ts +1 -1
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js.map +1 -1
  199. package/dist/journal-client.d.ts +3 -1
  200. package/dist/journal-client.d.ts.map +1 -1
  201. package/dist/journal-client.js +17 -2
  202. package/dist/journal-client.js.map +1 -1
  203. package/dist/journal-projection.d.ts +16 -0
  204. package/dist/journal-projection.d.ts.map +1 -0
  205. package/dist/journal-projection.js +108 -0
  206. package/dist/journal-projection.js.map +1 -0
  207. package/dist/llm-worker.js +1 -1
  208. package/dist/llm-worker.js.map +1 -1
  209. package/dist/local-agent.d.ts +1 -1
  210. package/dist/local-agent.d.ts.map +1 -1
  211. package/dist/local-agent.js +4 -3
  212. package/dist/local-agent.js.map +1 -1
  213. package/dist/named-gate-lowering.js +35 -5
  214. package/dist/named-gate-lowering.js.map +1 -1
  215. package/dist/named-gate-preflight.d.ts +27 -0
  216. package/dist/named-gate-preflight.d.ts.map +1 -0
  217. package/dist/named-gate-preflight.js +47 -0
  218. package/dist/named-gate-preflight.js.map +1 -0
  219. package/dist/named-gates.d.ts +1 -1
  220. package/dist/named-gates.d.ts.map +1 -1
  221. package/dist/named-gates.js +3 -0
  222. package/dist/named-gates.js.map +1 -1
  223. package/dist/observer-link.d.ts +7 -0
  224. package/dist/observer-link.d.ts.map +1 -1
  225. package/dist/observer-link.js +3 -1
  226. package/dist/observer-link.js.map +1 -1
  227. package/dist/package-version.d.ts +10 -0
  228. package/dist/package-version.d.ts.map +1 -0
  229. package/dist/package-version.js +22 -0
  230. package/dist/package-version.js.map +1 -0
  231. package/dist/preflight.d.ts +14 -0
  232. package/dist/preflight.d.ts.map +1 -1
  233. package/dist/preflight.js +25 -3
  234. package/dist/preflight.js.map +1 -1
  235. package/dist/protocol.d.ts +2 -0
  236. package/dist/protocol.d.ts.map +1 -1
  237. package/dist/redact.d.ts +42 -0
  238. package/dist/redact.d.ts.map +1 -1
  239. package/dist/redact.js +128 -0
  240. package/dist/redact.js.map +1 -1
  241. package/dist/relay-cli.d.ts.map +1 -1
  242. package/dist/relay-cli.js +1 -21
  243. package/dist/relay-cli.js.map +1 -1
  244. package/dist/run-projection.d.ts +83 -0
  245. package/dist/run-projection.d.ts.map +1 -0
  246. package/dist/run-projection.js +199 -0
  247. package/dist/run-projection.js.map +1 -0
  248. package/dist/shell-word.d.ts +19 -0
  249. package/dist/shell-word.d.ts.map +1 -0
  250. package/dist/shell-word.js +23 -0
  251. package/dist/shell-word.js.map +1 -0
  252. package/dist/spec.d.ts +52 -3
  253. package/dist/spec.d.ts.map +1 -1
  254. package/dist/spec.js.map +1 -1
  255. package/dist/step-fields.d.ts +1 -1
  256. package/dist/step-fields.js +1 -1
  257. package/dist/step-fields.js.map +1 -1
  258. package/dist/steps-green.d.ts +27 -0
  259. package/dist/steps-green.d.ts.map +1 -0
  260. package/dist/steps-green.js +164 -0
  261. package/dist/steps-green.js.map +1 -0
  262. package/dist/validate.d.ts.map +1 -1
  263. package/dist/validate.js +39 -8
  264. package/dist/validate.js.map +1 -1
  265. package/dist/worker-lease.d.ts +8 -1
  266. package/dist/worker-lease.d.ts.map +1 -1
  267. package/dist/worker-lease.js +34 -4
  268. package/dist/worker-lease.js.map +1 -1
  269. package/dist/worker.d.ts +8 -0
  270. package/dist/worker.d.ts.map +1 -1
  271. package/dist/worker.js +17 -9
  272. package/dist/worker.js.map +1 -1
  273. package/package.json +3 -7
  274. package/src/agent-artifacts.ts +2 -10
  275. package/src/agent-cwd.ts +139 -0
  276. package/src/artifact-scan-policy.ts +51 -0
  277. package/src/authored-completion-record.ts +119 -0
  278. package/src/authored-completion.ts +203 -0
  279. package/src/authored-flow-error.ts +13 -1
  280. package/src/authored-flow-executor.ts +91 -58
  281. package/src/authored-human.ts +1 -4
  282. package/src/authored-node-entry.ts +4 -1
  283. package/src/authored-node-runner.ts +96 -22
  284. package/src/authored-preflight.ts +46 -0
  285. package/src/authored-root.ts +20 -2
  286. package/src/authored-step-output.ts +139 -42
  287. package/src/authored-verdict.ts +87 -0
  288. package/src/authored-worker-step.ts +63 -14
  289. package/src/cli/check-worker-surface.ts +66 -0
  290. package/src/cli/check.ts +59 -166
  291. package/src/cli/cli-probe.ts +194 -0
  292. package/src/cli/cloud-format.ts +82 -0
  293. package/src/cli/cloud-live.ts +366 -0
  294. package/src/cli/cloud-mirror-session.ts +329 -0
  295. package/src/cli/cloud-read.ts +13 -282
  296. package/src/cli/cloud-refusal.ts +113 -0
  297. package/src/cli/cloud-status-view.ts +213 -0
  298. package/src/cli/direct-run.ts +19 -2
  299. package/src/cli/hn-monitor.ts +2 -1
  300. package/src/cli/local-agent-remedy.ts +160 -0
  301. package/src/cli/observer-session.ts +107 -0
  302. package/src/cli/run.ts +233 -28
  303. package/src/cli/status.ts +59 -3
  304. package/src/cli/step-evidence.ts +310 -0
  305. package/src/cli/step-failure.ts +57 -81
  306. package/src/cli-commands.ts +3 -0
  307. package/src/cli.ts +155 -60
  308. package/src/cloud-deploy.ts +26 -8
  309. package/src/cloud-mirror-ledger.ts +161 -0
  310. package/src/cloud-mirror-step.ts +618 -0
  311. package/src/cloud-mirror-transport.ts +261 -0
  312. package/src/cloud-mirror.ts +633 -0
  313. package/src/cloud-read.ts +25 -1
  314. package/src/cloud-run-record.ts +64 -0
  315. package/src/cloud-run.ts +5 -24
  316. package/src/communication/local.ts +2 -1
  317. package/src/communication/worker.ts +13 -5
  318. package/src/compile.ts +28 -6
  319. package/src/direct-input.ts +22 -1
  320. package/src/failure-kinds.ts +104 -2
  321. package/src/flow-requirements.ts +24 -9
  322. package/src/gate-contract.ts +13 -1
  323. package/src/helper-preflight.ts +10 -3
  324. package/src/helper-reference.ts +130 -0
  325. package/src/hosted-extension-runtime.ts +1 -1
  326. package/src/index.ts +2 -0
  327. package/src/journal-client.ts +19 -2
  328. package/src/journal-projection.ts +106 -0
  329. package/src/llm-worker.ts +1 -1
  330. package/src/local-agent.ts +4 -2
  331. package/src/named-gate-lowering.ts +35 -5
  332. package/src/named-gate-preflight.ts +47 -0
  333. package/src/named-gates.ts +3 -0
  334. package/src/observer-link.ts +10 -1
  335. package/src/package-version.ts +23 -0
  336. package/src/preflight.ts +38 -7
  337. package/src/protocol.ts +2 -0
  338. package/src/redact.ts +111 -0
  339. package/src/relay-cli.ts +1 -24
  340. package/src/run-projection.ts +247 -0
  341. package/src/shell-word.ts +24 -0
  342. package/src/spec.ts +54 -3
  343. package/src/step-fields.ts +1 -1
  344. package/src/steps-green.ts +168 -0
  345. package/src/validate.ts +35 -8
  346. package/src/worker-lease.ts +35 -5
  347. package/src/worker.ts +27 -11
@@ -0,0 +1,166 @@
1
+ import { accessSync, constants } from 'node:fs';
2
+ import { isAbsolute, resolve } from 'node:path';
3
+ import { execFile, spawnSync } from 'node:child_process';
4
+ import { agentEnvironment, brokerEnvironment } from '../communication/environment.js';
5
+ import { adapterIdentification, authenticationProbe, cliAdapterKind, displayInvocation, modelReadinessProbe } from '../cli-adapter.js';
6
+ import { MODEL_ENV } from '../worker-cli.js';
7
+ import { CliProbeError } from '../preflight.js';
8
+ /** One decision sequence; checking uses synchronous I/O, live flows yield the loop. */
9
+ export function probeCli(...args) {
10
+ return driveSync(probeSequence(...args));
11
+ }
12
+ export async function probeCliAsync(...args) {
13
+ const sequence = probeSequence(...args);
14
+ let next = sequence.next();
15
+ while (!next.done)
16
+ next = sequence.next(await runProbeAsync(next.value));
17
+ return next.value;
18
+ }
19
+ export function resolveExecutable(command, directory) {
20
+ return driveSync(executableSequence(command, directory));
21
+ }
22
+ function driveSync(sequence) {
23
+ let next = sequence.next();
24
+ while (!next.done) {
25
+ const request = next.value;
26
+ const result = spawnSync(request.executable, request.invocation.args, {
27
+ ...probeOptions(request),
28
+ // Preserve the old synchronous probe contract: provider CLIs must not
29
+ // inherit a readable stdin that can block auth/identify probes.
30
+ stdio: ['ignore', 'pipe', 'pipe'],
31
+ });
32
+ const failure = classifySpawnFailure(result.error, result.signal, request.invocation.timeoutMs);
33
+ if (failure !== undefined)
34
+ throw failure;
35
+ next = sequence.next({ status: result.status, stdout: result.stdout ?? '', stderr: result.stderr ?? '' });
36
+ }
37
+ return next.value;
38
+ }
39
+ function probeOptions({ directory, invocation, environment }) {
40
+ const env = { ...environment };
41
+ delete env[MODEL_ENV];
42
+ if (invocation.modelEnv !== undefined)
43
+ env[MODEL_ENV] = invocation.modelEnv;
44
+ return { cwd: directory, encoding: 'utf8', timeout: invocation.timeoutMs,
45
+ maxBuffer: 1024 * 1024, env };
46
+ }
47
+ function runProbeAsync(request) {
48
+ return new Promise((resolve, reject) => {
49
+ const child = execFile(request.executable, request.invocation.args, probeOptions(request), (error, stdout, stderr) => {
50
+ // Numeric exit codes are probe results; launch, timeout, signal and buffer
51
+ // errors are failures to collect a fact, just as in the synchronous driver.
52
+ if (error?.killed && typeof error.code !== 'string')
53
+ return reject(new CliProbeError(`timeout:${request.invocation.timeoutMs}ms`));
54
+ const failure = classifySpawnFailure(error !== null && typeof error.code !== 'number' && error.signal == null ? error : undefined, error?.signal ?? null, request.invocation.timeoutMs);
55
+ if (failure !== undefined)
56
+ return reject(failure);
57
+ resolve({ status: error === null ? 0 : typeof error.code === 'number' ? error.code : null,
58
+ stdout, stderr });
59
+ });
60
+ child.stdin?.end();
61
+ });
62
+ }
63
+ function* probeSequence(cli, directory, model, execution) {
64
+ const executable = yield* executableSequence(cli, directory);
65
+ if (executable === undefined)
66
+ return { exists: false, authenticated: false };
67
+ const kind = cliAdapterKind(executable);
68
+ // Relay owns interactive CLI launch/injection. Its generic PTY path is not
69
+ // the headless wrapper protocol; do not demand that protocol from Gemini,
70
+ // Cursor, OpenCode, or other interactive tools. Never invent an auth pass.
71
+ if (execution === 'managed' && kind === 'relayflows-wrapper-v1') {
72
+ return { exists: true, supported: true, authenticated: 'unverified' };
73
+ }
74
+ const environment = execution === 'managed'
75
+ ? { ...brokerEnvironment(process.env), ...agentEnvironment(executable) } : process.env;
76
+ const probe = (invocation) => ({ executable, directory, invocation, environment });
77
+ const identification = adapterIdentification(kind);
78
+ const identified = yield probe(identification.invocation);
79
+ if (identified.status !== 0
80
+ || (identification.expectedStdout !== undefined
81
+ && identified.stdout.trim() !== identification.expectedStdout)) {
82
+ return { exists: true, supported: false, authenticated: false };
83
+ }
84
+ const auth = authenticationProbe(kind);
85
+ const authCommand = displayInvocation(cli, auth);
86
+ if (model === undefined) {
87
+ return {
88
+ exists: true,
89
+ supported: true,
90
+ authenticated: (yield probe(auth)).status === 0,
91
+ authCommand,
92
+ };
93
+ }
94
+ const scoped = modelReadinessProbe(kind, model);
95
+ const modelCommand = displayInvocation(cli, scoped);
96
+ // A successful real provider round trip (or identified wrapper probe)
97
+ // proves both auth and exact-model access. On failure, run the adapter's
98
+ // actual auth command solely to classify auth vs model access truthfully.
99
+ if ((yield probe(scoped)).status === 0) {
100
+ return {
101
+ exists: true,
102
+ supported: true,
103
+ authenticated: true,
104
+ modelAvailable: true,
105
+ authCommand,
106
+ modelCommand,
107
+ };
108
+ }
109
+ const authProbe = yield probe(auth);
110
+ const authenticated = authProbe.status === 0;
111
+ return {
112
+ exists: true,
113
+ supported: true,
114
+ authenticated,
115
+ modelAvailable: false,
116
+ authCommand,
117
+ modelCommand,
118
+ // Only on failure: on success there is nothing to explain, and the output
119
+ // is the most identity-bearing thing this function touches.
120
+ ...(authenticated
121
+ ? {}
122
+ : {
123
+ authExitCode: authProbe.status,
124
+ authFailureDetail: redactProbeOutput(`${authProbe.stderr}${authProbe.stdout}`).trim().slice(0, 500),
125
+ }),
126
+ };
127
+ }
128
+ /**
129
+ * Redact anything that looks like a credential or an account identifier.
130
+ *
131
+ * `auth status` output is diagnostic, but it is also the one place an account
132
+ * email, org id or token fragment can appear. The point of surfacing it is to
133
+ * say WHY a probe failed, which survives redaction; leaking an identity into a
134
+ * refusal message that gets pasted into issues does not.
135
+ */
136
+ function redactProbeOutput(text) {
137
+ return text
138
+ .replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, '<redacted-email>')
139
+ .replace(/\b(sk|pk|oat|rt)[-_][A-Za-z0-9._-]{8,}/gi, '<redacted-token>')
140
+ .replace(/\b[A-Fa-f0-9]{32,}\b/g, '<redacted-hex>');
141
+ }
142
+ function* executableSequence(command, directory) {
143
+ if (command.includes('/') || isAbsolute(command)) {
144
+ const path = isAbsolute(command) ? command : resolve(directory, command);
145
+ try {
146
+ accessSync(path, constants.X_OK);
147
+ return path;
148
+ }
149
+ catch {
150
+ return undefined;
151
+ }
152
+ }
153
+ const result = yield { executable: 'which', directory: process.cwd(),
154
+ invocation: { args: [command], timeoutMs: 5_000 }, environment: process.env };
155
+ return result.status === 0 ? result.stdout.trim() : undefined;
156
+ }
157
+ function classifySpawnFailure(error, signal, timeoutMs) {
158
+ if (error !== undefined) {
159
+ const detail = error.code === 'ETIMEDOUT'
160
+ ? `timeout:${timeoutMs}ms`
161
+ : 'spawn_failed';
162
+ return new CliProbeError(detail);
163
+ }
164
+ return signal === null ? undefined : new CliProbeError(`signal:${signal}`);
165
+ }
166
+ //# sourceMappingURL=cli-probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-probe.js","sourceRoot":"","sources":["../../src/cli/cli-probe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,cAAc,EAAE,iBAAiB,EACpF,mBAAmB,EAAsB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AAUrE,uFAAuF;AACvF,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAsC;IAChE,OAAO,SAAS,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KA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d,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE;QAClE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;IAChF,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC;AAED,SAAS,oBAAoB,CAC3B,KAAwB,EACxB,MAA6B,EAC7B,SAAiB;IAEjB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,MAAM,GAAI,KAA+B,CAAC,IAAI,KAAK,WAAW;YAClE,CAAC,CAAC,WAAW,SAAS,IAAa;YACnC,CAAC,CAAC,cAAuB,CAAC;QAC5B,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare function thousands(value: number): string;
2
+ export declare function dollars(value: number): string;
3
+ /** Agent- and flow-authored names cannot inject terminal control sequences. */
4
+ export declare function safe(text: string): string;
5
+ export declare function errorLines(text: string, indent: string): string[];
6
+ /** ISO-8601 to the second: a list column, not a timestamp to do arithmetic on. */
7
+ export declare function instant(value: string | null): string;
8
+ export declare function ago(value: string | null, now: number): string;
9
+ //# sourceMappingURL=cloud-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-format.d.ts","sourceRoot":"","sources":["../../src/cli/cloud-format.ts"],"names":[],"mappings":"AAYA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,+EAA+E;AAC/E,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC;AAoBD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAyBjE;AAED,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAIpD;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAI7D"}
@@ -0,0 +1,77 @@
1
+ // The cells every hosted-run page is built from.
2
+ //
3
+ // Moved out of `cli/cloud-read.ts` verbatim when the live views (`--watch`,
4
+ // `--follow`) needed the same formatting: the run list, the status page and
5
+ // the watched page must render a count, a cost and an instant identically, or
6
+ // a reader would have to learn which verb they were looking at first.
7
+ //
8
+ // Depends on nothing in `cli/` but `formatDuration`, so every other Cloud CLI
9
+ // module can import it without an import cycle.
10
+ import { formatDuration } from './status.js';
11
+ export function thousands(value) {
12
+ return String(value).replace(/\B(?=(\d{3})+(?!\d))/gu, ',');
13
+ }
14
+ export function dollars(value) {
15
+ return `$${value.toFixed(6).replace(/0+$/u, '').replace(/\.$/u, '')}`;
16
+ }
17
+ /** Agent- and flow-authored names cannot inject terminal control sequences. */
18
+ export function safe(text) {
19
+ return text.replace(/[\u0000-\u001F\u007F-\u009F]/gu, '?');
20
+ }
21
+ /**
22
+ * Render a run's `error` as readable lines rather than one control-char smear.
23
+ *
24
+ * Cloud stores the runner's terminal output in this field, newlines and all, so
25
+ * passing it through `safe()` alone turns a 200-line tail into a single line of
26
+ * `?` separators. Long runs are dominated by lease renewals — one line every
27
+ * 10s for the life of every agent step, differing only in the deadline — which
28
+ * are worth counting, not reading.
29
+ *
30
+ * Collapsing is deliberately narrow: two adjacent lines merge only when they
31
+ * are character-for-character identical once a trailing integer is masked. A
32
+ * shared prefix is NOT line identity — runner lines put the step name, reason
33
+ * or message after a long fixed prefix, so collapsing on a prefix would hide
34
+ * distinct diagnostics behind a similarity count. The final line never
35
+ * collapses into an earlier one, because that is where the failure is.
36
+ */
37
+ const TRAILING_NUMBER = /\d+(?=\D{0,2}$)/u;
38
+ export function errorLines(text, indent) {
39
+ const raw = text.split(/\r\n|\r|\n/u).map((line) => line.trimEnd()).filter((line) => line !== '');
40
+ if (raw.length === 0)
41
+ return [];
42
+ const key = (line) => line.replace(TRAILING_NUMBER, '#');
43
+ const collapsed = [];
44
+ raw.forEach((line, index) => {
45
+ const previous = collapsed.at(-1);
46
+ const isLast = index === raw.length - 1;
47
+ if (previous !== undefined && !isLast && key(previous.line) === key(line))
48
+ previous.count += 1;
49
+ else
50
+ collapsed.push({ line, count: 1 });
51
+ });
52
+ const rendered = collapsed.map(({ line, count }) => count === 1 ? safe(line) : `${safe(line)} (${count} times, differing only in a number)`);
53
+ const HEAD = 2;
54
+ const TAIL = 12;
55
+ if (rendered.length <= HEAD + TAIL + 1)
56
+ return rendered.map((line) => `${indent}${line}`);
57
+ const elided = rendered.length - HEAD - TAIL;
58
+ return [
59
+ ...rendered.slice(0, HEAD),
60
+ `… ${elided} more line${elided === 1 ? '' : 's'} (full text: --json)`,
61
+ ...rendered.slice(-TAIL),
62
+ ].map((line) => `${indent}${line}`);
63
+ }
64
+ /** ISO-8601 to the second: a list column, not a timestamp to do arithmetic on. */
65
+ export function instant(value) {
66
+ if (value === null)
67
+ return 'unknown';
68
+ const parsed = Date.parse(value);
69
+ return Number.isFinite(parsed) ? new Date(parsed).toISOString().replace(/\.\d{3}Z$/u, 'Z') : 'unknown';
70
+ }
71
+ export function ago(value, now) {
72
+ if (value === null)
73
+ return 'unknown';
74
+ const parsed = Date.parse(value);
75
+ return Number.isFinite(parsed) ? `${formatDuration(now - parsed)} ago` : 'unknown';
76
+ }
77
+ //# sourceMappingURL=cloud-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-format.js","sourceRoot":"","sources":["../../src/cli/cloud-format.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,8EAA8E;AAC9E,gDAAgD;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;AACxE,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,MAAc;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IAClG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEhC,MAAM,GA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,CAAC,CAAC,EAAE,IAAI,CAAC;QAC1B,KAAK,MAAM,aAAa,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,sBAAsB;QACrE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;KACzB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,OAAO,CAAC,KAAoB;IAC1C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzG,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAAoB,EAAE,GAAW;IACnD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACrF,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type CloudReadOptions } from './cloud-refusal.js';
2
+ import type { CliIo } from '../cli.js';
3
+ export interface CloudLiveOptions extends CloudReadOptions {
4
+ /** Milliseconds between polls. Injected by tests; 1..60000, as the waiter accepts. */
5
+ pollIntervalMs?: number;
6
+ /** Injected by tests so no suite sleeps; production uses the abortable sleep. */
7
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
8
+ }
9
+ /**
10
+ * Redraw the hosted status page until the run is terminal, then leave the
11
+ * final page up and exit with the run's outcome.
12
+ *
13
+ * The detail and the step rows are two requests against two projections, so
14
+ * the page is a pair of reads and not an atomic snapshot: a step row can lag
15
+ * the header it is drawn under by one poll. That is a property of the API, and
16
+ * this view reports what each read said rather than reconciling them.
17
+ */
18
+ export declare function runCloudStatusWatch(args: {
19
+ runId?: string;
20
+ json: boolean;
21
+ }, io: CliIo, options?: CloudLiveOptions): Promise<0 | 1 | 2>;
22
+ /**
23
+ * Append the hosted runner log until the run is terminal and its log is drained.
24
+ *
25
+ * The route serves the log from an offset, but this client does not page it:
26
+ * the offsets are byte counts and the content is a JavaScript string, and
27
+ * subtracting one from the other silently loses text the moment a log contains
28
+ * a non-ASCII character — which the runner's own transition lines do. Until
29
+ * the byte-range contract can be checked against the server, each poll reads
30
+ * the whole log and prints the part that is new, refusing outright if what it
31
+ * already showed is no longer a prefix of what Cloud serves. That costs a full
32
+ * read per poll and holds the log in memory; it cannot duplicate or drop a line.
33
+ */
34
+ export declare function runCloudLogsFollow(args: {
35
+ runId: string;
36
+ step: string | undefined;
37
+ json: boolean;
38
+ }, io: CliIo, options?: CloudLiveOptions): Promise<0 | 1 | 2>;
39
+ //# sourceMappingURL=cloud-live.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-live.d.ts","sourceRoot":"","sources":["../../src/cli/cloud-live.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAsD,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG/G,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAMvC,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,sFAAsF;IACtF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AA2CD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,EACvC,EAAE,EAAE,KAAK,EACT,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CA+CpB;AAuGD;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,EAChE,EAAE,EAAE,KAAK,EACT,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAkGpB"}
@@ -0,0 +1,325 @@
1
+ // `flows status --cloud --watch` and `flows logs <run> --follow`: the two
2
+ // hosted reads that keep reading.
3
+ //
4
+ // The one-shot verbs (cli/cloud-read.ts) answer "what did that run do". These
5
+ // two answer "what is it doing", by asking again until the run is over. Three
6
+ // properties separate them from a loop around the one-shot reads:
7
+ //
8
+ // 1. **The exit code is the run's.** A finished page is not evidence that the
9
+ // run succeeded; `getCloudRunDetailLive` validates the same record
10
+ // `flows run --wait` blocks on, so `--watch` and `--follow` exit 0 only on
11
+ // an attested `completed`/`success`, 1 on an attested failure or a
12
+ // cancellation, and refuse a terminal record that attests neither.
13
+ // 2. **A frame is whole or absent.** The page is rendered, then the abort is
14
+ // checked, then the whole page leaves in one `io.stdout` call. A Ctrl-C
15
+ // mid-poll ends the command with a refusal and no half-drawn screen.
16
+ // 3. **Nothing is invented while waiting.** A failed poll leaves the previous
17
+ // page and the consumed log exactly where they were; it never clears the
18
+ // screen to show an error, and never re-prints a line it has shown.
19
+ //
20
+ // Cancellation is the caller's: `runCli` hands these functions the signal it
21
+ // owns for the verb's duration, and nothing here installs a process handler.
22
+ // Aborting stops the observation, not the hosted run — the refusal says so.
23
+ import { canonicalize } from '../canonical.js';
24
+ import { getCloudRunDetailLive, getCloudRunLog, getCloudRunSteps, } from '../cloud-read.js';
25
+ import { isCloudRunActive } from '../cloud-run-record.js';
26
+ import { endsWithOpenCredentialHeader, openCredentialStart, openSecretStart, redact } from '../redact.js';
27
+ import { thousands } from './cloud-format.js';
28
+ import { fail, isTransientRead, refusalFor, RUN_ID_REQUIRED } from './cloud-refusal.js';
29
+ import { renderCloudStatus, scrubRun, scrubSteps } from './cloud-status-view.js';
30
+ import { sleepInterruptible } from './interruptible-sleep.js';
31
+ /** The cadence `waitForCloudFlowRun` polls at; not a user flag on either verb. */
32
+ const DEFAULT_POLL_INTERVAL_MS = 2_000;
33
+ const MAX_BACKOFF_MS = 30_000;
34
+ /** Clears the screen only for a terminal; a redirected page must stay text. */
35
+ function clearSequence(io) {
36
+ return io.tty === true ? '\u001b[2J\u001b[H' : '';
37
+ }
38
+ /** The same delay schedule as `waitForCloudFlowRun`: ×2 per failure, capped. */
39
+ function delayFor(failures, interval) {
40
+ return failures === 0 ? interval : Math.min(interval * 2 ** (failures - 1), MAX_BACKOFF_MS);
41
+ }
42
+ /** The hosted `flows run --wait` mapping: only an attested success is 0. */
43
+ function exitFor(state) {
44
+ return state.status === 'completed' ? 0 : 1;
45
+ }
46
+ function aborted(verb, runId, json, io) {
47
+ fail({
48
+ code: 'observation_aborted', exit: 1,
49
+ message: `Stopped ${verb} run ${runId}; the hosted run has not been cancelled.`,
50
+ }, json, io);
51
+ return 1;
52
+ }
53
+ /**
54
+ * Has the caller cancelled?
55
+ *
56
+ * A function rather than `signal?.aborted` at each site on purpose: `aborted`
57
+ * is a readonly property, so an inline check narrows the signal's type for the
58
+ * rest of the block and the compiler then calls every later check dead — which
59
+ * is exactly backwards for a value that changes under an await.
60
+ */
61
+ function isAborted(signal) {
62
+ return signal !== undefined && signal.aborted;
63
+ }
64
+ function invalidInterval(interval) {
65
+ return !Number.isSafeInteger(interval) || interval < 1 || interval > 60_000;
66
+ }
67
+ // -------------------------------------------------- flows status --cloud --watch
68
+ /**
69
+ * Redraw the hosted status page until the run is terminal, then leave the
70
+ * final page up and exit with the run's outcome.
71
+ *
72
+ * The detail and the step rows are two requests against two projections, so
73
+ * the page is a pair of reads and not an atomic snapshot: a step row can lag
74
+ * the header it is drawn under by one poll. That is a property of the API, and
75
+ * this view reports what each read said rather than reconciling them.
76
+ */
77
+ export async function runCloudStatusWatch(args, io, options = {}) {
78
+ const env = options.env ?? process.env;
79
+ const clock = options.now ?? Date.now;
80
+ const signal = options.signal;
81
+ const interval = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
82
+ const sleep = options.sleep ?? sleepInterruptible;
83
+ if (args.runId === undefined || args.runId.length === 0)
84
+ return fail(RUN_ID_REQUIRED, args.json, io);
85
+ const runId = args.runId;
86
+ if (invalidInterval(interval)) {
87
+ return fail({ code: 'cloud_configuration', exit: 2, message: 'pollIntervalMs must be an integer from 1 to 60000.' }, args.json, io);
88
+ }
89
+ let failures = 0;
90
+ for (;;) {
91
+ if (isAborted(signal))
92
+ return aborted('watching', runId, args.json, io);
93
+ let live;
94
+ let steps;
95
+ try {
96
+ live = await getCloudRunDetailLive(runId, options);
97
+ if (isAborted(signal))
98
+ return aborted('watching', runId, args.json, io);
99
+ steps = await getCloudRunSteps(runId, options);
100
+ }
101
+ catch (error) {
102
+ if (isAborted(signal))
103
+ return aborted('watching', runId, args.json, io);
104
+ if (!isTransientRead(error))
105
+ return fail(refusalFor(error, `run ${runId}`, env), args.json, io);
106
+ // The previous page stays exactly as it was: a poll that did not
107
+ // complete is not news about the run.
108
+ failures = Math.min(failures + 1, 16);
109
+ await sleep(delayFor(failures, interval), signal);
110
+ continue;
111
+ }
112
+ failures = 0;
113
+ const run = scrubRun(live.detail, env);
114
+ const scrubbed = scrubSteps(steps, env);
115
+ const terminal = !isCloudRunActive(live.state.status);
116
+ // Rendered before the abort check and emitted after it, in one call: an
117
+ // interrupt between two lines of a frame would leave a torn page.
118
+ const page = args.json ? '' : `${clearSequence(io)}${renderCloudStatus(run, scrubbed, clock()).join('\n')}`;
119
+ if (isAborted(signal))
120
+ return aborted('watching', runId, args.json, io);
121
+ if (!args.json)
122
+ io.stdout(page);
123
+ if (terminal) {
124
+ if (args.json)
125
+ io.stdout(canonicalize({ v: 1, ok: true, run, steps: scrubbed, now_ms: clock() }));
126
+ return exitFor(live.state);
127
+ }
128
+ await sleep(interval, signal);
129
+ }
130
+ }
131
+ /**
132
+ * Print `text` as lines.
133
+ *
134
+ * Splitting is on `\n` only, and one trailing `\r` per line is dropped: a
135
+ * CRLF log printed with its carriage returns intact makes a terminal overwrite
136
+ * each line it just drew. A final newline ends the last line rather than
137
+ * starting an empty one. Blank lines and repeated identical lines are
138
+ * preserved — they are the log.
139
+ */
140
+ function writeLines(text, state, io) {
141
+ const lines = text.split('\n');
142
+ if (lines.at(-1) === '')
143
+ lines.pop();
144
+ for (const line of lines) {
145
+ io.stdout(line.replace(/\r$/u, ''));
146
+ state.emitted = true;
147
+ }
148
+ }
149
+ /** The last line boundary at or before `at`: 0, or the index after a newline. */
150
+ function lineBoundaryAtOrBefore(text, at) {
151
+ return at <= 0 ? 0 : text.lastIndexOf('\n', at - 1) + 1;
152
+ }
153
+ /**
154
+ * Release every line the log has settled on, redacted as one block.
155
+ *
156
+ * Four things hold a line back. `openSecretStart` marks where a secret value
157
+ * has begun and not ended, so nothing at or past it can be shown until the
158
+ * next poll completes it. `openCredentialStart` marks a trailing credential
159
+ * header — `authorization:`, `Bearer`, a callback-token name, or an
160
+ * unterminated credential JSON field — whose value may only arrive on a later
161
+ * poll; releasing the header first would leave the value without the context
162
+ * the redactor needs. A block is never ended on a bare credential header even
163
+ * when more text follows, because the redactor folds the header's newline
164
+ * into its own match — the block-prefix check cannot see that the header's
165
+ * value lives on the next line. And a candidate block is released only when
166
+ * redacting it alone gives the same text as the front of the whole redacted
167
+ * remainder: if the cut fell inside something the redactor would have caught —
168
+ * the second line of a private key — the two disagree, and the cut moves back
169
+ * a line and is tried again.
170
+ *
171
+ * A poll that can release nothing prints nothing; the bytes are not lost, they
172
+ * are held until a later poll or the drain flush can redact them whole.
173
+ */
174
+ function releaseLines(state, io, env) {
175
+ const raw = state.consumed;
176
+ if (state.released >= raw.length)
177
+ return;
178
+ const remainder = redact(raw.slice(state.released), env);
179
+ let cut = lineBoundaryAtOrBefore(raw, Math.min(openSecretStart(raw, env), openCredentialStart(raw)));
180
+ while (cut > state.released) {
181
+ if (endsWithOpenCredentialHeader(raw.slice(state.released, cut))) {
182
+ // A bare credential header as the released block's last line strands
183
+ // the value that starts on the next line — redact needs them together.
184
+ // Shrink until the header is inside the held remainder; it releases
185
+ // with its value line once that line is complete.
186
+ cut = lineBoundaryAtOrBefore(raw, cut - 1);
187
+ continue;
188
+ }
189
+ const block = redact(raw.slice(state.released, cut), env);
190
+ if (remainder.startsWith(block)) {
191
+ writeLines(block, state, io);
192
+ state.released = cut;
193
+ return;
194
+ }
195
+ cut = lineBoundaryAtOrBefore(raw, cut - 1);
196
+ }
197
+ }
198
+ /**
199
+ * Has Cloud finished publishing this log?
200
+ *
201
+ * Three facts, all required. The run being over does not mean the last bytes
202
+ * have been written; `done` alone does not mean the run is over (the route can
203
+ * report a completed *upload* of a log the run is still adding to); and a
204
+ * `done` envelope that carries fewer bytes than it advertises has not served
205
+ * the tail. Stopping on any one of them alone would truncate the output, which
206
+ * is the one thing a follow must not do.
207
+ */
208
+ function logDrained(log, terminal, content) {
209
+ return terminal && log.done && Buffer.byteLength(content, 'utf8') >= log.total_size;
210
+ }
211
+ /**
212
+ * Append the hosted runner log until the run is terminal and its log is drained.
213
+ *
214
+ * The route serves the log from an offset, but this client does not page it:
215
+ * the offsets are byte counts and the content is a JavaScript string, and
216
+ * subtracting one from the other silently loses text the moment a log contains
217
+ * a non-ASCII character — which the runner's own transition lines do. Until
218
+ * the byte-range contract can be checked against the server, each poll reads
219
+ * the whole log and prints the part that is new, refusing outright if what it
220
+ * already showed is no longer a prefix of what Cloud serves. That costs a full
221
+ * read per poll and holds the log in memory; it cannot duplicate or drop a line.
222
+ */
223
+ export async function runCloudLogsFollow(args, io, options = {}) {
224
+ const env = options.env ?? process.env;
225
+ const signal = options.signal;
226
+ const interval = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
227
+ const sleep = options.sleep ?? sleepInterruptible;
228
+ const runId = args.runId;
229
+ // Refused before any request: a step transcript is not an append-only stream
230
+ // this verb can follow. A retry replaces it, and the rendered form is built
231
+ // from the whole JSONL — attempt markers, session header, result footer —
232
+ // rather than a line at a time.
233
+ if (args.step !== undefined) {
234
+ return fail({
235
+ code: 'invalid_invocation', exit: 2,
236
+ message: '`flows logs --follow` follows the runner log, which is append-only; it cannot follow a step '
237
+ + 'transcript. Follow the run with `flows logs <run-id> --follow`, or read the step transcript once '
238
+ + 'with `flows logs <run-id> --step <name>`.',
239
+ }, args.json, io);
240
+ }
241
+ if (invalidInterval(interval)) {
242
+ return fail({ code: 'cloud_configuration', exit: 2, message: 'pollIntervalMs must be an integer from 1 to 60000.' }, args.json, io);
243
+ }
244
+ const state = { consumed: '', released: 0, emitted: false };
245
+ let header = false;
246
+ let failures = 0;
247
+ // A snapshot that satisfies every drain fact can still predate terminality:
248
+ // `done` can describe an upload finished while the run kept writing, and the
249
+ // log route can keep serving that snapshot past the terminal transition.
250
+ // The read that ends the follow has to postdate the terminal observation —
251
+ // which on the first sighting it cannot — so a terminal run always gets one
252
+ // more poll before its log counts as drained.
253
+ let terminalObserved = false;
254
+ for (;;) {
255
+ if (isAborted(signal))
256
+ return aborted('following', runId, args.json, io);
257
+ let outcome;
258
+ let log;
259
+ try {
260
+ // The run record first: a log read that follows a terminal status can
261
+ // only be missing bytes Cloud had not published yet, never bytes written
262
+ // after the check.
263
+ const live = await getCloudRunDetailLive(runId, options);
264
+ if (isAborted(signal))
265
+ return aborted('following', runId, args.json, io);
266
+ log = await getCloudRunLog(runId, undefined, options);
267
+ outcome = live.state;
268
+ }
269
+ catch (error) {
270
+ if (isAborted(signal))
271
+ return aborted('following', runId, args.json, io);
272
+ if (!isTransientRead(error))
273
+ return fail(refusalFor(error, `run ${runId}`, env), args.json, io);
274
+ failures = Math.min(failures + 1, 16);
275
+ await sleep(delayFor(failures, interval), signal);
276
+ continue;
277
+ }
278
+ failures = 0;
279
+ if (isAborted(signal))
280
+ return aborted('following', runId, args.json, io);
281
+ if (!log.content.startsWith(state.consumed)) {
282
+ return fail({
283
+ code: 'cloud_log_rewritten', exit: 1,
284
+ message: `Cloud's runner log for run ${runId} no longer begins with the ${thousands(state.consumed.length)} `
285
+ + 'characters already shown, so following it would skip or repeat output. Read it whole with '
286
+ + `\`flows logs ${runId}\`.`,
287
+ }, args.json, io);
288
+ }
289
+ state.consumed = log.content;
290
+ const terminal = !isCloudRunActive(outcome.status);
291
+ const drained = terminalObserved && logDrained(log, terminal, log.content);
292
+ terminalObserved ||= terminal;
293
+ if (!args.json) {
294
+ if (!header) {
295
+ io.stdout(`LOG ${runId} runner following ${thousands(log.total_size)} bytes so far`);
296
+ header = true;
297
+ }
298
+ releaseLines(state, io, env);
299
+ }
300
+ if (!drained) {
301
+ await sleep(interval, signal);
302
+ continue;
303
+ }
304
+ // Drained: the last line may have no newline, and this is the only moment
305
+ // at which printing it cannot cut a line in half.
306
+ if (args.json) {
307
+ io.stdout(canonicalize({
308
+ v: 1, ok: true, run_id: runId, step: null,
309
+ bytes: log.offset, total_bytes: log.total_size, done: log.done,
310
+ content: redact(log.content, env),
311
+ }));
312
+ return exitFor(outcome);
313
+ }
314
+ if (state.released < state.consumed.length) {
315
+ writeLines(redact(state.consumed.slice(state.released), env), state, io);
316
+ state.released = state.consumed.length;
317
+ }
318
+ if (!state.emitted)
319
+ io.stdout(' (empty)');
320
+ io.stdout(`${outcome.status.toUpperCase()} ${runId} completionReason: `
321
+ + `${'completionReason' in outcome ? outcome.completionReason : 'unavailable'}`);
322
+ return exitFor(outcome);
323
+ }
324
+ }
325
+ //# sourceMappingURL=cloud-live.js.map