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

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(),
@@ -1049,6 +1075,14 @@ function summarizeWorkflowProgress(events) {
1049
1075
  return [...jobs.values()];
1050
1076
  }
1051
1077
  //#endregion
1078
+ //#region src/types/webWorkflows.ts
1079
+ /** A customRun step ran as this child session. */
1080
+ const STEP_SESSION_REF_KIND = "session";
1081
+ /** A command step ran in this terminal pane. */
1082
+ const STEP_PANE_REF_KIND = "pane";
1083
+ const WORKFLOW_RUNS_TYPE = "workflow_runs";
1084
+ const WORKFLOW_CATALOG_TYPE = "workflow_catalog";
1085
+ //#endregion
1052
1086
  //#region src/models/InvalidWorkflowRunRecordError.ts
1053
1087
  /**
1054
1088
  * Structured error raised when a persisted workflow run record is malformed.
@@ -1362,6 +1396,7 @@ var WorkflowRegistryService = class {
1362
1396
  stale: DEFAULT_RECOVERY_CLAIM_TTL_MS
1363
1397
  });
1364
1398
  try {
1399
+ this.runtime.workflowHost.durable?.assertOwnership();
1365
1400
  return await action();
1366
1401
  } finally {
1367
1402
  await release();
@@ -1529,7 +1564,7 @@ var WorkflowRegistryService = class {
1529
1564
  },
1530
1565
  stage: RUNNING_STAGE,
1531
1566
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1532
- pid: input.pid ?? this.runtime.workflowHost.processId,
1567
+ ...this.runtime.workflowHost.durable ? { hostOwner: this.runtime.workflowHost.durable.owner } : { pid: input.pid ?? this.runtime.workflowHost.processId },
1533
1568
  workflowPath: input.workflowPath,
1534
1569
  workflowId: input.workflowId,
1535
1570
  workflowName: input.workflowName,
@@ -1834,6 +1869,7 @@ var WorkflowRegistryService = class {
1834
1869
  };
1835
1870
  }
1836
1871
  async writeAtomic(path, value) {
1872
+ this.runtime.workflowHost.durable?.assertOwnership();
1837
1873
  await (0, _agimon_ai_po_core_platform.writeFileAtomic)(this.runtime.fs, path, `${JSON.stringify(value, null, 2)}\n`, this.runtime.ioContext);
1838
1874
  }
1839
1875
  /** Publish complete JSON without ever exposing a partially written capability. */
@@ -1887,7 +1923,7 @@ var WorkflowRegistryService = class {
1887
1923
  claimId: (0, node_crypto.randomUUID)(),
1888
1924
  claimedAt: (/* @__PURE__ */ new Date()).toISOString(),
1889
1925
  ownerSessionId: ownerSessionId?.trim() || void 0,
1890
- pid: this.runtime.workflowHost.processId
1926
+ ...this.runtime.workflowHost.durable ? { hostOwner: this.runtime.workflowHost.durable.owner } : { pid: this.runtime.workflowHost.processId }
1891
1927
  };
1892
1928
  const claimPath = (0, node_path.resolve)(errorDir, RECOVERY_CLAIM_FILENAME);
