@wichayutdew/pi-workflows 2.5.1 → 2.7.0

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 (103) hide show
  1. package/README.md +34 -1
  2. package/dist/index.js +1315 -2467
  3. package/examples/starter-kit/agents/planner.md +11 -0
  4. package/examples/starter-kit/agents/reviewer.md +10 -0
  5. package/examples/starter-kit/agents/scout.md +10 -0
  6. package/examples/starter-kit/agents/worker.md +11 -0
  7. package/examples/starter-kit/agents/workspace-preparer.md +10 -0
  8. package/examples/starter-kit/investigate.workflow.yaml +84 -0
  9. package/examples/starter-kit/jira.workflow.yaml +75 -0
  10. package/examples/starter-kit/mr-comment.workflow.yaml +86 -93
  11. package/examples/starter-kit/mr-review.workflow.yaml +52 -88
  12. package/examples/starter-kit/settings.yaml +4 -0
  13. package/examples/starter-kit/steps/investigate/investigate.md +40 -0
  14. package/examples/starter-kit/steps/investigate/retrieve.md +28 -0
  15. package/examples/starter-kit/steps/investigate/validate.md +20 -0
  16. package/examples/starter-kit/steps/jira/create.md +25 -0
  17. package/examples/starter-kit/steps/jira/draft.md +18 -0
  18. package/examples/starter-kit/steps/jira/plan.md +30 -0
  19. package/examples/starter-kit/steps/mr-comment/checkout-source.md +14 -0
  20. package/examples/starter-kit/steps/mr-comment/fetch.md +11 -28
  21. package/examples/starter-kit/steps/mr-comment/implement.md +9 -26
  22. package/examples/starter-kit/steps/mr-comment/plan.md +46 -55
  23. package/examples/starter-kit/steps/mr-comment/publish.md +11 -31
  24. package/examples/starter-kit/steps/mr-comment/verify.md +7 -34
  25. package/examples/starter-kit/steps/mr-review/fetch.md +13 -21
  26. package/examples/starter-kit/steps/mr-review/publish-approved.md +18 -0
  27. package/examples/starter-kit/steps/mr-review/review-for-approval.md +53 -0
  28. package/examples/starter-kit/steps/mr-review/verify-published.md +16 -0
  29. package/examples/starter-kit/steps/shared/prepare-workspace.md +11 -89
  30. package/examples/starter-kit/steps/shared/publish-remote.md +16 -0
  31. package/examples/starter-kit/steps/ticket/implement.md +10 -23
  32. package/examples/starter-kit/steps/ticket/plan.md +49 -98
  33. package/examples/starter-kit/steps/ticket/verify.md +14 -65
  34. package/examples/starter-kit/steps/work/implement.md +11 -22
  35. package/examples/starter-kit/steps/work/plan.md +43 -59
  36. package/examples/starter-kit/steps/work/verify.md +14 -25
  37. package/examples/starter-kit/ticket.workflow.yaml +57 -61
  38. package/examples/starter-kit/work.workflow.yaml +49 -57
  39. package/package.json +9 -19
  40. package/schemas/workflow.schema.json +63 -15
  41. package/scripts/patch-herdr-agent-state.mjs +36 -0
  42. package/src/agents/profile.ts +98 -0
  43. package/src/config/ceiling.ts +0 -82
  44. package/src/config/types.ts +15 -53
  45. package/src/config/validation/settings.ts +2 -14
  46. package/src/config/validation/step.ts +129 -8
  47. package/src/config/validation/workflow.ts +1 -10
  48. package/src/engine/run-workflow-validation.ts +0 -3
  49. package/src/engine/state-types.ts +1 -1
  50. package/src/harness/action-context.ts +1 -13
  51. package/src/harness/artifact-contract.ts +46 -0
  52. package/src/harness/delegation-control-actions.ts +4 -63
  53. package/src/harness/delegation-plan.ts +26 -80
  54. package/src/harness/delegation-response-actions.ts +22 -135
  55. package/src/harness/dependencies.ts +1 -12
  56. package/src/harness/gate-submission-action.ts +28 -0
  57. package/src/harness/status-actions.ts +20 -0
  58. package/src/harness/step-execution-actions.ts +2 -9
  59. package/src/harness/types.ts +2 -40
  60. package/src/harness.ts +2 -17
  61. package/src/herdr-workflow-state.ts +65 -0
  62. package/src/index.ts +4 -9
  63. package/src/integrations/subagents/child-policy-validation.ts +6 -7
  64. package/src/integrations/subagents/child-runtime-dependencies.ts +1 -1
  65. package/src/integrations/subagents/child-runtime-policy.ts +1 -7
  66. package/src/integrations/subagents/child-runtime.ts +18 -9
  67. package/src/integrations/subagents/client.ts +240 -98
  68. package/src/integrations/subagents/protocol-events.ts +32 -15
  69. package/src/integrations/subagents/protocol.ts +1 -1
  70. package/src/preflight.ts +0 -8
  71. package/src/prompt/main-workflow-notice.ts +8 -15
  72. package/src/prompt/step-task.ts +7 -6
  73. package/src/workflow-status/format-status.ts +5 -1
  74. package/src/workflow-status/render-step-detail.ts +94 -0
  75. package/src/workflow-status/types.ts +1 -0
  76. package/src/workflow-status/view.ts +49 -14
  77. package/agents/step.md +0 -32
  78. package/examples/mr-comments.workflow.yaml +0 -125
  79. package/examples/prompts/mr-comments/implement.md +0 -17
  80. package/examples/prompts/mr-comments/inspect.md +0 -5
  81. package/examples/prompts/mr-comments/plan.md +0 -54
  82. package/examples/prompts/mr-comments/verify.md +0 -9
  83. package/examples/settings.yaml +0 -27
  84. package/examples/starter-kit/steps/mr-review/publish.md +0 -48
  85. package/examples/starter-kit/steps/mr-review/review.md +0 -76
  86. package/examples/starter-kit/steps/mr-review/verify.md +0 -35
  87. package/src/config/validation/subagent.ts +0 -288
  88. package/src/harness/delegation-failure.ts +0 -248
  89. package/src/harness/delegation-recovery-validation.ts +0 -161
  90. package/src/harness/delegation-retry-policy.ts +0 -120
  91. package/src/integrations/subagents/client-delegation.ts +0 -181
  92. package/src/integrations/subagents/client-messages.ts +0 -66
  93. package/src/integrations/subagents/client-types.ts +0 -36
  94. package/src/integrations/subagents/diagnostic-format.ts +0 -45
  95. package/src/integrations/subagents/diagnostic-text.ts +0 -114
  96. package/src/integrations/subagents/diagnostic-types.ts +0 -83
  97. package/src/integrations/subagents/diagnostics.ts +0 -26
  98. package/src/integrations/subagents/failure-correlation.ts +0 -285
  99. package/src/integrations/subagents/failure-transcript.ts +0 -252
  100. package/src/integrations/subagents/hidden-bash-failure.ts +0 -98
  101. package/src/integrations/subagents/replay-audit.ts +0 -146
  102. package/src/integrations/subagents/replay-safety.ts +0 -67
  103. package/src/integrations/subagents/session-diagnostics.ts +0 -357
