@agimon-ai/po-workflow 0.0.0-alpha.21 → 0.0.0-alpha.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/LICENSE +110 -149
  2. package/README.md +155 -53
  3. package/dist/apiContracts.cjs +205 -36
  4. package/dist/apiContracts.cjs.map +1 -1
  5. package/dist/apiContracts.d.mts +2 -2
  6. package/dist/apiContracts.d.mts.map +1 -1
  7. package/dist/apiContracts.mjs +205 -36
  8. package/dist/apiContracts.mjs.map +1 -1
  9. package/dist/contract-BpzJeyjh.mjs +33 -0
  10. package/dist/contract-BpzJeyjh.mjs.map +1 -0
  11. package/dist/contract-D80yV2d-.cjs +68 -0
  12. package/dist/contract-D80yV2d-.cjs.map +1 -0
  13. package/dist/extensions/native.mjs +4643 -1020
  14. package/dist/extensions/native.mjs.map +1 -1
  15. package/dist/extensions/server.cjs +21507 -3593
  16. package/dist/extensions/server.cjs.map +1 -1
  17. package/dist/extensions/server.d.mts.map +1 -1
  18. package/dist/extensions/server.mjs +21495 -3558
  19. package/dist/extensions/server.mjs.map +1 -1
  20. package/dist/extensions/web.mjs +5224 -2610
  21. package/dist/extensions/web.mjs.map +1 -1
  22. package/dist/index-CxS__mkJ.d.mts +5210 -0
  23. package/dist/index-CxS__mkJ.d.mts.map +1 -0
  24. package/dist/index.cjs +41 -3
  25. package/dist/index.cjs.map +1 -0
  26. package/dist/index.d.mts +104 -4
  27. package/dist/index.d.mts.map +1 -1
  28. package/dist/index.mjs +38 -1
  29. package/dist/index.mjs.map +1 -0
  30. package/dist/po-runtime-identity.json +1 -0
  31. package/dist/workflowHost-B8ludUOG.cjs +4190 -0
  32. package/dist/workflowHost-B8ludUOG.cjs.map +1 -0
  33. package/dist/workflowHost-DB4GtWpM.mjs +3974 -0
  34. package/dist/workflowHost-DB4GtWpM.mjs.map +1 -0
  35. package/dist/workflowHost.cjs +7 -0
  36. package/dist/workflowHost.d.mts +29 -0
  37. package/dist/workflowHost.d.mts.map +1 -0
  38. package/dist/workflowHost.mjs +3 -0
  39. package/dist/workflowServices-CSHleLJo.mjs +273 -0
  40. package/dist/workflowServices-CSHleLJo.mjs.map +1 -0
  41. package/dist/workflowServices-DYXhIDVE.cjs +350 -0
  42. package/dist/workflowServices-DYXhIDVE.cjs.map +1 -0
  43. package/llms.txt +10 -8
  44. package/locales/vi.json +492 -0
  45. package/locales/zh-CN.json +492 -0
  46. package/package.json +150 -26
  47. package/src/prompts/codemode-how-to-workflow/SKILL.md +226 -0
  48. package/src/prompts/help-how-to-workflow/SKILL.md +185 -0
  49. package/src/prompts/help-how-to-workflow-settings/SKILL.md +33 -0
  50. package/src/types/webWorkflowTerminal.ts +21 -0
  51. package/src/types/webWorkflows.ts +52 -2
  52. package/dist/workflowLaunchCommand-C69Nn3k5.cjs +0 -139
  53. package/dist/workflowLaunchCommand-C69Nn3k5.cjs.map +0 -1
  54. package/dist/workflowLaunchCommand-GGqimmTC.mjs +0 -122
  55. package/dist/workflowLaunchCommand-GGqimmTC.mjs.map +0 -1
  56. package/skills/workflow-recovery/SKILL.md +0 -85
  57. package/src/prompts/po-author-workflow/SKILL.md +0 -64
  58. package/src/prompts/po-use-workflow/SKILL.md +0 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-workflow",
3
- "version": "0.0.0-alpha.21",
3
+ "version": "0.0.0-alpha.211",
4
4
  "description": "GitHub Actions-style workflow graphs, artifacts, recovery, and asynchronous runs for Po.",
5
5
  "keywords": [
6
6
  "ai",
@@ -18,21 +18,21 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/AgiFlow/po/issues"
20
20
  },
21
- "license": "BUSL-1.1",
21
+ "license": "FSL-1.1-MIT",
22
22
  "author": "Vuong Ngo",
23
23
  "repository": {
24
24
  "type": "git",
25
25
  "url": "git+https://github.com/AgiFlow/po.git",
26
- "directory": "packages/minor/po-workflow"
26
+ "directory": "layers/automation/po-workflow"
27
27
  },
28
28
  "files": [
29
29
  "dist",
30
30
  "llms.txt",
31
31
  "README.md",
32
32
  "src/prompts",
33
- "skills/workflow-recovery/SKILL.md",
34
33
  "src/types/webWorkflows.ts",
35
- "src/types/webWorkflowTerminal.ts"
34
+ "src/types/webWorkflowTerminal.ts",
35
+ "locales"
36
36
  ],
37
37
  "type": "module",
38
38
  "main": "./dist/index.cjs",