1893
1929
  const releaseLock = await this.acquireRecoveryClaimLock(errorDir).catch((error) => {
@@ -1925,7 +1961,7 @@ var WorkflowRegistryService = class {
1925
1961
  const adoption = {
1926
1962
  adoptedAt: (/* @__PURE__ */ new Date()).toISOString(),
1927
1963
  claimId,
1928
- pid: this.runtime.workflowHost.processId
1964
+ ...this.runtime.workflowHost.durable ? { hostOwner: this.runtime.workflowHost.durable.owner } : { pid: this.runtime.workflowHost.processId }
1929
1965
  };
1930
1966
  const adoptionPath = (0, node_path.resolve)(errorDir, RECOVERY_ADOPTION_FILENAME);
1931
1967
  const releaseLock = await this.acquireRecoveryClaimLock(errorDir);
@@ -1994,7 +2030,7 @@ var WorkflowRegistryService = class {
1994
2030
  let deadAdoption;
1995
2031
  try {
1996
2032
  const adoption = await this.readRecoveryAdoption(adoptionPath);
1997
- if (this.isProcessAlive(adoption.pid)) return false;
2033
+ if (this.isOwnerAlive(adoption)) return false;
1998
2034
  deadAdoption = adoption;
1999
2035
  } catch (error) {
2000
2036
  if (!["ENOENT", "not_found"].includes(String(error.code))) throw error;
@@ -2010,7 +2046,7 @@ var WorkflowRegistryService = class {
2010
2046
  if (deadAdoption && deadAdoption.claimId !== claim.claimId) return false;
2011
2047
  const claimedAt = Date.parse(claim.claimedAt);
2012
2048
  const expired = !Number.isFinite(claimedAt) || Date.now() - claimedAt >= this.recoveryClaimTtlMs;
2013
- if (!deadAdoption && this.isProcessAlive(claim.pid) && !expired) return false;
2049
+ if (!deadAdoption && this.isOwnerAlive(claim) && !expired) return false;
2014
2050
  try {
2015
2051
  if ((await this.readRecoveryClaim(claimPath)).claimId !== claim.claimId) return false;
2016
2052
  (0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.remove(claimPath, void 0, this.runtime.ioContext));
@@ -2025,14 +2061,14 @@ var WorkflowRegistryService = class {
2025
2061
  const value = JSON.parse((0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.readTextFile(path, this.runtime.ioContext)));
2026
2062
  if (!value || typeof value !== "object") throw new Error(`Invalid workflow recovery claim: ${path}`);
2027
2063
  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}`);
2064
+ 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
2065
  return claim;
2030
2066
  }
2031
2067
  async readRecoveryAdoption(path) {
2032
2068
  const value = JSON.parse((0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.readTextFile(path, this.runtime.ioContext)));
2033
2069
  if (!value || typeof value !== "object") throw new Error(`Invalid workflow recovery adoption: ${path}`);
2034
2070
  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}`);
2071
+ if (typeof adoption.claimId !== "string" || typeof adoption.adoptedAt !== "string" || !this.validOwner(adoption)) throw new Error(`Invalid workflow recovery adoption: ${path}`);
2036
2072
  return adoption;
2037
2073
  }
2038
2074
  /**
@@ -2140,11 +2176,14 @@ var WorkflowRegistryService = class {
2140
2176
  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
2177
  const adoption = current.files[RECOVERY_ADOPTION_FILENAME];
2142
2178
  if (adoption !== void 0 && !input.remove?.includes(RECOVERY_ADOPTION_FILENAME)) {
2143
- let pid;
2179
+ let owner = {};
2144
2180
  try {
2145
- pid = JSON.parse(adoption).pid;
2181
+ owner = JSON.parse(adoption);
2146
2182
  } 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}.`);
2183
+ if (this.validOwner(owner) && this.isOwnerAlive(owner)) {
2184
+ const identity = owner.hostOwner ? "a durable owner" : `process ${owner.pid}`;
2185
+ throw new Error(`Workflow run ${input.workspace}/${input.runKey} is being recovered by ${identity}.`);
2186
+ }
2148
2187
  }
2149
2188
  let record;
2150
2189
  let targetDir = runDir;
@@ -2198,7 +2237,7 @@ var WorkflowRegistryService = class {
2198
2237
  return {
2199
2238
  ...state,
2200
2239
  record,
2201
- ...record.pid ? { pidAlive: this.isProcessAlive(record.pid) } : {}
2240
+ ...record.pid || record.hostOwner ? { pidAlive: this.isOwnerAlive(record) } : {}
2202
2241
  };
2203
2242
  } catch (error) {
2204
2243
  return {
@@ -2249,7 +2288,7 @@ var WorkflowRegistryService = class {
2249
2288
  const recordPath = (0, node_path.resolve)(stageDir, entry.name, RUN_RECORD_FILENAME$1);
2250
2289
  if (!await this.pathExists(recordPath)) continue;
2251
2290
  const record = await this.readRunRecord(recordPath).catch(() => null);
2252
- if (!record || record.pid && this.isProcessAlive(record.pid)) alive++;
2291
+ if (!record || (record.pid || record.hostOwner) && this.isOwnerAlive(record)) alive++;
2253
2292
  }
2254
2293
  return alive;
2255
2294
  }
@@ -2271,7 +2310,7 @@ var WorkflowRegistryService = class {
2271
2310
  if (!await this.pathExists(recordPath)) continue;
2272
2311
  const record = await this.inspectReconcilableRunningRecord(workspaceName, entry.name);
2273
2312
  if (!record) continue;
2274
- const unmovedTerminal = record.stage !== RUNNING_STAGE && !!record.pid && !this.isProcessAlive(record.pid);
2313
+ const unmovedTerminal = record.stage !== RUNNING_STAGE && !!(record.pid || record.hostOwner) && !this.isOwnerAlive(record);
2275
2314
  if (record.stale || unmovedTerminal) reconciled.push(await this.reconcileStaleRunningRecord(workspaceName, entry.name));
2276
2315
  }
2277
2316
  }
@@ -2350,13 +2389,13 @@ var WorkflowRegistryService = class {
2350
2389
  async inspectRunningRecord(workspace, runKey) {
2351
2390
  const runningRecordPath = (0, node_path.resolve)(this.getRunDirectory(workspace, RUNNING_STAGE, runKey), RUN_RECORD_FILENAME$1);
2352
2391
  const currentRecord = await this.readRunRecord(runningRecordPath);
2353
- if (currentRecord.stage !== RUNNING_STAGE || !currentRecord.pid || this.isProcessAlive(currentRecord.pid)) return currentRecord;
2392
+ if (currentRecord.stage !== RUNNING_STAGE || !(currentRecord.pid || currentRecord.hostOwner) || this.isOwnerAlive(currentRecord)) return currentRecord;
2354
2393
  return {
2355
2394
  ...currentRecord,
2356
2395
  effectiveOutcome: "interrupted",
2357
2396
  effectiveStage: ERROR_STAGE$2,
2358
2397
  stale: true,
2359
- staleReason: `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`
2398
+ staleReason: this.runtime.workflowHost.durable?.interruptionReason?.(currentRecord.runKey) ?? `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`
2360
2399
  };
2361
2400
  }
2362
2401
  /**
@@ -2406,7 +2445,7 @@ var WorkflowRegistryService = class {
2406
2445
  if (expected.stop) throw new Error(`Workflow run ownership changed: ${workspace}/${runKey}`);
2407
2446
  return currentRecord;
2408
2447
  }
2409
- if (!currentRecord.pid || this.isProcessAlive(currentRecord.pid)) {
2448
+ if (!(currentRecord.pid || currentRecord.hostOwner) || this.isOwnerAlive(currentRecord)) {
2410
2449
  if (expected?.stop) throw new Error(`Workflow process is not known to be dead: ${workspace}/${runKey}`);
2411
2450
  return currentRecord;
2412
2451
  }
@@ -2425,15 +2464,16 @@ var WorkflowRegistryService = class {
2425
2464
  return currentRecord;
2426
2465
  }
2427
2466
  const errorDir = this.getRunDirectory(workspace, ERROR_STAGE$2, runKey);
2467
+ const interruption = this.runtime.workflowHost.durable?.interruptionReason?.(currentRecord.runKey);
2428
2468
  const finalRecord = {
2429
2469
  ...currentRecord,
2430
- errorMessage: `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`,
2470
+ errorMessage: interruption ?? `${STALE_RUNNING_ERROR_PREFIX}: pid ${currentRecord.pid}`,
2431
2471
  exitCode: INTERRUPTED_EXIT_CODE$1,
2432
2472
  failedJob: currentRecord.executionCursor?.job ?? currentRecord.failedJob,
2433
2473
  finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
2434
2474
  outcome: "interrupted",
2435
2475
  stage: ERROR_STAGE$2,
2436
- ...expected?.stop ? { resume: void 0 } : {}
2476
+ ...expected?.stop || interruption ? { resume: void 0 } : {}
2437
2477
  };
2438
2478
  await this.writeRunRecord(runningRecordPath, finalRecord);
2439
2479
  (0, _agimon_ai_po_core_platform.getOrThrow)(await this.runtime.fs.remove(errorDir, {
@@ -2467,8 +2507,13 @@ var WorkflowRegistryService = class {
2467
2507
  * Persist a run record with stable formatting.
2468
2508
  */
2469
2509
  async writeRunRecord(recordPath, record) {
2510
+ const durable = this.runtime.workflowHost.durable;
2511
+ if (record.runId && record.stage === RUNNING_STAGE) await durable?.setRunActive?.(record.runId, true);
2470
2512
  await this.writeAtomic(recordPath, record);
2471
- if (record.stage !== RUNNING_STAGE) await this.preserveRunEvidence(record, (0, node_path.dirname)(recordPath));
2513
+ if (record.stage !== RUNNING_STAGE) {
2514
+ await this.preserveRunEvidence(record, (0, node_path.dirname)(recordPath));
2515
+ if (record.runId) await durable?.setRunActive?.(record.runId, false);
2516
+ }
2472
2517
  }
2473
2518
  /**
2474
2519
  * Validate the persisted run record shape before returning it to callers.
@@ -2538,9 +2583,18 @@ var WorkflowRegistryService = class {
2538
2583
  slugifySegment(value, fallback) {
2539
2584
  return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, SLUG_SEPARATOR).replace(/^-+|-+$/g, "") || fallback;
2540
2585
  }
2541
- /**
2542
- * Check whether a locally tracked process still exists.
2543
- */
2586
+ validOwner(value) {
2587
+ if (!value || typeof value !== "object") return false;
2588
+ const owner = value.hostOwner;
2589
+ 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;
2590
+ }
2591
+ isOwnerAlive(value) {
2592
+ const durable = this.runtime.workflowHost.durable;
2593
+ if (durable) return value.hostOwner !== void 0 && durable.isOwnerAlive(value.hostOwner);
2594
+ if (value.hostOwner !== void 0) return true;
2595
+ return value.pid !== void 0 && this.isProcessAlive(value.pid);
2596
+ }
2597
+ /** Check whether a locally tracked native process still exists. */
2544
2598
  isProcessAlive(pid) {
2545
2599
  try {
2546
2600
  this.runtime.workflowHost.signal(pid, 0);
@@ -3638,14 +3692,6 @@ async function summarizeWorkflow(workflowPath, parse) {
3638
3692
  }
3639
3693
  }
3640
3694
  //#endregion
3641
- //#region src/types/webWorkflows.ts
3642
- /** A customRun step ran as this child session. */
3643
- const STEP_SESSION_REF_KIND = "session";
3644
- /** A command step ran in this terminal pane. */
3645
- const STEP_PANE_REF_KIND = "pane";
3646
- const WORKFLOW_RUNS_TYPE = "workflow_runs";
3647
- const WORKFLOW_CATALOG_TYPE = "workflow_catalog";
3648
- //#endregion
3649
3695
  //#region src/services/RunDirectoryService/index.ts
3650
3696
  /** Which job and step last wrote each declared entry, one change per line. */
3651
3697
  const RUN_DIRECTORY_WRITES_FILENAME = "writes.ndjson";
@@ -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-CuiDaGMq.cjs.map