@@ -1,34 +1,23 @@
1
- You independently verify the approved local-work result. Do not edit files,
2
- amend commits, change worktrees, or mutate external state.
1
+ You are the independent verification stage for local work. Stay read-only in this delegated child; do not modify files, amend commits, or launch subagents.
3
2
 
4
- Request:
3
+ Original request:
5
4
  {{workflow.input}}
6
5
 
7
6
  Approved plan:
8
7
  {{reviewed.artifact}}
9
8
 
10
- Implementation handoff:
11
- {{last.summary}}
12
-
13
- Confirm the current directory and branch are still the bound worktree. Inspect
14
- the full diff, changed callers, tests, repository instructions, commit and
15
- working-tree status. Check every approved acceptance criterion independently.
16
- Run the exact repository-native validation commands named in the approved plan;
17
- derive any necessary invocation-only correction from current scripts or tool
18
- help without weakening the check. A skipped, stale, unavailable, or failing
19
- required check is not passing.
9
+ Approval feedback:
10
+ {{reviewed.feedback}}
20
11
 
21
- Any regression, lint failure, formatting failure, or other actionable local
22
- verification finding is `failed`; the workflow sends that outcome directly back
23
- to implementation. Do not use `blocked` for a fixable local finding.
24
-
25
- Call `structured_output` alone with:
12
+ Implementation ledger:
13
+ {{last.summary}}
26
14
 