@@ -56,59 +56,130 @@
56
56
  "./extensions/web": {
57
57
  "import": "./dist/extensions/web.mjs"
58
58
  },
59
- "./skills/workflow-recovery/SKILL.md": "./skills/workflow-recovery/SKILL.md",
59
+ "./locales/vi.json": "./locales/vi.json",
60
+ "./locales/zh-CN.json": "./locales/zh-CN.json",
61
+ "./workflowHost": {
62
+ "types": "./dist/workflowHost.d.mts",
63
+ "import": "./dist/workflowHost.mjs"
64
+ },
60
65
  "./package.json": "./package.json"
61
66
  },
62
67
  "publishConfig": {
63
68
  "access": "public"
64
69
  },
65
70
  "dependencies": {
66
- "@agimon-ai/po-core": "0.0.0-alpha.21",
67
- "@agimon-ai/po-minor-mode": "0.0.0-alpha.21",
68
- "@agimon-ai/po-telemetry": "0.0.0-alpha.21",
69
- "@agimon-ai/po-ui": "0.0.0-alpha.21",
70
- "@agimon-ai/po-web-components": "0.0.0-alpha.21",
71
- "@agimon-ai/po-web-security": "0.0.0-alpha.21",
72
- "@agimon-ai/workflow-mcp": "0.24.13",
71
+ "@agimon-ai/foundation-port-registry": "0.30.15",
72
+ "@agimon-ai/foundation-process-registry": "0.30.15",
73
+ "@agimon-ai/po-approval": "0.0.0-alpha.210",
74
+ "@agimon-ai/po-config": "0.0.0-alpha.211",
75
+ "@agimon-ai/po-core": "0.0.0-alpha.211",
76
+ "@agimon-ai/po-db": "0.0.0-alpha.211",
77
+ "@agimon-ai/po-logsink": "0.0.1-alpha.193",
78
+ "@agimon-ai/po-ui": "0.0.0-alpha.211",
79
+ "@agimon-ai/po-web-components": "0.0.0-alpha.211",
80
+ "@agimon-ai/po-web-security": "0.0.0-alpha.211",
73
81
  "@deepseek-ai/cordis": "4.0.5",
82
+ "@mastra/core": "1.78.0",
74
83
  "@modelcontextprotocol/server": "2.3.1",
84
+ "@rmux/sdk": "0.6.5",
85
+ "chalk": "6.0.1",
86
+ "commander": "15.0.0",
75
87
  "hono": "4.13.13",
76
- "typebox": "1.3.37",
77
- "zod": "4.6.7"
88
+ "js-yaml": "5.5.0",
89
+ "liquidjs": "10.30.0",
90
+ "proper-lockfile": "4.1.2",
91
+ "typebox": "1.4.2"
78
92
  },
79
93
  "devDependencies": {
80
- "@agimon-ai/po-build": "0.0.0-alpha.21",
81
- "@agimon-ai/po-native-components": "0.0.0-alpha.21",
94
+ "@agimon-ai/po-build": "0.0.0-alpha.211",
95
+ "@agimon-ai/po-native-components": "0.0.0-alpha.211",
82
96
  "@babel/core": "7.29.7",
83
- "@earendil-works/pi-coding-agent": "1.3.0",
97
+ "@earendil-works/pi-coding-agent": "1.6.1",
84
98
  "@tanstack/react-store": "0.11.2",
85
99
  "@tanstack/store": "0.11.2",
100
+ "@types/js-yaml": "4.0.9",
86
101
  "@types/node": "26.6.5",
102
+ "@types/proper-lockfile": "4.1.4",
87
103
  "@types/react": "19.3.0",
88
104
  "@types/react-dom": "19.3.0",
89
105
  "@vitest/coverage-v8": "5.0.4",
90
- "react": "19.3.0",
91
- "react-dom": "19.3.0",
92
- "react-native": "0.86.3",
93
- "react-native-unistyles": "3.5.3",
106
+ "react": "19.3.1",
107
+ "react-dom": "19.3.1",
108
+ "react-native": "0.88.1",
109
+ "react-native-unistyles": "3.7.0",
94
110
  "tsdown": "0.23.1",
95
111
  "typescript": "7.0.2",
96
- "vitest": "5.0.4"
112
+ "vitest": "5.0.4",
113
+ "zod": "4.6.7"
97
114
  },
98
115
  "peerDependencies": {
99
- "@earendil-works/pi-coding-agent": "1.3.0"
116
+ "@earendil-works/pi-coding-agent": "1.6.1",
117
+ "zod": "^4.4.3"
100
118
  },
101
119
  "peerDependenciesMeta": {
102
120
  "@earendil-works/pi-coding-agent": {
103
121
  "optional": true
104
122
  }
105
123
  },
124
+ "optionalDependencies": {
125
+ "@agimon-ai/rmux-darwin-arm64": "0.10.14",
126
+ "@agimon-ai/rmux-darwin-x64": "0.10.14",
127
+ "@agimon-ai/rmux-linux-arm64": "0.10.14",
128
+ "@agimon-ai/rmux-linux-x64": "0.10.14"
129
+ },
106
130
  "engines": {
107
131
  "node": ">=24"
108
132
  },
