@agimon-ai/po-workflow 0.0.0-alpha.69 → 0.0.0-alpha.70

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.
@@ -6147,90 +6147,6 @@ declare const workflow: {
6147
6147
  repairRun(input: WorkflowRepairInput): Promise<WorkflowRunState>;
6148
6148
  };`;
6149
6149
  //#endregion
6150
- //#region src/services/workflowNamespace/index.ts
6151
- const clip = (value, max) => value.length > max ? `${value.slice(0, max - 1)}…` : value;
6152
- /** What the person approves: never the record body, which may carry env values. */
6153
- function describeRepair(input) {
6154
- const parsed = WorkflowRepairRunSchema.safeParse(input);
6155
- if (!parsed.success) return {
6156
- title: "Repair a workflow run (invalid request)",
6157
- summary: clip(parsed.error.message, 600)
6158
- };
6159
- const repair = parsed.data;
6160
- const nextStage = typeof repair.record?.stage === "string" ? repair.record.stage : repair.stage;
6161
- const changes = [
6162
- repair.record ? `rewrite run.json${nextStage === repair.stage ? "" : ` and move it to ${nextStage}`}` : "",
6163
- repair.fix === null ? "remove fix.md" : repair.fix !== void 0 ? "rewrite fix.md" : "",
6164
- repair.remove?.length ? `remove ${repair.remove.join(", ")}` : ""
6165
- ].filter(Boolean);
6166
- return {
6167
- title: clip(`Repair workflow run ${repair.runKey}`, 120),
6168
- summary: clip(`${repair.force ? "Force a repair of" : "Repair"} the ${repair.stage} run ${repair.runKey} in ${repair.workspace}: ${changes.join("; ") || "no change"}. A backup of every replaced file is kept in the run directory.`, 600),
6169
- details: [
6170
- {
6171
- label: "Reason",
6172
- value: clip(repair.reason, 300)
6173
- },
6174
- {
6175
- label: "Workspace",
6176
- value: clip(repair.workspace, 300)
6177
- },
6178
- {
6179
- label: "Stage",
6180
- value: nextStage === repair.stage ? repair.stage : `${repair.stage} → ${nextStage}`
6181
- },
6182
- ...repair.fix ? [{
6183
- label: "fix.md",
6184
- value: clip(repair.fix, 300)
6185
- }] : [],
6186
- ...repair.force ? [{
6187
- label: "Force",
6188
- value: "Repairs even though the run process is still alive."
6189
- }] : []
6190
- ]
6191
- };
6192
- }
6193
- /** A run borrows the session's operations; ending exec never stops a committed workflow. */
6194
- function createWorkflowNamespace(options) {
6195
- return {
6196
- name: "workflow",
6197
- summary: "Discover and launch YAML workflows, inspect their runs, request generation-checked controls, and recover failed runs from evidence.",
6198
- declarations: WORKFLOW_DECLARATIONS,
6199
- portable: true,
6200
- approval: { repairRun: {
6201
- requirement: "human",
6202
- describe: describeRepair
6203
- } },
6204
- bind(run) {
6205
- if (run.sessionId !== options.sessionId) throw new Error("Workflow namespace belongs to another session.");
6206
- const disposed = new AbortController();
6207
- run.onDispose(() => disposed.abort(/* @__PURE__ */ new Error("Workflow namespace run is disposed.")));
6208
- const signal = AbortSignal.any([run.signal, disposed.signal]);
6209
- const invoke = async (action) => {
6210
- signal.throwIfAborted();
6211
- options.assertAvailable();
6212
- const result = await action();
6213
- signal.throwIfAborted();
6214
- options.assertAvailable();
6215
- return JSON.parse(JSON.stringify(result));
6216
- };
6217
- const members = Object.create(null);
6218
- members.list = (input) => invoke(() => options.operations.list(input, options.cwd, signal));
6219
- members.launch = (input) => invoke(() => options.operations.launch(input, options.cwd, signal));
6220
- members.status = (input) => invoke(() => options.operations.status(input, signal));
6221
- members.pause = (input) => invoke(() => options.operations.pause(input, signal));
6222
- members.resume = (input) => invoke(() => options.operations.resume(input, signal));
6223
- members.stop = (input) => invoke(() => options.operations.stop(input, signal));
6224
- members.listFailed = (input) => invoke(() => options.operations.listFailed(input, signal));
6225
- members.recoveryEvidence = (input) => invoke(() => options.operations.recoveryEvidence(input, signal));
6226
- members.recover = (input) => invoke(() => options.operations.recover(input, signal));
6227
- members.inspectRun = (input) => invoke(() => options.operations.inspectRun(input, signal));
6228
- members.repairRun = (input) => invoke(() => options.operations.repairRun(input, signal));
6229
- return members;
6230
- }
6231
- };
6232
- }
6233
- //#endregion
6234
6150
  //#region src/services/workflowOperations/index.ts
6235
6151
  /** The tools and code mode use the same validation, ownership checks and session mutation queue. */
6236
6152
  function createWorkflowOperations(options) {
@@ -6431,6 +6347,166 @@ function renderWorkflowEvidence(evidence) {
6431
6347
  return `Workflow: ${evidence.record.displayName} (${evidence.runKey})\n${sections.length ? "" : "No durable evidence files found.\n"}--- run.json ---\n${JSON.stringify(evidence.record, null, 2)}${sections.length ? "\n" + sections.join("\n") : ""}`;
6432
6348
  }
6433
6349
  //#endregion
6350
+ //#region src/services/workflowNamespace/index.ts
6351
+ const clip = (value, max) => value.length > max ? `${value.slice(0, max - 1)}…` : value;
6352
+ /** The direct tool, and its action, whose card shows a member's call; the rest fall back to exec's own row. */
6353
+ const CARD_TOOLS = {
6354
+ list: ["list_workflows"],
6355
+ launch: ["launch_workflow"],
6356
+ status: ["workflow_run", "status"],
6357
+ pause: ["workflow_run", "pause"],
6358
+ resume: ["workflow_run", "resume"],
6359
+ stop: ["workflow_run", "stop"],
6360
+ listFailed: [WORKFLOW_TOOLS_TOOL_NAME, "list-failed"],
6361
+ recoveryEvidence: [WORKFLOW_TOOLS_TOOL_NAME, "recovery-evidence"],
6362
+ recover: [WORKFLOW_TOOLS_TOOL_NAME, "recover"]
6363
+ };
6364
+ function recordedArgs(input, action) {
6365
+ const value = typeof input === "object" && input !== null && !Array.isArray(input) ? input : {};
6366
+ try {
6367
+ return {
6368
+ ...JSON.parse(JSON.stringify(value)),
6369
+ ...action ? { action } : {}
6370
+ };
6371
+ } catch {
6372
+ return action ? { action } : {};
6373
+ }
6374
+ }
6375
+ /** What the matching direct tool returns: a launch's message, rendered evidence, or the JSON value. */
6376
+ function recordedResult(member, value) {
6377
+ let text;
6378
+ try {
6379
+ text = member === "launch" || member === "recover" ? value.message : member === "recoveryEvidence" ? renderWorkflowEvidence(value) : JSON.stringify(value, null, 2);
6380
+ } catch {
6381
+ text = JSON.stringify(value ?? null, null, 2);
6382
+ }
6383
+ return {
6384
+ content: [{
6385
+ type: "text",
6386
+ text
6387
+ }],
6388
+ details: value
6389
+ };
6390
+ }
6391
+ /** What the person approves: never the record body, which may carry env values. */
6392
+ function describeRepair(input) {
6393
+ const parsed = WorkflowRepairRunSchema.safeParse(input);
6394
+ if (!parsed.success) return {
6395
+ title: "Repair a workflow run (invalid request)",
6396
+ summary: clip(parsed.error.message, 600)
6397
+ };
6398
+ const repair = parsed.data;
6399
+ const nextStage = typeof repair.record?.stage === "string" ? repair.record.stage : repair.stage;
6400
+ const changes = [
6401
+ repair.record ? `rewrite run.json${nextStage === repair.stage ? "" : ` and move it to ${nextStage}`}` : "",
6402
+ repair.fix === null ? "remove fix.md" : repair.fix !== void 0 ? "rewrite fix.md" : "",
6403
+ repair.remove?.length ? `remove ${repair.remove.join(", ")}` : ""
6404
+ ].filter(Boolean);
6405
+ return {
6406
+ title: clip(`Repair workflow run ${repair.runKey}`, 120),
6407
+ summary: clip(`${repair.force ? "Force a repair of" : "Repair"} the ${repair.stage} run ${repair.runKey} in ${repair.workspace}: ${changes.join("; ") || "no change"}. A backup of every replaced file is kept in the run directory.`, 600),
6408
+ details: [
6409
+ {
6410
+ label: "Reason",
6411
+ value: clip(repair.reason, 300)
6412
+ },
6413
+ {
6414
+ label: "Workspace",
6415
+ value: clip(repair.workspace, 300)
6416
+ },
6417
+ {
6418
+ label: "Stage",
6419
+ value: nextStage === repair.stage ? repair.stage : `${repair.stage} → ${nextStage}`
6420
+ },
6421
+ ...repair.fix ? [{
6422
+ label: "fix.md",
6423
+ value: clip(repair.fix, 300)
6424
+ }] : [],
6425
+ ...repair.force ? [{
6426
+ label: "Force",
6427
+ value: "Repairs even though the run process is still alive."
6428
+ }] : []
6429
+ ]
6430
+ };
6431
+ }
6432
+ /** A run borrows the session's operations; ending exec never stops a committed workflow. */
6433
+ function createWorkflowNamespace(options) {
6434
+ return {
6435
+ name: "workflow",
6436
+ summary: "Discover and launch YAML workflows, inspect their runs, request generation-checked controls, and recover failed runs from evidence.",
6437
+ declarations: WORKFLOW_DECLARATIONS,
6438
+ portable: true,
6439
+ approval: { repairRun: {
6440
+ requirement: "human",
6441
+ describe: describeRepair
6442
+ } },
6443
+ bind(run) {
6444
+ if (run.sessionId !== options.sessionId) throw new Error("Workflow namespace belongs to another session.");
6445
+ const disposed = new AbortController();
6446
+ run.onDispose(() => disposed.abort(/* @__PURE__ */ new Error("Workflow namespace run is disposed.")));
6447
+ const signal = AbortSignal.any([run.signal, disposed.signal]);
6448
+ const invoke = async (action) => {
6449
+ signal.throwIfAborted();
6450
+ options.assertAvailable();
6451
+ const result = await action();
6452
+ signal.throwIfAborted();
6453
+ options.assertAvailable();
6454
+ return JSON.parse(JSON.stringify(result));
6455
+ };
6456
+ const members = Object.create(null);
6457
+ members.list = (input) => invoke(() => options.operations.list(input, options.cwd, signal));
6458
+ members.launch = (input) => invoke(() => options.operations.launch(input, options.cwd, signal));
6459
+ members.status = (input) => invoke(() => options.operations.status(input, signal));
6460
+ members.pause = (input) => invoke(() => options.operations.pause(input, signal));
6461
+ members.resume = (input) => invoke(() => options.operations.resume(input, signal));
6462
+ members.stop = (input) => invoke(() => options.operations.stop(input, signal));
6463
+ members.listFailed = (input) => invoke(() => options.operations.listFailed(input, signal));
6464
+ members.recoveryEvidence = (input) => invoke(() => options.operations.recoveryEvidence(input, signal));
6465
+ members.recover = (input) => invoke(() => options.operations.recover(input, signal));
6466
+ members.inspectRun = (input) => invoke(() => options.operations.inspectRun(input, signal));
6467
+ members.repairRun = (input) => invoke(() => options.operations.repairRun(input, signal));
6468
+ for (const [name, member] of Object.entries(members)) {
6469
+ const call = member;
6470
+ const [tool, action] = CARD_TOOLS[name] ?? ["workflow"];
6471
+ members[name] = async (input) => {
6472
+ const started = Date.now();
6473
+ const base = {
6474
+ name: `workflow.${name}`,
6475
+ tool,
6476
+ args: recordedArgs(input, action)
6477
+ };
6478
+ let value;
6479
+ try {
6480
+ value = await call(input);
6481
+ } catch (error) {
6482
+ const message = error instanceof Error ? error.message : String(error);
6483
+ const text = name === "launch" ? message : JSON.stringify({ error: message }, null, 2);
6484
+ run.record?.({
6485
+ ...base,
6486
+ ok: false,
6487
+ ms: Date.now() - started,
6488
+ error: message,
6489
+ result: { content: [{
6490
+ type: "text",
6491
+ text
6492
+ }] }
6493
+ });
6494
+ throw error;
6495
+ }
6496
+ run.record?.({
6497
+ ...base,
6498
+ ok: true,
6499
+ ms: Date.now() - started,
6500
+ result: recordedResult(name, value)
6501
+ });
6502
+ return value;
6503
+ };
6504
+ }
6505
+ return members;
6506
+ }
6507
+ };
6508
+ }
6509
+ //#endregion
6434
6510
  //#region src/services/serverRuntime/index.ts
6435
6511
  const SOURCE = "@agimon-ai/po-workflow";
6436
6512
  const LIST_TOOL = "list_workflows";