27
- - `passed` only when every criterion and required check passes;
28
- - `failed` for an actionable implementation defect, with the exact location,
29
- evidence, and smallest corrective handoff;
30
- - `blocked` when verification cannot proceed safely or the approved contract is
31
- materially stale.
15
+ ## Rules & Verification Criteria
32
16
 
33
- Include fresh commands, results, per-criterion evidence, diff/commit identity,
34
- and final status in the summary. Do not fix findings yourself.
17
+ 1. **Independent Verification**: Re-run all standalone commands under `repositories[0].reviewer[]` (`full-tests`, `lint`, `format`).
18
+ 2. **Strict Evidence**: Confirm exact commit title, clean status (or original dirty baseline preserved), and explicit criterion proofs. Any failing or skipped check is non-passing.
19
+ 3. **Outcomes**:
20
+ - `passed`: All acceptance criteria and automated checks verified.
21
+ - `failed`: Actionable failure or regression. Automatically returns to `implement` stage for fix.
22
+ - `retry`: Recoverable read-only environment failure.
23
+ - `blocked`: Corrupted workspace or missing review authority.
@@ -1,112 +1,108 @@
1
1
  version: 1
2
2
  id: ticket
3
3
  command: ticket
4
- description: Prepare a dedicated workspace, approve a ticket plan, implement, and verify
4
+ description: 'Prepare a dedicated workspace, plan, implement, and verify an issue-tracker ticket. Example: /ticket PROJ-123 Fix a missing client-id header'
5
5
  start: prepare-workspace
6
- maxStepVisits: 4
6
+ maxStepVisits: 20
7
7
  summaryMaxChars: 30000
8
8
  steps:
9
9
  prepare-workspace:
10
- title: Prepare or reuse a dedicated worktree
10
+ title: Prepare dedicated branch and worktree
11
11
  prompt:
12
12
  file: steps/shared/prepare-workspace.md
13
- subagent:
14
- agent: worker
15
- context: fresh
16
- timeoutMs: 900000
13
+ agent: workspace-preparer
17
14
  workspace:
18
- bindOn: [ready]
19
- allowedRoots: ['..']
15
+ bindOn:
16
+ - ready
17
+ allowedRoots:
18
+ - ~/repositories/worktrees
20
19
  permissions:
21
20
  tools: [read, ls, bash]
21
+ mcp: []
22
+ extensions: [/]
23
+ skills: [using-git-worktrees, caveman]
22
24
  bash:
23
25
  mode: unrestricted
24
- requires:
25
- tools: [read, ls, bash]
26
26
  transitions:
27
27
  ready: plan
28
+ retry: prepare-workspace
28
29
  blocked: $pause
29
-
30
30
  plan:
31
- title: Read the ticket and propose a plan
31
+ title: Read Jira evidence and plan
32
32
  prompt:
33
33
  file: steps/ticket/plan.md
34
- subagent:
35
- agent: planner
36
- context: fresh
37
- timeoutMs: 1200000
34
+ agent: planner
38
35
  permissions:
39
- tools: [read, ls, bash]
40
- mcp: [atlassian]
41
- bash:
42
- mode: allow-list
43
- allow:
44
- - executable: git
45
- argsPrefixes:
46
- [
47
- [status],
48
- [diff],
49
- [log],
50
- [show],
51
- [grep],
52
- [ls-files],
53
- [rev-parse],
54
- [merge-base],
55
- [rev-list],
56
- [worktree, list],
57
- ]
58
- - executable: rg
59
- - executable: grep
60
- requires:
61
36
  tools: [read, ls, bash, mcp]
37
+ mcp: [atlassian, context7, sourcegraph, glean, gitlab]
38
+ extensions: [/]
39
+ skills:
40
+ [
41
+ jira-ticket,
42
+ coding-standards,
43
+ writing-plans,
44
+ search-code-sourcegraph,
45
+ caveman,
46
+ ]
47
+ bash:
48
+ mode: unrestricted
62
49
  gate:
63
50
  provider: plannotator