109
133
  "poNative": {
110
134
  "pluginId": "workflows",
135
+ "brain": {
136
+ "version": 1,
137
+ "slots": [
138
+ {
139
+ "name": "activity.workflows",
140
+ "scope": "session",
141
+ "parent": "activity",
142
+ "kind": "component"
143
+ }
144
+ ],
145
+ "fills": [
146
+ {
147
+ "id": "step-parent",
148
+ "slot": "conversation-strip",
149
+ "scope": "workspace",
150
+ "placement": "verified"
151
+ },
152
+ {
153
+ "id": "workflows",
154
+ "slot": "home",
155
+ "scope": "workspace",
156
+ "placement": "verified"
157
+ },
158
+ {
159
+ "id": "workflow-launcher",
160
+ "slot": "overlay",
161
+ "scope": "session",
162
+ "placement": "verified"
163
+ },
164
+ {
165
+ "id": "workflows",
166
+ "slot": "activity.workflows",
167
+ "scope": "session",
168
+ "placement": "verified"
169
+ },
170
+ {
171
+ "id": "Workflows",
172
+ "slot": "help.guides",
173
+ "scope": "session",
174
+ "placement": "verified"
175
+ }
176
+ ],
177
+ "diagnostics": [
178
+ "activity.workflows: parent activity unavailable locally (may be supplied by host or another package)"
179
+ ]
180
+ },
111
181
  "channels": [
182
+ "dynamic_workflow_runs",
112
183
  "workflow_catalog",
113
184
  "workflow_runs"
114
185
  ],
@@ -122,30 +193,83 @@
122
193
  "entry": "./generated/server.ts",
123
194
  "dist": "./dist/extensions/server.mjs",
124
195
  "scopes": [
125
- "global",
196
+ "host",
126
197
  "workspace",
127
198
  "session"
128
199
  ],
129
200
  "contracts": {
130
201
  "entry": "./src/exports/apiContracts.ts",
131
202
  "dist": "./dist/apiContracts.mjs"
203
+ },
204
+ "brain": {
205
+ "version": 1,
206
+ "provides": {}
132
207
  }
133
208
  },
134
209
  "poWeb": {
135
210
  "pluginId": "workflows",
211
+ "brain": {
212
+ "version": 1,
213
+ "slots": [],
214
+ "fills": [
215
+ {
216
+ "id": "step-parent",
217
+ "slot": "conversation-strip",
218
+ "scope": "workspace",
219
+ "placement": "verified"
220
+ },
221
+ {
222
+ "id": "workflows",
223
+ "slot": "home",
224
+ "scope": "workspace",
225
+ "placement": "verified"
226
+ },
227
+ {
228
+ "id": "workflow-launcher",
229
+ "slot": "overlay",
230
+ "scope": "session",
231
+ "placement": "verified"
232
+ },
233
+ {
234
+ "id": "workflows",
235
+ "slot": null,
236
+ "scope": "session",
237
+ "placement": "unverified"
238
+ },
239
+ {
240
+ "id": "workflows",
241
+ "slot": "artifacts.source",
242
+ "scope": "session",
243
+ "placement": "verified"
244
+ },
245
+ {
246
+ "id": "Workflows",
247
+ "slot": "help.guides",
248
+ "scope": "session",
249
+ "placement": "verified"
250
+ }
251
+ ],
252
+ "diagnostics": [
253
+ "src/extensions/workspaces/sessions/(frontend)/activity-group/workflows.web.ts: activity-group metadata unavailable (dynamic declaration)",
254
+ "src/extensions/workspaces/sessions/(frontend)/fill/Workflows.activity.workflows.web.tsx: fill identity unverified (spread or dynamic declaration); path is not placement evidence"
255
+ ]
256
+ },
136
257
  "channels": [
258
+ "dynamic_workflow_runs",
137
259
  "workflow_catalog",
138
260
  "workflow_runs"
139
261
  ],
140
262
  "client": "./dist/extensions/web.mjs",
141
263
  "scopes": [
264
+ "workspace",
142
265
  "session"
143
266
  ]
144
267
  },
145
268
  "scripts": {
146
269
  "build": "tsdown",
270
+ "build:guest": "node scripts/buildGuest.mjs",
147
271
  "test": "vitest --run",
148
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.web.json && tsc --noEmit -p tsconfig.native.json",
272
+ "typecheck": "tsrs --noEmit && tsrs --noEmit -p tsconfig.web.json && tsrs --noEmit -p tsconfig.native.json",
149
273
  "lint": "oxlint . && oxfmt . --check",
150
274
  "fixcode": "oxlint . --fix && oxfmt ."
151
275
  }
