@agimon-ai/po-workflow 0.0.0-alpha.152 → 0.0.0-alpha.153

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.
@@ -1,7 +1,29 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
2
23
  const require_workflowCommandTemplate = require("./workflowCommandTemplate-w6rOCJpw.cjs");
24
+ const require_contract = require("./contract-DDvm7ENF.cjs");
3
25
  let node_path = require("node:path");
4
- node_path = require_rolldown_runtime.__toESM(node_path, 1);
26
+ node_path = __toESM(node_path, 1);
5
27
  let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
6
28
  let _agimon_ai_po_core_workflow = require("@agimon-ai/po-core/workflow");
7
29
  let typebox_value = require("typebox/value");
@@ -15,7 +37,7 @@ let _agimon_ai_po_core_hubChannel = require("@agimon-ai/po-core/hubChannel");
15
37
  let node_child_process = require("node:child_process");
16
38
  let node_fs = require("node:fs");
17
39
  let node_fs_promises = require("node:fs/promises");
18
- node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises, 1);
40
+ node_fs_promises = __toESM(node_fs_promises, 1);
19
41
  let node_readline = require("node:readline");
20
42
  let node_url = require("node:url");
21
43
  let proper_lockfile = require("proper-lockfile");
@@ -725,6 +747,10 @@ const WorkflowRunRecordSchema = zod.z.object({
725
747
  job: zod.z.string().optional(),
726
748
  launcher: WorkflowLauncherMetadataSchema.optional(),
727
749
  outcome: WorkflowOutcomeSchema.optional(),
750
+ hostOwner: zod.z.object({
751
+ token: zod.z.string().min(1),
752
+ generation: zod.z.number().int().positive()
753
+ }).optional(),
728
754
  pid: zod.z.number().int().positive().optional(),
729
755
  prompt: zod.z.string().optional(),
730
756
  runner: zod.z.string().optional(),
@@ -1362,6 +1388,7 @@ var WorkflowRegistryService = class {
1362
1388
  stale: DEFAULT_RECOVERY_CLAIM_TTL_MS
1363
1389
  });
1364
1390
  try {
1391
+ this.runtime.workflowHost.durable?.assertOwnership();
1365
1392
  return await action();
1366
1393
  } finally {
1367
1394
  await release();
@@ -1529,7 +1556,7 @@ var WorkflowRegistryService = class {
1529
1556
  },
1530
1557
  stage: RUNNING_STAGE,
1531
1558
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1532
- pid: input.pid ?? this.runtime.workflowHost.processId,
1559
+ ...this.runtime.workflowHost.durable ? { hostOwner: this.runtime.workflowHost.durable.owner } : { pid: input.pid ?? this.runtime.workflowHost.processId },
1533
1560
  workflowPath: input.workflowPath,
1534
1561
  workflowId: input.workflowId,
1535
1562
  workflowName: input.workflowName,
@@ -1834,6 +1861,7 @@ var WorkflowRegistryService = class {
1834
1861
  };
1835
1862
  }
1836
1863
  async writeAtomic(path, value) {
1864
+ this.runtime.workflowHost.durable?.assertOwnership();
1837
1865
  await (0, _agimon_ai_po_core_platform.writeFileAtomic)(this.runtime.fs, path, `${JSON.stringify(value, null, 2)}\n`, this.runtime.ioContext);
1838
1866
  }
1839
1867
  /** Publish complete JSON without ever exposing a partially written capability. */
@@ -1887,7 +1915,7 @@ var WorkflowRegistryService = class {
1887
1915
  claimId: (0, node_crypto.randomUUID)(),
1888
1916
  claimedAt: (/* @__PURE__ */ new Date()).toISOString(),
1889
1917
  ownerSessionId: ownerSessionId?.trim() || void 0,
1890
- pid: this.runtime.workflowHost.processId
1918
+ ...this.runtime.workflowHost.durable ? { hostOwner: this.runtime.workflowHost.durable.owner } : { pid: this.runtime.workflowHost.processId }
1891
1919
  };
1892
1920
  const claimPath = (0, node_path.resolve)(errorDir, RECOVERY_CLAIM_FILENAME);
1893
1921
  const releaseLock = await this.acquireRecoveryClaimLock(errorDir).catch((error) => {
@@ -1925,7 +1953,7 @@ var WorkflowRegistryService = class {
1925
1953
  const adoption = {
1926
1954
  adoptedAt: (/* @__PURE__ */ new Date()).toISOString(),
1927
1955
  claimId,
1928
- pid: this.runtime.workflowHost.processId
1956
+ ...this.runtime.workflowHost.durable ? { hostOwner: this.runtime.workflowHost.durable.owner } : { pid: this.runtime.workflowHost.processId }
1929
1957
  };
1930
1958
  const adoptionPath = (0, node_path.resolve)(errorDir, RECOVERY_ADOPTION_FILENAME);
1931
1959
  const releaseLock = await this.acquireRecoveryClaimLock(errorDir);
@@ -1994,7 +2022,7 @@ var WorkflowRegistryService = class {
1994
2022
  let deadAdoption;
1995
2023
  try {
1996
2024
  const adoption = await this.readRecoveryAdoption(adoptionPath);
1997
- if (this.isProcessAlive(adoption.pid)) return false;
2025
+ if (this.isOwnerAlive(adoption)) return false;
1998
2026
  deadAdoption = adoption;
1999
2027
  } catch (error) {
2000
2028
  if (!["ENOENT", "not_found"].includes(String(error.code))) throw error;
@@ -2010,7 +2038,7 @@ var WorkflowRegistryService = class {
2010
2038
  if (deadAdoption && deadAdoption.claimId !== claim.claimId) return false;
2011
2039
  const claimedAt = Date.parse(claim.claimedAt);
2012
2040
  const expired = !Number.isFinite(claimedAt) || Date.now() - claimedAt >= this.recoveryClaimTtlMs;
2013
- if (!deadAdoption && this.isProcessAlive(claim.pid) && !expired) return false;
2041
+ if (!deadAdoption && this.isOwnerAlive(claim) && !expired) return false;
2014
2042
  try {
2015
2043
  if ((await this.readRecoveryClaim(claimPath)).claimId !== claim.claimId) return false;
2016
2044
  (0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.remove(claimPath, void 0, this.runtime.ioContext));
@@ -2025,14 +2053,14 @@ var WorkflowRegistryService = class {
2025
2053
  const value = JSON.parse((0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.readTextFile(path, this.runtime.ioContext)));
2026
2054
  if (!value || typeof value !== "object") throw new Error(`Invalid workflow recovery claim: ${path}`);
2027
2055
  const claim = value;
2028
- if (typeof claim.claimId !== "string" || typeof claim.claimedAt !== "string" || typeof claim.pid !== "number" || !Number.isInteger(claim.pid) || claim.pid <= 0 || claim.ownerSessionId !== void 0 && typeof claim.ownerSessionId !== "string") throw new Error(`Invalid workflow recovery claim: ${path}`);
2056
+ if (typeof claim.claimId !== "string" || typeof claim.claimedAt !== "string" || !this.validOwner(claim) || claim.ownerSessionId !== void 0 && typeof claim.ownerSessionId !== "string") throw new Error(`Invalid workflow recovery claim: ${path}`);
2029
2057
  return claim;
2030
2058
  }
2031
2059
  async readRecoveryAdoption(path) {
2032
2060
  const value = JSON.parse((0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.readTextFile(path, this.runtime.ioContext)));
2033
2061
  if (!value || typeof value !== "object") throw new Error(`Invalid workflow recovery adoption: ${path}`);
2034
2062
  const adoption = value;
2035
- if (typeof adoption.claimId !== "string" || typeof adoption.adoptedAt !== "string" || typeof adoption.pid !== "number" || !Number.isInteger(adoption.pid) || adoption.pid <= 0) throw new Error(`Invalid workflow recovery adoption: ${path}`);
2063
+ if (typeof adoption.claimId !== "string" || typeof adoption.adoptedAt !== "string" || !this.validOwner(adoption)) throw new Error(`Invalid workflow recovery adoption: ${path}`);
2036
2064
  return adoption;
2037
2065
  }
2038
2066
  /**
@@ -2140,11 +2168,14 @@ var WorkflowRegistryService = class {
2140
2168
  if (current.revision !== input.revision) throw new Error(`Workflow run ${input.workspace}/${input.runKey} changed since it was inspected; inspect it again before repairing.`);
2141
2169
  const adoption = current.files[RECOVERY_ADOPTION_FILENAME];
2142
2170
  if (adoption !== void 0 && !input.remove?.includes(RECOVERY_ADOPTION_FILENAME)) {
2143
- let pid;
2171
+ let owner = {};
2144
2172
  try {
2145
- pid = JSON.parse(adoption).pid;
2173
+ owner = JSON.parse(adoption);
2146
2174
  } catch {}
2147
- if (typeof pid === "number" && Number.isInteger(pid) && pid > 0 && this.isProcessAlive(pid)) throw new Error(`Workflow run ${input.workspace}/${input.runKey} is being recovered by process ${pid}.`);
2175
+ if (this.validOwner(owner) && this.isOwnerAlive(owner)) {
2176
+ const identity = owner.hostOwner ? "a durable owner" : `process ${owner.pid}`;
2177
+ throw new Error(`Workflow run ${input.workspace}/${input.runKey} is being recovered by ${identity}.`);
2178
+ }
2148
2179
  }
2149
2180
  let record;
2150
2181
  let targetDir = runDir;
@@ -2198,7 +2229,7 @@ var WorkflowRegistryService = class {
2198
2229
  return {
2199
2230
  ...state,
2200
2231
  record,
2201
- ...record.pid ? { pidAlive: this.isProcessAlive(record.pid) } : {}
2232
+ ...record.pid || record.hostOwner ? { pidAlive: this.isOwnerAlive(record) } : {}
2202
2233
  };
2203
2234
  } catch (error) {
2204
2235
  return {
@@ -2249,7 +2280,7 @@ var WorkflowRegistryService = class {
2249
2280
  const recordPath = (0, node_path.resolve)(stageDir, entry.name, RUN_RECORD_FILENAME$1);
2250
2281
  if (!await this.pathExists(recordPath)) continue;
2251
2282
  const record = await this.readRunRecord(recordPath).catch(() => null);
2252
- if (!record || record.pid && this.isProcessAlive(record.pid)) alive++;
2283
+ if (!record || (record.pid || record.hostOwner) && this.isOwnerAlive(record)) alive++;
2253
2284
  }
2254
2285
  return alive;
2255
2286
  }
@@ -2271,7 +2302,7 @@ var WorkflowRegistryService = class {
2271
2302
  if (!await this.pathExists(recordPath)) continue;
2272
2303
  const record = await this.inspectReconcilableRunningRecord(workspaceName, entry.name);
2273
2304
  if (!record) continue;
2274
- const unmovedTerminal = record.stage !== RUNNING_STAGE && !!record.pid && !this.isProcessAlive(record.pid);
2305
+ const unmovedTerminal = record.stage !== RUNNING_STAGE && !!(record.pid || record.hostOwner) && !this.isOwnerAlive(record);
2275
2306
  if (record.stale || unmovedTerminal) reconciled.push(await this.reconcileStaleRunningRecord(workspaceName, entry.name));
2276
2307
  }
2277
2308
  }
@@ -2350,13 +2381,13 @@ var WorkflowRegistryService = class {
2350
2381
  async inspectRunningRecord(workspace, runKey) {
2351
2382
  const runningRecordPath = (0, node_path.resolve)(this.getRunDirectory(workspace, RUNNING_STAGE, runKey), RUN_RECORD_FILENAME$1);
2352
2383
  const currentRecord = await this.readRunRecord(runningRecordPath);
2353
- if (currentRecord.stage !== RUNNING_STAGE || !currentRecord.pid || this.isProcessAlive(currentRecord.pid)) return currentRecord;
2384
+ if (currentRecord.stage !== RUNNING_STAGE || !(currentRecord.pid || currentRecord.hostOwner) || this.isOwnerAlive(currentRecord)) return currentRecord;
2354
2385
  return {
2355
2386
  ...currentRecord,
2356
2387
  effectiveOutcome: "interrupted",
2357
2388
  effectiveStage: ERROR_STAGE$2,
2358
2389
  stale: true,
2359
- staleReason: `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`
2390
+ staleReason: this.runtime.workflowHost.durable?.interruptionReason?.(currentRecord.runKey) ?? `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`
2360
2391
  };
2361
2392
  }
2362
2393
  /**
@@ -2406,7 +2437,7 @@ var WorkflowRegistryService = class {
2406
2437
  if (expected.stop) throw new Error(`Workflow run ownership changed: ${workspace}/${runKey}`);
2407
2438
  return currentRecord;
2408
2439
  }
2409
- if (!currentRecord.pid || this.isProcessAlive(currentRecord.pid)) {
2440
+ if (!(currentRecord.pid || currentRecord.hostOwner) || this.isOwnerAlive(currentRecord)) {
2410
2441
  if (expected?.stop) throw new Error(`Workflow process is not known to be dead: ${workspace}/${runKey}`);
2411
2442
  return currentRecord;
2412
2443
  }
@@ -2425,15 +2456,16 @@ var WorkflowRegistryService = class {
2425
2456
  return currentRecord;
2426
2457
  }
2427
2458
  const errorDir = this.getRunDirectory(workspace, ERROR_STAGE$2, runKey);
2459
+ const interruption = this.runtime.workflowHost.durable?.interruptionReason?.(currentRecord.runKey);
2428
2460
  const finalRecord = {
2429
2461
  ...currentRecord,
2430
- errorMessage: `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`,
2462
+ errorMessage: interruption ?? `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`,
2431
2463
  exitCode: INTERRUPTED_EXIT_CODE$1,
2432
2464
  failedJob: currentRecord.executionCursor?.job ?? currentRecord.failedJob,
2433
2465
  finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
2434
2466
  outcome: "interrupted",
2435
2467
  stage: ERROR_STAGE$2,
2436
- ...expected?.stop ? { resume: void 0 } : {}
2468
+ ...expected?.stop || interruption ? { resume: void 0 } : {}
2437
2469
  };
2438
2470
  await this.writeRunRecord(runningRecordPath, finalRecord);
2439
2471
  (0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.remove(errorDir, {
@@ -2467,8 +2499,13 @@ var WorkflowRegistryService = class {
2467
2499
  * Persist a run record with stable formatting.
2468
2500
  */
2469
2501
  async writeRunRecord(recordPath, record) {
2502
+ const durable = this.runtime.workflowHost.durable;
2503
+ if (record.runId && record.stage === RUNNING_STAGE) await durable?.setRunActive?.(record.runId, true);
2470
2504
  await this.writeAtomic(recordPath, record);
2471
- if (record.stage !== RUNNING_STAGE) await this.preserveRunEvidence(record, (0, node_path.dirname)(recordPath));
2505
+ if (record.stage !== RUNNING_STAGE) {
2506
+ await this.preserveRunEvidence(record, (0, node_path.dirname)(recordPath));
2507
+ if (record.runId) await durable?.setRunActive?.(record.runId, false);
2508
+ }
2472
2509
  }
2473
2510
  /**
2474
2511
  * Validate the persisted run record shape before returning it to callers.
@@ -2538,9 +2575,18 @@ var WorkflowRegistryService = class {
2538
2575
  slugifySegment(value, fallback) {
2539
2576
  return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, SLUG_SEPARATOR).replace(/^-+|-+$/g, "") || fallback;
2540
2577
  }
2541
- /**
2542
- * Check whether a locally tracked process still exists.
2543
- */
2578
+ validOwner(value) {
2579
+ if (!value || typeof value !== "object") return false;
2580
+ const owner = value.hostOwner;
2581
+ return owner !== void 0 ? owner !== null && typeof owner === "object" && typeof owner.token === "string" && owner.token.length > 0 && Number.isInteger(owner.generation) && owner.generation > 0 : typeof value.pid === "number" && Number.isInteger(value.pid) && value.pid > 0;
2582
+ }
2583
+ isOwnerAlive(value) {
2584
+ const durable = this.runtime.workflowHost.durable;
2585
+ if (durable) return value.hostOwner !== void 0 && durable.isOwnerAlive(value.hostOwner);
2586
+ if (value.hostOwner !== void 0) return true;
2587
+ return value.pid !== void 0 && this.isProcessAlive(value.pid);
2588
+ }
2589
+ /** Check whether a locally tracked native process still exists. */
2544
2590
  isProcessAlive(pid) {
2545
2591
  try {
2546
2592
  this.runtime.workflowHost.signal(pid, 0);
@@ -7628,6 +7674,36 @@ const STEP_WAITING_EVENT = "po_workflow.step_waiting";
7628
7674
  const STEP_SESSION_RELEASE_FAILED_EVENT = "po_workflow.step_session_release_failed";
7629
7675
  const STEP_PANE_FAILED_EVENT = "po_workflow.step_pane_failed";
7630
7676
  const PO_KEYS = new Set(PO_RUN_CONFIG_KEYS);
7677
+ /** Fail before creating a workflow owner or registering a run on a cloud host. */
7678
+ function cloudWorkflowLaunchRefusal(workflow, selection) {
7679
+ const blocks = [workflow.pre, workflow.post];
7680
+ const jobs = [
7681
+ ...Object.values(workflow.jobs),
7682
+ ...Object.values(workflow["child-jobs"] ?? {}),
7683
+ ...workflow.repair ? [workflow.repair] : []
7684
+ ];
7685
+ for (const job of jobs) {
7686
+ if (job.tools !== void 0) return "Workflow jobTools are not available on this cloud host.";
7687
+ blocks.push(job.preJob, job.postJob);
7688
+ }
7689
+ if (blocks.some((block) => block?.services !== void 0)) return "This cloud host does not support workflow background services.";
7690
+ const steps = [
7691
+ ...blocks.flatMap((block) => block?.steps ?? []),
7692
+ ...jobs.flatMap((job) => job.steps),
7693
+ ...workflow.on?.agent_decision?.steps ?? []
7694
+ ];
7695
+ const inspect = (step) => {
7696
+ if (step.parallel?.some(inspect)) return true;
7697
+ if (!step.interactiveRun || step.customRun) return false;
7698
+ if (!Array.isArray(step.interactiveRun)) return step.run === void 0;
7699
+ const offered = step.interactiveRun;
7700
+ const wanted = selection.command ?? (offered.some((entry) => entry.command === selection.runner) ? selection.runner : void 0);
7701
+ const entry = wanted === void 0 ? offered[0] : offered.find((candidate) => candidate.command === wanted);
7702
+ const template = entry && workflow.commands?.[entry.command];
7703
+ return typeof template !== "object" || template.inProcess !== true;
7704
+ };
7705
+ if (steps.some(inspect)) return "This cloud host cannot run interactive CLI workflow steps. Select an in-process command.";
7706
+ }
7631
7707
  /**
7632
7708
  * A step's `runConfig`, validated against the keys Po understands.
7633
7709
  *
@@ -7799,6 +7875,7 @@ function createStepExecutor(dependencies) {
7799
7875
  }
7800
7876
  });
7801
7877
  const script = async (request, secretEnvironment = {}) => {
7878
+ if (runtime.workflowHost.platform === "edge") return failedExecution("Typed stdin child scripts are not available on this cloud host.");
7802
7879
  if (request.interactive || request.template !== void 0) return failedExecution("Only deterministic scripts can receive typed stdin.");
7803
7880
  if (request.command === void 0) return failedExecution("Child script requires a static command.");
7804
7881
  const controller = new AbortController();
@@ -7912,7 +7989,11 @@ function createStepExecutor(dependencies) {
7912
7989
  * prompted with the gate's reminder. The gate counts reminders against its
7913
7990
  * cap, so a stuck agent ends and the engine fails the step.
7914
7991
  */
7915
- async function runSession(request) {
7992
+ function runSession(request) {
7993
+ const durable = dependencies.runtime.workflowHost.durable;
7994
+ return durable?.executeStep ? durable.executeStep(request, (recordRef) => runSessionUntracked(request, recordRef)) : runSessionUntracked(request);
7995
+ }
7996
+ async function runSessionUntracked(request, recordRef) {
7916
7997
  if (prompt === void 0) return failedExecution("This host cannot prompt sessions, so this step cannot run here.");
7917
7998
  if (readExecutionState === void 0) return failedExecution("This host cannot read execution state, so this step cannot run here.");
7918
7999
  const attributes = {
@@ -8014,6 +8095,11 @@ function createStepExecutor(dependencies) {
8014
8095
  environment,
8015
8096
  ...workflowContext === void 0 ? {} : { workflowContext }
8016
8097
  });
8098
+ recordRef?.({
8099
+ kind: STEP_SESSION_REF_KIND,
8100
+ id: scope.sessionId,
8101
+ label: name
8102
+ });
8017
8103
  await request.child?.sessionStarted(scope.sessionId);
8018
8104
  } catch (error) {
8019
8105
  telemetry?.recordError(STEP_SESSION_FAILED_EVENT, error, attributes, { includeException: true });
@@ -8189,6 +8275,7 @@ function createStepExecutor(dependencies) {
8189
8275
  ...request.customRun.systemPrompt === void 0 ? {} : { systemPrompt: request.customRun.systemPrompt }
8190
8276
  });
8191
8277
  },
8278
+ script: dependencies.hostExecutor?.script?.bind(dependencies.hostExecutor),
8192
8279
  async command(request) {
8193
8280
  const template = request.template;
8194
8281
  if (template?.inProcess && prompt !== void 0) return runSession({
@@ -8208,6 +8295,7 @@ function createStepExecutor(dependencies) {
8208
8295
  prompt: template.prompt,
8209
8296
  ...template.systemPrompt === void 0 ? {} : { systemPrompt: template.systemPrompt }
8210
8297
  });
8298
+ if (dependencies.hostExecutor?.command) return dependencies.hostExecutor.command(request);
8211
8299
  const command = request.command;
8212
8300
  if (launchPane === void 0 || command === void 0) return void 0;
8213
8301
  let pane;
@@ -8266,12 +8354,13 @@ async function lastScreen(service, key) {
8266
8354
  * the pane's target. When the step ends or is stopped, its last screen is kept
8267
8355
  * beside the socket and the pane is released, whatever fails on the way.
8268
8356
  */
8269
- function createNativeStepPaneLauncher(runtime, service = new NativeTerminalService$1(runtime), telemetry) {
8357
+ function createNativeStepPaneLauncher(runtime, service, telemetry) {
8270
8358
  const report = (stage) => (error) => telemetry?.recordWarning(STEP_PANE_FAILED_EVENT, error, { stage }) ?? Promise.resolve();
8271
8359
  return async (request) => {
8272
8360
  if (runtime.temporaryDirectory === void 0) throw new Error("Workflow step panes require an admitted temporary directory.");
8273
- if (!await service.available()) return void 0;
8274
- await service.spawn({
8361
+ const terminal = service ??= new NativeTerminalService$1(runtime);
8362
+ if (!await terminal.available()) return void 0;
8363
+ await terminal.spawn({
8275
8364
  command: runtime.workflowHost.shellPath,
8276
8365
  args: ["-c", request.command],
8277
8366
  cwd: request.cwd,
@@ -8282,31 +8371,31 @@ function createNativeStepPaneLauncher(runtime, service = new NativeTerminalServi
8282
8371
  let server;
8283
8372
  try {
8284
8373
  server = await serveNativeTerminal$1(runtime, {
8285
- service,
8374
+ service: terminal,
8286
8375
  runKey: request.id,
8287
8376
  socketPath: target
8288
8377
  });
8289
8378
  } catch (error) {
8290
- await service.kill(request.id).catch(report("kill"));
8379
+ await terminal.kill(request.id).catch(report("kill"));
8291
8380
  throw error;
8292
8381
  }
8293
8382
  let finishing;
8294
8383
  const finish = () => finishing ??= (async () => {
8295
8384
  let screen;
8296
8385
  try {
8297
- screen = await lastScreen(service, request.id);
8386
+ screen = await lastScreen(terminal, request.id);
8298
8387
  if (screen !== void 0) (0, _agimon_ai_po_core_platform.getOrThrow)(await runtime.fs.writeFile(stepPaneLogPath(target), screen, runtime.ioContext));
8299
8388
  } catch (error) {
8300
8389
  await report("keep-screen")(error);
8301
8390
  } finally {
8302
8391
  await server.close().catch(report("close-socket"));
8303
- await service.kill(request.id).catch(report("kill"));
8392
+ await terminal.kill(request.id).catch(report("kill"));
8304
8393
  }
8305
8394
  return screen;
8306
8395
  })();
8307
8396
  return {
8308
8397
  target,
8309
- completion: service.ended(request.id).then(async (exitCode) => {
8398
+ completion: terminal.ended(request.id).then(async (exitCode) => {
8310
8399
  const screen = (await finish())?.trimEnd();
8311
8400
  return screen ? {
8312
8401
  exitCode,
@@ -10786,6 +10875,12 @@ function connectNativeTerminal() {
10786
10875
  }
10787
10876
  //#endregion
10788
10877
  //#region src/services/workflowHost/index.ts
10878
+ const nativeHosts = /* @__PURE__ */ new WeakSet();
10879
+ /** Factory-created native hosts capture per-root environment and directories. */
10880
+ function readBoundWorkflowHost(context) {
10881
+ const host = context.get(require_contract.PO_WORKFLOW_HOST_SERVICE);
10882
+ return host !== void 0 && nativeHosts.has(host) ? void 0 : host;
10883
+ }
10789
10884
  function resolveWorkflowCliPath() {
10790
10885
  const manifest = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("@agimon-ai/po-workflow/package.json");
10791
10886
  return (0, node_path.join)((0, node_path.dirname)(manifest), "dist", "cli.cjs");
@@ -10804,7 +10899,7 @@ function createWorkflowHost(options) {
10804
10899
  (0, node_fs.accessSync)("/bin/zsh", node_fs.constants.X_OK);
10805
10900
  shellPath = "/bin/zsh";
10806
10901
  } catch {}
10807
- return Object.freeze({
10902
+ const host = Object.freeze({
10808
10903
  processId: process.pid,
10809
10904
  executablePath: process.execPath,
10810
10905
  platform: process.platform,
@@ -10901,6 +10996,8 @@ function createWorkflowHost(options) {
10901
10996
  if (process.stdout.isTTY) process.stdout.write("\x1B[0m\x1B[?25h\x1B[?1049l");
10902
10997
  }
10903
10998
  });
10999
+ nativeHosts.add(host);
11000
+ return host;
10904
11001
  }
10905
11002
  async function openArtifact(path) {
10906
11003
  let file;
@@ -13610,7 +13707,7 @@ var RecoverWorkflowService = class {
13610
13707
  if (current.admission?.settlement?.outcome === "abandoned") throw new Error(`Workflow run "${record.workspace}/${record.runKey}" was abandoned and cannot be recovered`);
13611
13708
  const runDir = this.registry.runDirectoryFor(record);
13612
13709
  const paneRefs = (await readWorkflowProgress(this.runtime, runDir)).flatMap((event) => event.ref?.kind === "pane" ? [event.ref.id] : []);
13613
- await new NativeTerminalService$1(this.runtime).killRunPanes(record.runId, paneRefs);
13710
+ if (paneRefs.length) await new NativeTerminalService$1(this.runtime).killRunPanes(record.runId, paneRefs);
13614
13711
  await killRunServices(this.runtime, runDir);
13615
13712
  return await this.recoverClaimed(input, claim.claimId, claim.ownerSessionId, record);
13616
13713
  } catch (error) {
@@ -13842,6 +13939,12 @@ Object.defineProperty(exports, "WorkflowToolsPathSchema", {
13842
13939
  return WorkflowToolsPathSchema;
13843
13940
  }
13844
13941
  });
13942
+ Object.defineProperty(exports, "__toESM", {
13943
+ enumerable: true,
13944
+ get: function() {
13945
+ return __toESM;
13946
+ }
13947
+ });
13845
13948
  Object.defineProperty(exports, "admitWorkflowAllocation", {
13846
13949
  enumerable: true,
13847
13950
  get: function() {
@@ -13854,6 +13957,12 @@ Object.defineProperty(exports, "assertWorkflowAllocationExecution", {
13854
13957
  return assertWorkflowAllocationExecution;
13855
13958
  }
13856
13959
  });
13960
+ Object.defineProperty(exports, "cloudWorkflowLaunchRefusal", {
13961
+ enumerable: true,
13962
+ get: function() {
13963
+ return cloudWorkflowLaunchRefusal;
13964
+ }
13965
+ });
13857
13966
  Object.defineProperty(exports, "connectNativeTerminal", {
13858
13967
  enumerable: true,
13859
13968
  get: function() {
@@ -13926,6 +14035,12 @@ Object.defineProperty(exports, "poTemplateRunConfigSchema", {
13926
14035
  return poTemplateRunConfigSchema;
13927
14036
  }
13928
14037
  });
14038
+ Object.defineProperty(exports, "readBoundWorkflowHost", {
14039
+ enumerable: true,
14040
+ get: function() {
14041
+ return readBoundWorkflowHost;
14042
+ }
14043
+ });
13929
14044
  Object.defineProperty(exports, "readWorkflowCatalog", {
13930
14045
  enumerable: true,
13931
14046
  get: function() {
@@ -14041,4 +14156,4 @@ Object.defineProperty(exports, "workflowShellOutput", {
14041
14156
  }
14042
14157
  });
14043
14158
 
14044
- //# sourceMappingURL=RecoverWorkflowService-7-0W_pJg.cjs.map
14159
+ //# sourceMappingURL=RecoverWorkflowService-Cfx7QB0G.cjs.map