64
51
  submitOutcome: submit
65
52
  approvedOutcome: approved
66
53
  rejectedOutcome: changes-requested
67
54
  timeoutMs: 30000
55
+ artifactContract:
56
+ maxChars: 10000
57
+ requiredSubstrings:
58
+ - '## Review summary'
59
+ - '## Review focus'
60
+ - '## Proposed approach'
61
+ - '## Validation'
62
+ - '## Risks'
63
+ - '## Execution appendix (machine-readable)'
64
+ - '## Publication contract'
65
+ forbiddenSubstrings:
66
+ - 'The complete gate artifact is the exact Markdown saved at'
67
+ onValidationFailure: retry
68
68
  transitions:
69
69
  approved: implement
70
70
  changes-requested: plan
71
71
  workspace-refresh: prepare-workspace
72
+ retry: plan
72
73
  blocked: $pause
73
-
74
74
  implement:
75
- title: Implement the approved ticket plan
75
+ title: Implement the approved Jira plan
76
76
  prompt:
77
77
  file: steps/ticket/implement.md
78
- subagent:
79
- agent: worker
80
- context: fresh
81
- timeoutMs: 7200000
82
- artifacts: true
78
+ agent: worker
83
79
  permissions:
84
- tools: [read, ls, bash, edit, write]
85
- mcp: [atlassian]
80
+ tools: [read, ls, bash, edit, write, mcp]
81
+ mcp: [context7]
82
+ extensions: [/]
83
+ skills:
84
+ [coding-standards, test-driven-development, lint-commands, caveman]
86
85
  bash:
87
86
  mode: unrestricted
88
- requires:
89
- tools: [read, ls, bash, edit, write, mcp]
90
87
  transitions:
91
88
  ready: verify
89
+ retry: implement
92
90
  blocked: $pause
93
-
94
91
  verify:
95
- title: Independently verify the ticket work
92
+ title: Independently verify Jira work
96
93
  prompt:
97
94
  file: steps/ticket/verify.md
98
- subagent:
99
- agent: reviewer
100
- context: fresh
101
- timeoutMs: 3600000
95
+ agent: reviewer
102
96
  permissions:
103
- tools: [read, ls, bash]
104
- mcp: [atlassian]
97
+ tools: [read, ls, bash, mcp]
98
+ mcp: [gitlab]
99
+ extensions: [/]
100
+ skills:
101
+ [verification-before-completion, lint-commands, commit-format, caveman]
105
102
  bash:
106
103
  mode: unrestricted
107
- requires:
108
- tools: [read, ls, bash, mcp]
109
104
  transitions:
110
105
  passed: $done
111
106
  failed: implement
112
- blocked: $pause
107
+ retry: verify
108
+ blocked: verify
@@ -1,109 +1,101 @@
1
1
  version: 1
2
2
  id: work
3
3
  command: work
4
- description: Prepare a dedicated workspace, approve a plan, implement, and verify local work
4
+ description: 'Prepare a dedicated workspace, plan, implement, and verify local work. Example: /work Add rate limiting to user registration endpoint'
5
5
  start: prepare-workspace
6
- maxStepVisits: 4
6
+ maxStepVisits: 20
7
7
  summaryMaxChars: 30000
8
8
  steps:
9
9
  prepare-workspace:
10
- title: Prepare or reuse a dedicated worktree
10
+ title: Prepare dedicated branch and worktree
11
11
  prompt:
12
12
  file: steps/shared/prepare-workspace.md
13
- subagent:
14
- agent: worker
15
- context: fresh
16
- timeoutMs: 900000
13
+ agent: workspace-preparer
17
14
  workspace:
18
- bindOn: [ready]
19
- allowedRoots: ['..']
15
+ bindOn:
16
+ - ready
17
+ allowedRoots:
18
+ - ~/repositories/worktrees
20
19
  permissions:
21
20
  tools: [read, ls, bash]
21
+ mcp: []
22
+ extensions: [/]
23
+ skills: [using-git-worktrees, caveman]
22
24
  bash:
23
25
  mode: unrestricted
24
- requires:
25
- tools: [read, ls, bash]
26
26
  transitions:
27
27
  ready: plan
28
+ retry: prepare-workspace
28
29
  blocked: $pause
