@agimon-ai/po-workflow 0.0.0-alpha.196 → 0.0.0-alpha.198

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.
@@ -19,6 +19,7 @@ let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile
19
19
  let _agimon_ai_po_db = require("@agimon-ai/po-db");
20
20
  let _agimon_ai_po_core_telemetry = require("@agimon-ai/po-core/telemetry");
21
21
  let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
22
+ let _agimon_ai_po_core_locale = require("@agimon-ai/po-core/locale");
22
23
  let node_async_hooks = require("node:async_hooks");
23
24
  let _agimon_ai_po_core_codemode = require("@agimon-ai/po-core/codemode");
24
25
  let _agimon_ai_po_core_delegation = require("@agimon-ai/po-core/delegation");
@@ -3441,38 +3442,38 @@ function duration(run) {
3441
3442
  * copy. A failure, approval wait or pause outranks a run in progress, because
3442
3443
  * it is the one that needs the reader.
3443
3444
  */
3444
- function workflowSessionActivity(runs) {
3445
+ function workflowSessionActivity(runs, t = (_key, fallback, vars) => (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars)) {
3445
3446
  if (runs.length === 0) return void 0;
3446
3447
  const failed = runs.find((run) => run.stage === "error" && !run.waiting);
3447
3448
  if (failed !== void 0) return {
3448
- label: `workflow failed · ${failed.failedJob ?? failed.displayName}`,
3449
+ label: t("workflow.activity.failed", "workflow failed · {job}", { job: failed.failedJob ?? failed.displayName }),
3449
3450
  attention: true
3450
3451
  };
3451
3452
  const waiting = runs.find((run) => run.waiting);
3452
3453
  if (waiting !== void 0) return {
3453
- label: waiting.position === void 0 ? "workflow waiting for approval" : `workflow waiting for approval · ${waiting.position.job}`,
3454
+ label: waiting.position === void 0 ? t("workflow.activity.waiting", "workflow waiting for approval") : t("workflow.activity.waitingAt", "workflow waiting for approval · {job}", { job: waiting.position.job }),
3454
3455
  attention: true
3455
3456
  };
3456
3457
  const paused = runs.find(isPaused);
3457
3458
  if (paused !== void 0) return {
3458
- label: paused.position === void 0 ? "workflow paused" : `workflow paused · ${paused.position.job}`,
3459
+ label: paused.position === void 0 ? t("workflow.activity.paused", "workflow paused") : t("workflow.activity.pausedAt", "workflow paused · {job}", { job: paused.position.job }),
3459
3460
  attention: true
3460
3461
  };
3461
3462
  if (runs.find((run) => run.stage === "running" && run.stale === true) !== void 0) return {
3462
- label: "workflow interrupted",
3463
+ label: t("workflow.activity.interrupted", "workflow interrupted"),
3463
3464
  attention: true
3464
3465
  };
3465
3466
  const running = runs.find((run) => run.stage === "running");
3466
3467
  if (running !== void 0) {
3467
3468
  const where = [running.position?.job, running.position?.step].filter(Boolean).join(" › ");
3468
3469
  return {
3469
- label: where === "" ? "workflow · starting" : `workflow · ${where}`,
3470
+ label: where === "" ? t("workflow.activity.starting", "workflow · starting") : t("workflow.activity.running", "workflow · {where}", { where }),
3470
3471
  since: running.startedAt
3471
3472
  };
3472
3473
  }
3473
- if (runs.every(succeeded)) return { label: "workflow succeeded" };
3474
+ if (runs.every(succeeded)) return { label: t("workflow.activity.succeeded", "workflow succeeded") };
3474
3475
  return {
3475
- label: `workflow ${runs[0].outcome ?? "ended"}`,
3476
+ label: t("workflow.activity.ended", "workflow {outcome}", { outcome: runs[0].outcome ?? t("workflow.activity.endedState", "ended") }),
3476
3477
  attention: true
3477
3478
  };
3478
3479
  }
@@ -3504,34 +3505,59 @@ function workflowSessionBrief(runs) {
3504
3505
  "On a workflow error, diagnose it locally, summarize the cause here, and tell the session that launched it what failed and what it needs with network.send({ to: <launcher>, text, terminal: true, outcome: 'failed' }), or outcome 'blocked' when only they can unblock it. Do not automatically restart it or diagnose a user-requested stop. When the user or launcher session asks: use workflow.status with the runKey and workspace for progress, workflow.recoveryEvidence to read a failure, and load codemode-how-to-workflow before workflow.recover. Without code mode, use workflow_run status and workflow_tools recovery-evidence/recover instead. Recover, pause, resume or stop a run only when the user asks or the launcher explicitly delegates it through intercom."
3505
3506
  ].join("\n");
3506
3507
  }
3507
- function failureNotice(run) {
3508
- const cause = (run.errorMessage ?? "the run ended in the error stage").slice(0, MAX_CAUSE).replace(/\.$/, "");
3509
- const job = run.failedJob === void 0 ? "" : ` at job "${run.failedJob}"`;
3508
+ function failureNotice(run, t) {
3509
+ const cause = (run.errorMessage ?? t("workflow.notice.errorStage", "the run ended in the error stage")).slice(0, MAX_CAUSE).replace(/\.$/, "");
3510
+ const body = run.failedJob === void 0 ? t("workflow.notice.failedBody", "Workflow \"{name}\" failed: {cause}. Ask me to diagnose or recover it.", {
3511
+ name: run.displayName,
3512
+ cause
3513
+ }) : t("workflow.notice.failedAtBody", "Workflow \"{name}\" failed at job \"{job}\": {cause}. Ask me to diagnose or recover it.", {
3514
+ name: run.displayName,
3515
+ job: run.failedJob,
3516
+ cause
3517
+ });
3510
3518
  return {
3511
- title: "Workflow failed",
3512
- body: `Workflow "${run.displayName}" failed${job}: ${cause}. Ask me to diagnose or recover it.`,
3519
+ title: t("workflow.notice.failedTitle", "Workflow failed"),
3520
+ body,
3513
3521
  level: "error"
3514
3522
  };
3515
3523
  }
3516
3524
  /** A parked run is not a failure: it carries on by itself once the person answers. */
3517
- function waitingNotice(run) {
3525
+ function waitingNotice(run, t) {
3518
3526
  const step = run.position?.step ?? run.jobs.flatMap((job) => job.steps).find((item) => item.status === "running")?.name;
3527
+ const body = step === void 0 ? t("workflow.notice.waitingBody", "Workflow \"{name}\" is waiting for your approval. It carries on once you answer.", { name: run.displayName }) : t("workflow.notice.waitingAtBody", "Workflow \"{name}\" is waiting for your approval at \"{step}\". It carries on once you answer.", {
3528
+ name: run.displayName,
3529
+ step
3530
+ });
3519
3531
  return {
3520
- title: "Workflow waiting for approval",
3521
- body: `Workflow "${run.displayName}" is waiting for your approval${step === void 0 ? "" : ` at "${step}"`}. It carries on once you answer.`,
3532
+ title: t("workflow.notice.waitingTitle", "Workflow waiting for approval"),
3533
+ body,
3522
3534
  level: "info"
3523
3535
  };
3524
3536
  }
3525
- function finishNotice(run) {
3537
+ function finishNotice(run, t) {
3526
3538
  const took = duration(run);
3527
- if (succeeded(run)) return {
3528
- title: "Workflow succeeded",
3529
- body: `Workflow "${run.displayName}" ${run.outcome === "skipped" ? "was skipped" : "succeeded"}${took === void 0 ? "" : ` in ${took}`}.`,
3530
- level: "info"
3531
- };
3539
+ if (succeeded(run)) {
3540
+ const skipped = run.outcome === "skipped";
3541
+ const body = took === void 0 ? skipped ? t("workflow.notice.skippedBody", "Workflow \"{name}\" was skipped.", { name: run.displayName }) : t("workflow.notice.succeededBody", "Workflow \"{name}\" succeeded.", { name: run.displayName }) : took === "under a minute" ? skipped ? t("workflow.notice.skippedQuickBody", "Workflow \"{name}\" was skipped in under a minute.", { name: run.displayName }) : t("workflow.notice.succeededQuickBody", "Workflow \"{name}\" succeeded in under a minute.", { name: run.displayName }) : skipped ? t("workflow.notice.skippedTimedBody", "Workflow \"{name}\" was skipped in {duration}.", {
3542
+ name: run.displayName,
3543
+ duration: took
3544
+ }) : t("workflow.notice.succeededTimedBody", "Workflow \"{name}\" succeeded in {duration}.", {
3545
+ name: run.displayName,
3546
+ duration: took
3547
+ });
3548
+ return {
3549
+ title: t("workflow.notice.succeededTitle", "Workflow succeeded"),
3550
+ body,
3551
+ level: "info"
3552
+ };
3553
+ }
3554
+ const body = run.outcome === void 0 ? t("workflow.notice.noOutcomeBody", "Workflow \"{name}\" ended: no outcome recorded. Ask me to look into it.", { name: run.displayName }) : t("workflow.notice.endedBody", "Workflow \"{name}\" ended: {outcome}. Ask me to look into it.", {
3555
+ name: run.displayName,
3556
+ outcome: run.outcome
3557
+ });
3532
3558
  return {
3533
- title: "Workflow ended",
3534
- body: `Workflow "${run.displayName}" ended: ${run.outcome ?? "no outcome recorded"}. Ask me to look into it.`,
3559
+ title: t("workflow.notice.endedTitle", "Workflow ended"),
3560
+ body,
3535
3561
  level: "error"
3536
3562
  };
3537
3563
  }
@@ -3554,6 +3580,7 @@ function diagnoseText(run, launcher) {
3554
3580
  * remove it.
3555
3581
  */
3556
3582
  function createWorkflowSessionLifecycle(deps) {
3583
+ const t = deps.translate ?? ((_key, fallback, vars) => (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars));
3557
3584
  const stages = /* @__PURE__ */ new Map();
3558
3585
  let seeded = false;
3559
3586
  let attention = false;
@@ -3621,7 +3648,7 @@ function createWorkflowSessionLifecycle(deps) {
3621
3648
  return {
3622
3649
  async observe(runs) {
3623
3650
  if (disposed) return;
3624
- deps.publishActivity?.(workflowSessionActivity(runs));
3651
+ deps.publishActivity?.(workflowSessionActivity(runs, deps.translate));
3625
3652
  if (runs.some(needsAttention)) attention = true;
3626
3653
  if (!seeded) {
3627
3654
  for (const run of runs) stages.set(identity(run), run.stage);
@@ -3634,10 +3661,10 @@ function createWorkflowSessionLifecycle(deps) {
3634
3661
  stages.set(identity(run), run.stage);
3635
3662
  if (previous === run.stage || run.launcherSessionId === void 0) continue;
3636
3663
  if (run.stage === "error") {
3637
- await deps.postNotice(run.waiting ? waitingNotice(run) : failureNotice(run));
3664
+ await deps.postNotice(run.waiting ? waitingNotice(run, t) : failureNotice(run, t));
3638
3665
  if (!run.waiting) await report(run);
3639
3666
  } else if (run.stage === "completed") {
3640
- await deps.postNotice(finishNotice(run));
3667
+ await deps.postNotice(finishNotice(run, t));
3641
3668
  await report(run);
3642
3669
  finished = true;
3643
3670
  }
@@ -11506,14 +11533,14 @@ function defaultCatalogDeps(runtime) {
11506
11533
  const parser = new require_workflowHost.WorkflowParserService(runtime);
11507
11534
  return {
11508
11535
  list: (directory) => readWorkflowCatalog(directory, runtime),
11509
- summarize: async (workflowPath) => {
11510
- const detail = await summarizeWorkflow(workflowPath, (target) => parser.parseWorkflowFile(target));
11536
+ summarize: async (workflowPath, definition) => {
11537
+ const detail = await summarizeWorkflow(workflowPath, async (target) => definition ? structuredClone(definition) : parser.parseWorkflowFile(target));
11511
11538
  if (detail.error !== void 0) return detail;
11512
11539
  const errors = (await diagnoseWorkflow(workflowPath, {
11513
11540
  runtime,
11514
11541
  runConfigKeys: PO_RUN_CONFIG_KEYS,
11515
11542
  renamedRunConfigKeys: RENAMED_RUN_CONFIG_KEYS
11516
- })).diagnostics.filter((diagnostic) => diagnostic.level === "error");
11543
+ }, definition)).diagnostics.filter((diagnostic) => diagnostic.level === "error");
11517
11544
  if (errors.length === 0) return detail;
11518
11545
  return {
11519
11546
  ...detail,
@@ -15937,9 +15964,10 @@ var RunWorkflowService = class {
15937
15964
  * Execute the workflow after signal handlers are installed.
15938
15965
  */
15939
15966
  async prepareAllocation(input) {
15940
- const saved = input.recovery?.definition;
15967
+ const saved = input.recovery?.definition ?? input.definition;
15968
+ const pinned = input.recovery === void 0 && input.definition !== void 0;
15941
15969
  const path = (0, node_path.resolve)(this.runtime.cwd, input.workflowPath);
15942
- return this.admitAllocationForWorkflow(input, saved && (input.helpActive?.() !== true || !await this.pathExists(path)) ? structuredClone(saved) : await this.parser.parseWorkflowFile(path));
15970
+ return this.admitAllocationForWorkflow(input, saved && (pinned || input.helpActive?.() !== true || !await this.pathExists(path)) ? structuredClone(saved) : await this.parser.parseWorkflowFile(path));
15943
15971
  }
15944
15972
  async admitAllocationForWorkflow(input, workflow) {
15945
15973
  const expected = input.allocation ?? input.admission?.allocation;
@@ -15970,9 +15998,10 @@ var RunWorkflowService = class {
15970
15998
  }
15971
15999
  async executeWorkflow(input, dryRun, continueOnError) {
15972
16000
  const workflowPath = (0, node_path.resolve)(this.runtime.cwd, input.workflowPath);
15973
- let saved = input.recovery?.definition;
16001
+ let saved = input.recovery?.definition ?? input.definition;
16002
+ const pinned = input.recovery === void 0 && input.definition !== void 0;
15974
16003
  const readDefinition = async (path) => {
15975
- if (saved && (input.helpActive?.() !== true || !await this.pathExists(path))) return structuredClone(saved);
16004
+ if (saved && (pinned || input.helpActive?.() !== true || !await this.pathExists(path))) return structuredClone(saved);
15976
16005
  const parsed = await this.parser.parseWorkflowFile(path);
15977
16006
  if (saved) saved = structuredClone(parsed);
15978
16007
  return parsed;
@@ -19370,7 +19399,7 @@ function untilAborted(work, signal) {
19370
19399
  work.then(resolveWork, rejectWork).finally(() => signal.removeEventListener("abort", onAbort));
19371
19400
  });
19372
19401
  }
19373
- function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets, children, resolveIdentity, outcome) {
19402
+ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets, children, resolveIdentity, outcome, translate) {
19374
19403
  if (serverHost.context.directEvents === void 0) throw new Error("Workflow server plugin requires the session direct event bus.");
19375
19404
  const directEvents = serverHost.context.directEvents;
19376
19405
  const environment = host.context.environment;
@@ -19413,6 +19442,16 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
19413
19442
  if (source === void 0) throw new Error(WORKFLOW_SOURCE_UNAVAILABLE);
19414
19443
  return source;
19415
19444
  };
19445
+ /**
19446
+ * The launching session's own copy of a definition. A session in the workspace's checkout reads the registered
19447
+ * source; a session in another checkout of the repository (a worktree) reads its own checkout instead.
19448
+ */
19449
+ const definitionPath = (definition) => {
19450
+ const source = sourceNamed(definition.source);
19451
+ const fromSession = (0, node_path.relative)(host.context.repoRoot, source.directory);
19452
+ const elsewhere = source.source === REPO_SOURCE && (fromSession.startsWith("..") || (0, node_path.isAbsolute)(fromSession));
19453
+ return (0, node_path.resolve)(elsewhere ? host.context.cwd : source.directory, definition.key);
19454
+ };
19416
19455
  const workflowRuns = {
19417
19456
  async readConfig(id) {
19418
19457
  if (disposed) return void 0;
@@ -19483,13 +19522,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
19483
19522
  const communication = serverHost.context.sessionCommunication;
19484
19523
  const lifecycle = workflowSession ? createWorkflowSessionLifecycle({
19485
19524
  parentSessionId: host.context.sessionContext?.parentSessionId,
19525
+ translate,
19486
19526
  publishActivity: (activity) => serverHost.context.publishActivity?.(activity),
19487
19527
  postNotice: async (notice) => {
19488
- const data = (0, _agimon_ai_po_core_notification.createPoNotificationEntryData)({
19489
- title: notice.title,
19490
- body: notice.body,
19491
- level: notice.level
19492
- });
19528
+ const data = (0, _agimon_ai_po_core_notification.createPoNotificationEntryData)(notice);
19493
19529
  if (data !== void 0) await host.context.session.appendCustomEntry(_agimon_ai_po_core_notification.PO_NOTIFICATION_ENTRY_TYPE, data);
19494
19530
  },
19495
19531
  isIdle: async () => {
@@ -19823,10 +19859,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
19823
19859
  const stored = require_contract.librarySourceOf(workflowPath, runtime.library);
19824
19860
  const inside = stored ? require_contract.workflowDefinitionRef(workflowPath, where.repoRoot, runtime.library).key : (0, node_path.relative)(where.repoRoot, workflowPath);
19825
19861
  if (!stored && (inside.startsWith("..") || (0, node_path.isAbsolute)(inside))) return `Workflow ${input.workflowPath} is outside this session's repository, so it cannot be launched here.`;
19826
- const detail = await catalogDeps.summarize(workflowPath);
19862
+ const detail = await catalogDeps.summarize(workflowPath, input.definition);
19827
19863
  if (detail.error !== void 0) return needsFixingNotice(inside, detail.error);
19828
19864
  if (runtime.workflowHost.platform === "edge") {
19829
- const refusal = cloudWorkflowLaunchRefusal(await feature.parser.parseWorkflowFile(workflowPath), input);
19865
+ const refusal = cloudWorkflowLaunchRefusal(input.definition ?? await feature.parser.parseWorkflowFile(workflowPath), input);
19830
19866
  if (refusal !== void 0) return refusal;
19831
19867
  }
19832
19868
  const requirements = preparing ? {
@@ -20365,13 +20401,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20365
20401
  const admissionInput = async (request) => {
20366
20402
  if (request.kind === "launch") {
20367
20403
  if (!typebox_value.Value.Check(_agimon_ai_po_core_workflow.PoWorkflowDefinitionRefSchema, request.definition)) throw new Error(INVALID_WORKFLOW_REFERENCE);
20368
- const source = sourceNamed(request.definition.source);
20369
- const { policy: _policy, targetSessionId, allocation: _allocation, ...overrides } = request.overrides ?? {};
20370
- const directory = targetSessionId === void 0 || source.source !== REPO_SOURCE ? source.directory : publicServices?.owner(targetSessionId)?.location.repoRoot;
20371
- if (directory === void 0) throw new Error("Workflow target session is unavailable.");
20404
+ const { policy: _policy, targetSessionId: _target, allocation: _allocation, ...overrides } = request.overrides ?? {};
20372
20405
  return feature.runTool.getInputSchema().parse({
20373
20406
  ...overrides,
20374
- workflowPath: (0, node_path.resolve)(directory, request.definition.key)
20407
+ workflowPath: definitionPath(request.definition)
20375
20408
  });
20376
20409
  }
20377
20410
  if (request.kind !== "recover") throw new Error("Invalid workflow admission request.");
@@ -20394,7 +20427,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20394
20427
  warnings: [],
20395
20428
  deferred: []
20396
20429
  };
20397
- const where = owner?.location ?? host.context;
20430
+ const where = request.kind === "launch" && request.definition?.source === REPO_SOURCE ? host.context : owner?.location ?? host.context;
20398
20431
  let input;
20399
20432
  try {
20400
20433
  input = await admissionInput(request);
@@ -20450,10 +20483,9 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20450
20483
  async requirements(definition, options = {}) {
20451
20484
  assertAvailable();
20452
20485
  if (!typebox_value.Value.Check(_agimon_ai_po_core_workflow.PoWorkflowDefinitionRefSchema, definition)) throw new Error(INVALID_WORKFLOW_REFERENCE);
20453
- const source = sourceNamed(definition.source);
20454
20486
  return operations.requirements({
20455
20487
  ...options,
20456
- workflowPath: (0, node_path.resolve)(source.directory, definition.key)
20488
+ workflowPath: definitionPath(definition)
20457
20489
  }, host.context.cwd, void 0, definition);
20458
20490
  },
20459
20491
  registerPolicy(coordinator, callback, options) {
@@ -20497,7 +20529,12 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20497
20529
  const owner = publicServices?.owner(ownerId);
20498
20530
  if (!owner) throw new Error("Workflow launch owner is unavailable; admission remains pending.");
20499
20531
  watchOwner(ownerId);
20500
- await owner.launch(input, {
20532
+ const pinned = request.kind === "launch" && request.definition.source === REPO_SOURCE ? {
20533
+ ...input,
20534
+ workflowPath: (0, node_path.resolve)(owner.location.repoRoot, request.definition.key),
20535
+ definition: await feature.parser.parseWorkflowFile(input.workflowPath)
20536
+ } : input;
20537
+ await owner.launch(pinned, {
20501
20538
  ...admission,
20502
20539
  ownerSessionId: ownerId
20503
20540
  });
@@ -20673,10 +20710,9 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20673
20710
  scope.provide(_agimon_ai_po_core_workflow.PO_WORKFLOW_LAUNCH_SERVICE, { async launch(definition, overrides = {}) {
20674
20711
  await waitForReadiness();
20675
20712
  if (!typebox_value.Value.Check(_agimon_ai_po_core_workflow.PoWorkflowDefinitionRefSchema, definition)) throw new Error(INVALID_WORKFLOW_REFERENCE);
20676
- const source = sourceNamed(definition.source);
20677
20713
  const result = await launch({
20678
20714
  ...overrides,
20679
- workflowPath: (0, node_path.resolve)(source.directory, definition.key),
20715
+ workflowPath: definitionPath(definition),
20680
20716
  env: {
20681
20717
  ...overrides.env,
20682
20718
  [PUBLIC_LAUNCH_ENV]: PUBLIC_LAUNCH_ENABLED
@@ -21189,7 +21225,7 @@ var index_server_default = (async (mountContext) => {
21189
21225
  await toolsProvider.await();
21190
21226
  if (!mounted) throw new Error("Workflow jobTools requires code mode in this managed step session.");
21191
21227
  }
21192
- const plugin = agent ? createWorkflowServerRuntime(agent, host, admitted, resolveSecrets, workflow?.children, resolveIdentity, workflow?.outcome) : { api: [createWorkflowApi(admitted)] };
21228
+ const plugin = agent ? createWorkflowServerRuntime(agent, host, admitted, resolveSecrets, workflow?.children, resolveIdentity, workflow?.outcome, (key, fallback, vars) => (0, _agimon_ai_po_core_locale.readPoLang)(context)?.t((0, _agimon_ai_po_core_locale.readPoPersonLocale)(context)?.read(), key, fallback, vars) ?? (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars)) : { api: [createWorkflowApi(admitted)] };
21193
21229
  let disposeTracker;
21194
21230
  let cleanup;
21195
21231
  disposeRuntime = () => cleanup ??= Promise.resolve().then(async () => {