@@ -0,0 +1,226 @@
1
+ ---
2
+ name: codemode-how-to-workflow
3
+ description: Discover, launch, monitor and recover YAML workflows, use selected jobTools, or track dynamic script graphs and child transcripts in Activity.
4
+ pinned: true
5
+ ---
6
+
7
+ # Workflows in code mode
8
+
9
+ Use `workflow` for persisted YAML runs and `dynamicWorkflow` for tracked script graphs with a durable step journal. A managed step may also receive workflow-selected `jobTools`. Discover each namespace for current signatures. Workflow is available whenever its package is selected, with no mode activation.
10
+
11
+ ## Discover, launch, monitor
12
+
13
+ 1. `workflow.list` discovers definitions, tags and pages, not existing runs. Inspect the definition and its imports before launching. Call `workflow.requirements({ workflowPath, job? })` to read effective roles, same-profile groups and safe eligible profile candidates before choosing assignments. It includes reachable allowed child jobs and repair triage, needs no selected profile or saved team, and creates no admission or run. Role-bound discovery requires an admitted workspace and an allocation-aware identity provider. Its candidates are read-only evidence, not launch authorization. Do not pass product, workspace, profile, team or assignments to discovery.
14
+ 2. Call `workflow.validate({ workflowPath, inputs, env, runner, command, choice, profile, job })` with the settings you intend to launch. This read-only check reuses the parser/doctor and actual command resolver: imports, references, required/default inputs, declared input options/types, command/choice/runConfig bindings, environment interpolation phases and host injections. It never launches steps or reads a secret file. Supply only the optional settings you need.
15
+ 3. Inspect `valid`, every diagnostic's `code`, `location` and corrective `message`, and the separate `deferred` list. Fix errors and revalidate after every edit or launch-setting change. `valid: true` means no detected errors, not 100% runtime coverage. Run identities, assembled prompts, child invocation inputs, conditional context files, host selection/authentication and shell/artifact behavior may need execution-time checks. Never replace deferred values with invented data or claim they were verified. Binding values are omitted from reports and call cards.
16
+ 4. `workflow.launch` starts a run only when authorized. Prefer a declared in-process Pi command, for example `command: "pi"` when that name is declared. `pi`, `po` and `claude` are literal workflow command names, not aliases. Never rewrite a declared command to match an example. `runner` selects the runner, not the command; `runner: "codex"` does not imply `command: "pi"`. Without `command`, each step uses its first command. An acknowledgement `{ message, run? }` is not completion. The run reference may be absent until an identity exists. Use `workflow.status({ runKey, workspace })`, terminal notifications, and final job/step states before reporting success.
17
+ A launch runs in your session: you own the run, its step sessions sit directly under yours, and you are told when it ends. `sessionName` only names the workflow session opened to collect missing inputs when a person launches from the UI; it does not change `name` (the run context directory).
18
+ A definition whose `validate` result reports `isolation: 'checkout'` expects its own checkout. The engine never creates one: start it through an isolating launcher such as po-git `worktrees.startWorkflow`, not `workflow.launch` from a shared checkout. A launch handed to another session's checkout runs the launching session's own copy of a repository definition, so an uncommitted or unpushed edit still runs there.
19
+ 5. Pause, resume and stop only at the person's request or an explicit launcher delegation. Pass `expectedRunId` from the inspected run so a replacement generation cannot be controlled accidentally. Keep the exact `runKey` and separate `workspace`.
20
+
21
+ Shell steps, child scripts and background services use executable `/bin/zsh` when available, otherwise `/bin/sh`. Prefer POSIX shell syntax for workflows that must run on minimal Linux hosts.
22
+
23
+ Dispatcher sessions can list, discover requirements, validate and launch definitions; inspect, control or recover runs in the owner's session. Closing an exec binding does not stop a successfully launched YAML workflow; existing owner-session shutdown rules still apply. Calls are bound to the current session and reject abort, disposal and inactive package ownership.
24
+
25
+ List, requirements, validate, inspectDefinition, status, listFailed, listRuns and recoveryEvidence are reads. Launch, pause, resume, stop and recover are effects serialized per session. Workflow steps consume quota and may repeat external effects: quiet progress is not a reason to replay. Inspect live ownership and persisted state first. `workflow.listRuns` summarizes runs in every stage (running, completed, error) and accepts stage, workspace and runKey filters. `workflow.inspectDefinition({ path, template?, job? })` parses a workflow or partial template without running it; repository scripts call the same parser through the package's `inspectWorkflowFile`.
26
+
27
+ ## Continue a workflow chain
28
+
29
+ A successful completion for a run you launched is a handoff, not a recovery prompt. The notice lists the run directory and the outputs its definition declares (declared, not checked to exist). Read them and decide what follows: resume the applicable playbook if the run belongs to an active chain, or launch the workflow the outputs call for. No YAML declares the next workflow; it is your judgement. Use the notice's exact run key and workspace to reconcile the outcome and required outputs with the work item. Check the current board or equivalent work state and existing runs before choosing the next eligible action. Do that work in this turn if authorized, or leave it with the authorized person if not. Don't stop at an acknowledgement when work can advance. If nothing can advance, name the blocker or close the chain. A skipped run does not prove it produced anything. A parked or stopped run is not a trigger to advance or recover.
30
+
31
+ For a failure, the run's owner diagnoses and repairs it, and that is normally you. Inspect the exact run generation and recovery evidence, fix what you can within your existing authority, then `workflow.recover`. A run's first 3 recoveries need no approval; from the 4th, `workflow.recover` asks the person, also in Help mode. A dry run is not counted. Verify progress after recovering. Escalate a named blocker, uncertain side effect, or approval requirement rather than retrying blindly. If a run belongs to a workflow session of its own (opened to collect inputs, or from before runs stayed in the launching session), don't start a competing recovery: its owner diagnoses first and reports back to you once, as a child report. If you own such a run, finish by telling the launcher with `network.send({ to: launcher, text, terminal: true, outcome })`.
32
+
33
+ ## Recover safely
34
+
35
+ Recovery resumes an existing terminal failed or interrupted run from its active repair, in the checkout it ran in, preserving completed work. It is not a fresh launch or permission to control another session's live run. Runs recorded with an engine-owned worktree predate its removal and cannot be recovered; launch them fresh. `workflow.listFailed` accepts workspace/runKey and exact-match `env` filters; summaries omit environment data.
36
+
37
+ A run launched by a plugin (such as Agiflow) may hold a lock for its job. The engine tells the plugin how each run ended: success releases the lock, while a failed or interrupted run keeps it so recovery reuses it and no one else picks up the job. Recover with `workflow.recover` as usual. Never release a held lock by hand or launch a fresh duplicate. When the person decides not to recover a failed run, `workflow.abandon` (with their approval) releases its lock and the run can never be recovered. `lockReleased: false` means the plugin that holds the lock is not loaded; it is released when it is.
38
+
39
+ A run can also wait on the person. When a job's agent step is idle with only undecided approvals left, the run parks unless the step recorded a fail: it ends interrupted with a `wait` record, its step session is released, and `post:` does not run. Once the person approves or denies, its owner session resumes the parked job attempt on its own (a dormant owner is woken for it): steps that already finished keep their result and do not run again, triggers and `pre:` steps are skipped (`pre.services` restart), and the waiting step reopens its own session without a new prompt, so the approved call runs once and its agent carries on. Do not recover a parked run yourself while nothing is decided; recover refuses with "waits for the person's approval". When the resume is refused, `wait.blocked` says why and the run waits for the person: recover it, or launch fresh. `workflow.stop` on a parked run clears the wait and takes back its undecided requests; the run stays interrupted and keeps any lock until `workflow.abandon`. A lead, child, `pre:` or `post:` step holds its live session in place instead, until the person decides; only a recorded fail, Stop, an error or the step timeout withdraws the requests. While any approval is undecided, the step cannot record complete or fix.
40
+
41
+ Every resume runs the definition saved in run.json when the run was approved, so editing, renaming or deleting the workflow file (or a stored org or personal workflow) does not affect a run already launched. A `workflow.recover` you start picks up the edited file once, at its start, when the run has no role assignments and was launched from this checkout. A role-bound run, or one launched into another session's checkout, adopts an edit only in Help mode. Restarts and approval wakes always run the saved definition.
42
+ Before `workflow.recover`, call `workflow.recoveryEvidence` with the exact run key and workspace. Read every relevant log source, process state, the recorded run.json and only the repair referenced by activeRepairId. Evidence is terminal-only and read-only; it does not scrape an earlier session's live launcher.
43
+
44
+ Choose exactly one outcome: recover when the recorded target remains valid and failure was transient; launch fresh when it cannot resume or the branch has diverged materially; defer when a named prerequisite remains unresolved. An empty failed-job target cannot be recovered. Never manufacture a target, edit issue.md or repair.json, or discard the active repair or the run's checkout. Prepare run.json only when verified recovery state requires it. Treat an already-claimed result as another recovery winning, not permission to retry or launch fresh. Do not use dryRun for a real recovery.
45
+
46
+ Under a dispatch contract only: enforce its pass budget (recover and fresh launch each cost one launch), do not recover terminal repair-triage runs, do not act on jobs in blocked columns, and report manually launched runs without a job id rather than adopting them. These job-id and board rules do not apply to ordinary manually launched workflows.
47
+
48
+ After recovery, verify real process and registry progress with workflow.status before reporting an outcome. In server sessions replay belongs to the recovering session, whose closure requests a stop. Recovery cannot make external effects idempotent or guarantee survival of parent shutdown. User-requested stops do not trigger diagnosis or automatic restart.
49
+
50
+ ## Repair a stuck run (needs the person)
51
+
52
+ Use this only when recovery cannot proceed: run.json is invalid so the run is missing from listings, a dead run still sits in running, the fix budget is spent, or a repair triage locks recovery until a person unblocks it. Otherwise recover.
53
+
54
+ 1. `workflow.inspectRun({ runKey, workspace })` returns every stage directory the run occupies: raw run.json and control files, the parsed record or its validation error, whether its pid is alive, and a `revision`.
55
+ 2. Ask the person what to change before calling `workflow.repairRun`. It always needs their approval and is refused where nobody can answer. It throws `ApprovalPendingError` while they decide. Keep working; the outcome arrives later as a message. Do not call it again while one is pending.
56
+ 3. Pass the exact `revision`, a short `reason`, and only the change you need. `record` is a full replacement run.json (copy it from the inspection and edit it), checked against the schema; workspace and run key cannot change. A record stage of `error` moves a dead running run to error. A repair never moves a run into running: repair it to error, then `workflow.recover`. `fix` rewrites fix.md (front matter `restart-from: <job>` picks where recovery restarts) or removes it with null. `remove` drops stale control files such as `recovery-claim.json`.
57
+ 4. To unblock a triage lock, set the stated restart target in fix.md as the person directs. Never edit issue.md or repair.json.
58
+ 5. A running run with a live pid is refused. Stop it first; pass `force` only when the person confirms it is hung. A run owned by another live session must be repaired there. A changed revision means inspect again, not retry.
59
+
60
+ Every repair keeps the replaced files under `repair-backups/` in the run directory. After a repair, recover and verify with `workflow.status`.
61
+
62
+ ## Budgets and definition edits depend on Help mode
63
+
64
+ Recovery reads the spent fix-loop cycles from run.json and each lead's spent continuations from its child journal, exactly as they are on disk. Nothing resets them automatically.
65
+
66
+ - Help mode off: changing a budget is refused. `repairRun` refuses a record that lowers or drops `fixLoopCycle` or `recoveries`, or changes `FIX_LOOP_MAX_CYCLES` or `WORKFLOW_FIX_LOOP_DISABLED` ("Lowering a workflow budget needs Help mode."). `helpRepair` is refused. A live run whose YAML is edited fails at its next job ("The workflow definition changed since this run was approved."); recover it to run the edit if it has no role assignments, otherwise ask the person to turn on Help mode, or launch a fresh run.
67
+ - Help mode on: use `workflow.helpRepair({ runKey, workspace, stage: 'error', revision, reason, fixLoopCycle?, continuations?, recomputeRevision? })` with the `revision` from `inspectRun`. It needs no approval. It lowers the spent fix-loop cycles, sets a lead's spent continuations (`continuations: { <lead job>: 0 }`), and with `recomputeRevision` moves lead journals to the run's approved definition revision. It keeps the same checks as `repairRun`: a stale revision, a run this server still executes, a live recovery or another live owner is refused, and every replaced file is backed up. A YAML edit is adopted at the next reload or `recover`. `repairRun` skips approval in Help mode unless the record changes `allocation`, `admission` or `identities`.
68
+
69
+ ## Managed child jobs and independent checks
70
+
71
+ A managed lead sees its main job's trusted acceptance table before its first turn: each criterion,
72
+ its description, authorised `verified-by` child definition, current state and latest feedback. The
73
+ lead knows the requirements but cannot attest them. `children` is the allowlist of reusable job
74
+ definitions, not a fixed chain. Discover `workflow` again inside managed sessions for role-scoped methods.
75
+
76
+ - Lead: call `workflow.spawnChild({ job, prompt, inputs, inputPaths })` when that child has useful work. The
77
+ assignment is task text only; configuration and verifier authority come from the captured YAML.
78
+ Inputs must match the child's declaration. `inputPaths` lists run-directory files or folders the
79
+ child reads; each is sealed and recorded in its assignment. Keep secrets out of assignments, input
80
+ values and feedback.
81
+ - Inspect `workflow.children()` or `workflow.childStatus({ invocationId })` for linked session ids,
82
+ states, checks and usage coverage. Unknown token/cost values are not zero. Route native intercom
83
+ sends by exact session id, never a bare name. Full-session ask/reply is not provided.
84
+ - Child verifier: use `workflow.reviewArtifacts()` to obtain the immutable review snapshot, then
85
+ `workflow.reportCriteria({ results: { criterionKey: { status: 'checked' | 'not-met', feedback } } })`.
86
+ Only criteria that authorise this invocation's definition can be reported. Reports commit after
87
+ successful invocation settlement; edits to reviewed artifacts invalidate their checks. Do not
88
+ change an artifact yourself and certify different bytes from the snapshot.
89
+ - Any child: `workflow.assignment()` returns its immutable assignment: prompt, inputs, the sealed
90
+ version ID and SHA-256 of each input path (`inputManifest`), and the paths it may write. It replaces
91
+ `manifest.json` files and `inputManifest` file inputs, which are no longer authoritative.
92
+ - `not-met` is successful feedback, not a failed step or repair request. The lead chooses how to
93
+ address it and which children to call again. The workflow never auto-spawns children by default.
94
+ - At settlement, unresolved children hold the lead open. Unchecked/not-met criteria prevent
95
+ completion and return the criteria table and bounded feedback to the SAME lead session.
96
+ `completion.max-continuations: 3` permits three additional prompts after the initial settled
97
+ attempt, not three total attempts. Child-wait notifications consume no continuations. A child job counts its own failures:
98
+ `max-failures` (default 3) failed invocations in a row fail the lead with the last error; a recovery
99
+ starts the count again. Exhaustion
100
+ fails explicitly with outstanding criteria. Decision files and exit code 0 cannot bypass this guard.
101
+ - A person's stop cancels owned children and stays stopped.
102
+ - A step agent that runs again (a re-spawned child, a fix-loop replay, a timeout or job retry, a recovery
103
+ after a host restart) reopens its previous conversation in the same run directory, with a note saying
104
+ why it runs again; a host that cannot reopen it starts a fresh session. A reopened verifier must call
105
+ `workflow.reviewArtifacts()` again before `workflow.reportCriteria()`. A job with `session: fresh`
106
+ always starts its agent steps fresh.
107
+
108
+ ## Selected job tools
109
+
110
+ When the session lists the pinned `workflow-job-tools` skill, read it before using its methods. Then
111
+ call `discover({ namespace: 'jobTools' })` for the exact declarations and use `exec` to call them.
112
+ The skill teaches judgement and ordering; discovery supplies signatures. Do not invent methods or
113
+ assume tools selected for another job are present here. Ordinary sessions and external Claude/Codex
114
+ CLI runners do not receive this namespace, and there is no direct-tool fallback for it.
115
+
116
+ The workflow's optional `tools` folder is the default; a job's `tools` overrides it for its main steps,
117
+ `preJob` and `postJob`. Repair triage uses `repair.tools` or the default. Global phases use the default.
118
+ Selection comes from this session's captured config, never step `cwd` or environment values. Paths
119
+ retain the declaring YAML's origin through imports and job-template inheritance.
120
+
121
+ Methods are flat named async functions with JSON inputs/results. Follow the skill's input validation
122
+ and effect rules. Approval-gated methods use the normal code-mode approval flow; never bypass it or
123
+ retry an effect merely because an exec was cancelled. Bindings refuse foreign sessions, abort and
124
+ disposal. Exec cleanup does not stop the owning YAML workflow or change recovery ownership.
125
+
126
+ Authors provide trusted JavaScript `index.mjs` plus non-empty `SKILL.md`, not TypeScript or sandboxed
127
+ agent code. A per-session default-export factory receives `{ sessionId, cwd, workflow, fs, shell,
128
+ signal, acceptedArtifacts? }` and returns the existing namespace contract named `jobTools`: summary, declarations and
129
+ `bind(run)`. Validate method inputs, honour `run.signal` for work and register exec cleanup through
130
+ `run.onDispose`. Keep per-session state inside the factory. Optional approval policies must name a
131
+ returned method. Native modules are cached by file URL; restart the host after same-path module
132
+ edits. There is no hot reload or external CLI bridge. Missing or malformed selected tools fail the
133
+ managed session before its first prompt. See the package README's **Job-specific tools** section for
134
+ a runnable module and skill example.
135
+
136
+ An authorised downstream consumer's trusted factory can receive `acceptedArtifacts({ job })`.
137
+ It rechecks the runtime ledger and current revision and returns the accepted immutable bytes.
138
+ A task-writing adapter must fail closed when this capability is absent or stale, and construct its
139
+ writes from those bytes. Inside `bind(run)`, use `run.runJson({ command, args, input? })` for
140
+ shell-free argv plus JSON stdin/stdout. It inherits the session cwd/environment, is bounded to 15
141
+ seconds and the process bridge byte limits, and cancels with this exec/session. It returns
142
+ `{ exitCode, output, stderr }`; successful exit alone never certifies acceptance. Do not interpolate
143
+ input JSON or assignments into commands. Environment flags, PASS files and caller-provided acceptance booleans are
144
+ not authority. This adapter guards its own write path only: neither jobTools nor the acceptance
145
+ capability sandboxes an unrestricted agent's raw shell or other external tools.
146
+
147
+ ## Delete a stored definition
148
+
149
+ Use `workflow.list()` to find the workflow's `source` and the file name at the end of its `path`, then submit one
150
+ `workflow.deleteDefinition({ source, key })` in a foreground exec. The key is a plain `.workflow.yml`
151
+ or `.workflow.yaml` file name, not a path. Only stored `org`, `personal` or `host` definitions can be
152
+ removed. The person approves each deletion, even in Help mode. Wait for the approval result before
153
+ checking `workflow.list()` again; do not retry a pending request. The operation does not remove run
154
+ history or edit repository files. Without code mode, use `workflow_delete_definition` with the same input.
155
+
156
+ ## Hosts without code mode
157
+
158
+ Use list_workflows and launch_workflow for discovery/launch; workflow_requirements for read-only role and eligible-profile discovery; workflow_run for status/pause/resume/stop; workflow_tools for list-failed, list-runs, inspect-definition, recovery-evidence and recover. These tools share the same operations and safety checks. Managed leads receive workflow_spawn_child,
159
+ workflow_child_status and workflow_children; children receive workflow_assignment, and child verifiers
160
+ also receive workflow_review_artifacts and workflow_report_criteria. These tools are main-agent-only and withdrawn when code mode is bound.
161
+ Scaffolding a skeleton is a Help task through `workflowAdmin.scaffold`; see `help-how-to-workflow`.
162
+
163
+ # Dynamic script graphs
164
+
165
+ Use `dynamicWorkflow` when a script has multiple steps or bounded item fan-out and the person should see progress in Activity. Desktop uses Mastra 1.78.0. Cloud runs a small compatible executor and real `zod/v3` inside the QuickJS guest, with JSON-only lifecycle events to Po. Discover `dynamicWorkflow` for the current signatures.
166
+
167
+ Cloud note: `then`, `parallel`, `branch`, bounded workflow `foreach`, `commit`, `createRun/start/cancel` and journal replay are supported with the same script shape. Callbacks and schemas never cross the JSON membrane. A child `team.run` is linked to a phase only when exactly one phase is running in the session at admission. With overlapping phases, children remain in the session snapshot's `unlinkedAgents`, never guessed onto a phase or root. Cloud still cannot import a saved script; after arming `resume(recordId)`, submit its saved source in the same exec binding rather than using `import()`. All APIs listed as unsupported below are refused on cloud too.
168
+
169
+ Use the supplied `z` (the Zod 3 API), `createStep`, and `createWorkflow`, not raw npm imports. Build, commit, create a run, then await `start({inputData})`. Run long work inside `exec({ code, background: true })` so the parent remains responsive; cancellation and disposal stop active runs.
170
+
171
+ ```ts
172
+ const { z, createStep, createWorkflow } = dynamicWorkflow;
173
+ const phase = (id) =>
174
+ createStep({
175
+ id,
176
+ inputSchema: z.string(),
177
+ outputSchema: z.string(),
178
+ execute: async ({ inputData }) => {
179
+ const child = await team.run({ task: inputData, systemPrompt: 'Complete this item and report your findings.' });
180
+ // The script owns its failure policy: inspect child.status and decide
181
+ // whether to throw, retry, or return failure data for another phase.
182
+ return inputData;
183
+ },
184
+ });
185
+ const item = createWorkflow({ id: 'item', inputSchema: z.string(), outputSchema: z.string() })
186
+ .then(phase('gather'))
187
+ .then(phase('check'))
188
+ .commit();
189
+ const workflow = createWorkflow({ id: 'items', inputSchema: z.array(z.string()), outputSchema: z.array(z.string()) })
190
+ .foreach(item, { concurrency: 3 })
191
+ .commit();
192
+ return await (await workflow.createRun()).start({ inputData: ['first', 'second'] });
193
+ ```
194
+
195
+ Supported composition: `.then(step)`, `.parallel([step,...])`, `.branch([[predicate,step],...])`, and `.foreach(committedTrackedItemWorkflow,{concurrency:positiveInteger})`. Branch predicates receive execution parameters and must return a boolean. Every matched branch can execute. Commit each nested workflow before adding it. Create every nested handle within the same exec binding. Use distinct step ids in a workflow. Handles are not durable and cannot be shared between exec calls.
196
+
197
+ Not supported: bare-step foreach, dynamic concurrency callbacks, raw Mastra instances, custom engines or storage, streams, Mastra suspend/resume, time travel, retries configured through workflow options, startAsync, or private methods. Only `id`, optional `description`, `inputSchema`, `outputSchema`, and step `execute` options are accepted. `createRun()` takes no options; `start` accepts only `inputData`; `cancel()` stops that run.
198
+
199
+ Return `null`, not `undefined`, when a callback intentionally has no output. The code-mode membrane converts guest callback exceptions to undefined; Po reports that as failed and directs you to exec diagnostics, rather than inventing the original error. A normal returned failure object is data, not an automatic exception. Mastra's own failure/queue behavior still applies. Mastra 1.78 validates step input but does not enforce step output schemas at runtime. Po preserves that behavior rather than adding a second validation engine. A child-agent failure remains visible even if the script handles it and Mastra finishes successfully. Po keeps execution status separate from this application outcome.
200
+
201
+ Activity snapshots are metadata only: names, topology, status, timing, bounded errors and child run ids. They omit prompts, schemas, callback source, input and output. Keep sensitive data out of ids and error messages. At most 20 finished root runs remain in memory, active roots are never evicted, and groups publish up to 1000 rows with true totals and aggregate counts.
202
+
203
+ ## Child sessions with their own selection
204
+
205
+ `dynamicWorkflow.agent({ task, systemPrompt?, preset?, modes?, profile?, domains?, model?, thinking?, cwd?, timeoutMs? })` runs one task in an unattended child session and resolves `{ sessionId?, status, output, error? }` with the child's final reply. Use it instead of `team.run` when a step needs a different preset, modes, profile or domains than this session.
206
+
207
+ - Call it only inside a running `createStep` execute callback, from the main agent. Anywhere else it throws.
208
+ - `profile: null` opens the child with no profile; leaving a field out keeps the host default. `domains: []` opens it with none.
209
+ - It never rejects once the child starts. Check `status` and decide in the script whether to throw, retry or pass the failure on.
210
+ - The child waits while it has approvals the person has not settled, up to `timeoutMs` (default 10 minutes, at most 2 hours). On timeout the child is stopped and its unsettled approvals are withdrawn.
211
+ - The phase in Activity links the child's transcript. The child leaves the session list once it finishes.
212
+ - A finished step replays its saved output on resume, so its agent is not asked again. A step that reruns starts a fresh child session.
213
+ - `exec` ends after 2 minutes at most, and its end stops the child. Run scripts with agent steps inside `exec({ code, background: true })`.
214
+ - Cloud links the child to a phase only when exactly one phase is running, as for `team.run`.
215
+
216
+ ## Resume after a restart
217
+
218
+ Po saves the outer exec source, JSON-serializable successful step outputs and each step's team.run identity in the workflow database. The saved source is immutable. On restart or release, the owner agent receives a prompt to arm `await dynamicWorkflow.resume(recordId)` and import the returned `specifier`, a read-only export of that source rewritten on every resume. Resume is scoped to that exec binding. To fix what failed, run a changed script in the armed binding instead of editing the export: completed steps replay their saved output by root and step path, so a step whose id or position changed runs again, and a kept step id returns its old output even if its code changed. Keep the root workflow ids, root order and input. A root mismatch throws before that root's callbacks run; there is no uncached fallback. A step that was running when the record was interrupted may or may not have applied its effect, so replay refuses it and the record stays resumable. Check that effect, then arm `dynamicWorkflow.resume(recordId, { retryUncertain: true })` to run the step again.
219
+
220
+ - Code outside steps re-runs. Put effects you want memoized inside steps.
221
+ - Step outputs must be JSON-serializable. Other outputs are not saved and those steps re-run.
222
+ - Branch predicates must be pure because they run again during replay.
223
+ - A step interrupted before its output was saved repeats its side effects.
224
+ - Imported scripts are not copied. Keep their definitions stable for replay.
225
+
226
+ A person's stop does not resume automatically. Interrupted runs appear stopped with the restart note, not a separate UI status.