29
-
30
30
  plan:
31
- title: Explore and plan the requested work
31
+ title: Explore and plan local work
32
32
  prompt:
33
33
  file: steps/work/plan.md
34
- subagent:
35
- agent: planner
36
- context: fresh
37
- timeoutMs: 1200000
34
+ agent: planner
38
35
  permissions:
39
- tools: [read, ls, bash]
36
+ tools: [read, ls, bash, mcp]
37
+ mcp: [context7, sourcegraph, glean, gh_grep]
38
+ extensions: [/]
39
+ skills:
40
+ [coding-standards, writing-plans, search-code-sourcegraph, caveman]
40
41
  bash:
41
- mode: allow-list
42
- allow:
43
- - executable: git
44
- argsPrefixes:
45
- [
46
- [status],
47
- [diff],
48
- [log],
49
- [show],
50
- [grep],
51
- [ls-files],
52
- [rev-parse],
53
- [merge-base],
54
- [rev-list],
55
- [worktree, list],
56
- ]
57
- - executable: rg
58
- - executable: grep
59
- requires:
60
- tools: [read, ls, bash]
42
+ mode: unrestricted
61
43
  gate:
62
44
  provider: plannotator
63
45
  submitOutcome: submit
64
46
  approvedOutcome: approved
65
47
  rejectedOutcome: changes-requested
66
48
  timeoutMs: 30000
49
+ artifactContract:
50
+ maxChars: 8000
51
+ requiredSubstrings:
52
+ - '## Review summary'
53
+ - '## Review focus'
54
+ - '## Proposed approach'
55
+ - '## Validation'
56
+ - '## Risks'
57
+ - '## Execution appendix (machine-readable)'
58
+ forbiddenSubstrings:
59
+ - 'The complete gate artifact is the exact Markdown saved at'
60
+ onValidationFailure: retry
67
61
  transitions:
68
62
  approved: implement
69
63
  changes-requested: plan
70
64
  workspace-refresh: prepare-workspace
65
+ retry: plan
71
66
  blocked: $pause
72
-
73
67
  implement:
74
- title: Implement the approved plan
68
+ title: Implement the approved local plan
75
69
  prompt:
76
70
  file: steps/work/implement.md
77
- subagent:
78
- agent: worker
79
- context: fresh
80
- timeoutMs: 7200000
81
- artifacts: true
71
+ agent: worker
82
72
  permissions:
83
- tools: [read, ls, bash, edit, write]
73
+ tools: [read, ls, bash, edit, write, mcp]
74
+ mcp: [context7]
75
+ extensions: [/]
76
+ skills:
77
+ [coding-standards, test-driven-development, lint-commands, caveman]
84
78
  bash:
85
79
  mode: unrestricted
86
- requires:
87
- tools: [read, ls, bash, edit, write]
88
80
  transitions:
89
81
  ready: verify
82
+ retry: implement
90
83
  blocked: $pause
91
-
92
84
  verify:
93
- title: Independently verify the result
85
+ title: Independently verify local work
94
86
  prompt:
95
87
  file: steps/work/verify.md
96
- subagent:
97
- agent: reviewer
98
- context: fresh
99
- timeoutMs: 3600000
88
+ agent: reviewer
100
89
  permissions:
101
90
  tools: [read, ls, bash]
91
+ mcp: []
92
+ extensions: [/]
93
+ skills:
94
+ [verification-before-completion, lint-commands, commit-format, caveman]
102
95
  bash:
103
96
  mode: unrestricted
104
- requires:
105
- tools: [read, ls, bash]
106
97
  transitions:
107
98
  passed: $done
108
99
  failed: implement
109
- blocked: $pause
100
+ retry: verify
101
+ blocked: verify
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wichayutdew/pi-workflows",
3
- "version": "2.5.1",
3
+ "version": "2.7.0",
4
4
  "description": "A declarative, pauseable workflow harness for Pi",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,32 +21,29 @@
21
21
  "files": [
22
22
  "dist",
23
23
  "src",
24
- "agents",
25
24
  "examples",
26
25
  "schemas",
26
+ "scripts",
27
27
  "README.md",
28
28
  "LICENSE"
29
29
  ],
30
30
  "pi": {
31
31
  "extensions": [
32
- "./src/index.ts"
33
- ],
34
- "subagents": {
35
- "agents": [
36
- "./agents"
37
- ]
38
- }
32
+ "./src/index.ts",
33
+ "./src/herdr-workflow-state.ts"
34
+ ]
39
35
  },
40
36
  "scripts": {
41
37
  "build": "bun build ./src/index.ts --outdir=dist --target=node --format=esm --packages=external",
38
+ "patch:herdr": "node ./scripts/patch-herdr-agent-state.mjs",
42
39
  "format": "bunx --bun prettier . --write",
43
40
  "format:check": "bunx --bun prettier . --check",
44
41
  "lint": "bun --bun eslint .",
45
42
  "lint:fix": "bun --bun eslint . --fix",
46
43
  "test": "bun test --no-orphans --reporter=dots",
44
+ "test:e2e": "bun --config=bunfig.e2e.toml test --no-orphans ./test/e2e/direct-worker-runtime.test.ts --reporter=dots",
47
45
  "test:coverage": "bun --config=bunfig.coverage.toml test --no-orphans --reporter=dots && bun run coverage:check",
48
46
  "coverage:check": "bun .github/scripts/check-coverage.mjs coverage/full/lcov.info",
49
- "test:e2e": "bun --config=bunfig.e2e.toml test --no-orphans test/e2e/workflow-runtime.test.ts --reporter=dots",
50
47
  "typecheck": "tsc --noEmit",
51
48
  "check": "bun run lint && bun run format:check && bun run typecheck && bun run test:coverage && bun run test:e2e && bun run build"
52
49
  },
@@ -56,29 +53,22 @@
56
53
  "peerDependencies": {
57
54
  "@earendil-works/pi-coding-agent": "*",
58
55
  "@earendil-works/pi-tui": "*",
59
- "pi-subagents": ">=0.36.0",
60
56
  "typebox": "*"
61
57
  },
62
- "peerDependenciesMeta": {
63
- "pi-subagents": {
64
- "optional": true
65
- }
66
- },
67
58
  "devDependencies": {
68
59
  "@earendil-works/pi-coding-agent": "^0.81.1",
69
60
  "@earendil-works/pi-tui": "^0.81.1",
70
61
  "@eslint/js": "^10.0.1",
71
- "@types/bun": "^1.3.14",
62
+ "@types/bun": "^1.4.0",
72
63
  "@types/node": "^24.0.0",
73
64
  "eslint": "^10.7.0",
74
65
  "globals": "^17.7.0",
75
- "pi-subagents": "0.36.0",
76
66
  "prettier": "^3.9.5",
77
67
  "typebox": "^1.1.38",
78
68
  "typescript": "^5.9.3",
79
69
  "typescript-eslint": "^8.64.0"
80
70
  },
81
- "packageManager": "bun@1.3.14",
71
+ "packageManager": "bun@1.4.0",
82
72
  "engines": {
83
73
  "node": ">=22.19.0"
84
74
  }
@@ -514,6 +514,61 @@
514
514
  }
515
515
  }
516
516
  },
517
+ "artifactContract": {
518
+ "type": "object",
519
+ "additionalProperties": false,
520
+ "required": [
521
+ "maxChars",
522
+ "requiredSubstrings",
523
+ "forbiddenSubstrings",
524
+ "equalOccurrenceGroups"
525
+ ],
526
+ "properties": {
527
+ "maxChars": {
528
+ "type": "integer",
529
+ "minimum": 1,
530
+ "maximum": 200000
531
+ },
532
+ "requiredSubstrings": {
533
+ "type": "array",
534
+ "maxItems": 32,
535
+ "uniqueItems": true,
536
+ "items": {
537
+ "type": "string",
538
+ "minLength": 1,
539
+ "maxLength": 1024
540
+ }
541
+ },
542
+ "forbiddenSubstrings": {
543
+ "type": "array",
544
+ "maxItems": 32,
545
+ "uniqueItems": true,
546
+ "items": {
547
+ "type": "string",
548
+ "minLength": 1,
549
+ "maxLength": 1024
550
+ }
551
+ },
552
+ "equalOccurrenceGroups": {
553
+ "type": "array",
554
+ "maxItems": 32,
555
+ "items": {
556
+ "type": "array",
557
+ "minItems": 2,
558
+ "maxItems": 32,
559
+ "uniqueItems": true,
560
+ "items": {
561
+ "type": "string",
562
+ "minLength": 1,
563
+ "maxLength": 1024
564
+ }
565
+ }
566
+ },
567
+ "onValidationFailure": {
568
+ "const": "retry"
569
+ }
570
+ }
571
+ },
517
572
  "gate": {
518
573
  "oneOf": [
519
574
  {
@@ -533,6 +588,9 @@
533
588
  },
534
589
  "rejectedOutcome": {
535
590
  "$ref": "#/$defs/identifier"
591
+ },
592
+ "artifactContract": {
593
+ "$ref": "#/$defs/artifactContract"
536
594
  }
537
595
  }
538
596
  },
@@ -563,6 +621,9 @@
563
621
  "minimum": 1000,
564
622
  "maximum": 30000,
565
623
  "default": 30000
624
+ },
625
+ "artifactContract": {
626
+ "$ref": "#/$defs/artifactContract"
566
627
  }
567
628
  }
568
629
  }
@@ -597,19 +658,6 @@
597
658
  "type": "object",
598
659
  "additionalProperties": false,
599
660
  "required": ["prompt", "transitions"],
600
- "allOf": [
601
- {
602
- "if": {
603
- "required": ["workspace"]
604
- },
605
- "then": {
606
- "required": ["subagent"],
607
- "not": {
608
- "required": ["gate"]
609
- }
610
- }
611
- }
612
- ],
613
661
  "properties": {
614
662
  "title": {
615
663
  "type": "string",
@@ -618,8 +666,8 @@
618
666
  "prompt": {
619
667
  "$ref": "#/$defs/prompt"
620
668
  },
621
- "subagent": {
622
- "$ref": "#/$defs/subagent"
669
+ "agent": {
670
+ "$ref": "#/$defs/subagentRuntimeName"
623
671
  },
624
672
  "permissions": {
625
673
  "$ref": "#/$defs/permissions"
@@ -0,0 +1,36 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+
5
+ const target =
6
+ process.env.HERDR_PI_EXTENSION_PATH ??
7
+ join(homedir(), '.pi', 'agent', 'extensions', 'herdr-agent-state.ts');
8
+ const source = await readFile(target, 'utf8');
9
+ if (source.includes('pi-workflows-herdr-lifecycle-patch:start')) {
10
+ console.log(`Herdr workflow patch already present: ${target}`);
11
+ process.exit(0);
12
+ }
13
+ const state =
14
+ ' // pi-workflows-herdr-lifecycle-patch:start\n let workflowActive = false;\n let workflowMessage: string | undefined;\n // pi-workflows-herdr-lifecycle-patch:end\n';
15
+ const listener =
16
+ ' // pi-workflows-herdr-lifecycle-patch:start\n pi.events.on("pi-workflows:state", (data) => {\n if (!rootSession || !data || typeof data !== "object") return;\n const event = data as { state?: string; message?: string };\n workflowActive = event.state === "working";\n workflowMessage = event.message;\n publishState();\n });\n // pi-workflows-herdr-lifecycle-patch:end\n\n';
17
+ let patched = source.replace(
18
+ ' let blockedCount = 0;',
19
+ `${state} let blockedCount = 0;`,
20
+ );
21
+ patched = patched.replace(
22
+ ' if (agentActive) {\n return { state: "working" as const, message: undefined };',
23
+ ' if (agentActive || workflowActive) {\n return { state: "working" as const, message: workflowMessage };',
24
+ );
25
+ patched = patched.replace(
26
+ ' return { state: "idle" as const, message: undefined };',
27
+ ' return { state: "idle" as const, message: workflowMessage };',
28
+ );
29
+ patched = patched.replace(
30
+ ' pi.events.on("herdr:blocked",',
31
+ `${listener} pi.events.on("herdr:blocked",`,
32
+ );
33
+ if (patched === source)
34
+ throw new Error(`Unsupported Herdr integration layout: ${target}`);
35
+ await writeFile(target, patched);
36
+ console.log(`Patched Herdr workflow lifecycle reporting: ${target}`);