relay-flow 0.2.1-alpha → 0.2.3-alpha

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 (83) hide show
  1. package/README.md +193 -25
  2. package/cmd/relay-flow/beads_composition_test.go +451 -0
  3. package/cmd/relay-flow/commands_test.go +79 -1
  4. package/cmd/relay-flow/main.go +50 -1
  5. package/cmd/relay-flow/scenario_test.go +48 -12
  6. package/cmd/relay-flow/serve.go +16 -2
  7. package/examples/beads-workflow.yaml +74 -0
  8. package/examples/default-story-workflow.yaml +6 -6
  9. package/go.mod +2 -1
  10. package/go.sum +2 -0
  11. package/internal/config/config.go +13 -2
  12. package/internal/config/merge_test.go +18 -0
  13. package/internal/execution/goworkflows/activities.go +124 -56
  14. package/internal/execution/goworkflows/end_feedback_test.go +124 -0
  15. package/internal/execution/goworkflows/engine.go +20 -0
  16. package/internal/execution/goworkflows/engine_test.go +33 -15
  17. package/internal/execution/goworkflows/fakes_test.go +84 -10
  18. package/internal/execution/goworkflows/interpreter.go +84 -30
  19. package/internal/execution/goworkflows/mailbox_test.go +85 -0
  20. package/internal/execution/goworkflows/node_runtime_test.go +30 -5
  21. package/internal/execution/goworkflows/projection.go +52 -11
  22. package/internal/execution/goworkflows/recovery_test.go +131 -2
  23. package/internal/execution/goworkflows/report_contract_fixture_test.go +31 -0
  24. package/internal/harness/contract_test.go +10 -0
  25. package/internal/harness/factory.go +25 -3
  26. package/internal/harness/harness.go +30 -4
  27. package/internal/harness/opencode/opencode.go +125 -10
  28. package/internal/harness/opencode/opencode_test.go +238 -0
  29. package/internal/harness/opencode/repo_setup.go +401 -0
  30. package/internal/harness/plugin_selection_test.go +5 -5
  31. package/internal/identity/identity.go +28 -1
  32. package/internal/identity/identity_test.go +40 -0
  33. package/internal/recover/recover.go +11 -6
  34. package/internal/repo/service.go +10 -0
  35. package/internal/repo/service_test.go +51 -2
  36. package/internal/run/manager.go +193 -25
  37. package/internal/run/run.go +30 -10
  38. package/internal/run/run_manager_test.go +100 -0
  39. package/internal/server/api_test.go +54 -0
  40. package/internal/server/client.go +11 -0
  41. package/internal/server/fixture_test.go +18 -0
  42. package/internal/server/server.go +16 -0
  43. package/internal/task/beads/bdcli/bdcli.go +323 -0
  44. package/internal/task/beads/bdcli/bdcli_test.go +297 -0
  45. package/internal/task/beads/bdcli/testdata/array.json +1 -0
  46. package/internal/task/beads/bdcli/testdata/children.json +1 -0
  47. package/internal/task/beads/bdcli/testdata/claimed.json +1 -0
  48. package/internal/task/beads/bdcli/testdata/commented.json +1 -0
  49. package/internal/task/beads/bdcli/testdata/comments.json +1 -0
  50. package/internal/task/beads/bdcli/testdata/created.json +1 -0
  51. package/internal/task/beads/bdcli/testdata/empty.json +1 -0
  52. package/internal/task/beads/bdcli/testdata/object.json +1 -0
  53. package/internal/task/beads/bdcli/testdata/ready.json +1 -0
  54. package/internal/task/beads/bdcli/testdata/show.json +1 -0
  55. package/internal/task/beads/bdcli/testdata/strict-bd.sh +149 -0
  56. package/internal/task/beads/bdcli/testdata/updated.json +1 -0
  57. package/internal/task/beads/beads.go +856 -0
  58. package/internal/task/beads/beads_test.go +609 -0
  59. package/internal/task/beads/comments_test.go +242 -0
  60. package/internal/task/beads/config_compatibility_test.go +163 -0
  61. package/internal/task/beads/lifecycle_inheritance_test.go +168 -0
  62. package/internal/task/beads/repo_composition_test.go +232 -0
  63. package/internal/task/beads/runtime_config_test.go +81 -0
  64. package/internal/task/beads/status_compatibility_test.go +276 -0
  65. package/internal/task/beads/status_test.go +257 -0
  66. package/internal/task/beads/testdata/strict-bd-repo.sh +27 -0
  67. package/internal/task/beads/validation_test.go +110 -0
  68. package/internal/task/contract_test.go +10 -0
  69. package/internal/task/factory.go +37 -4
  70. package/internal/task/jira/auth.go +27 -1
  71. package/internal/task/jira/auth_test.go +54 -1
  72. package/internal/task/jira/filters_test.go +60 -0
  73. package/internal/task/jira/helpers_test.go +3 -0
  74. package/internal/task/jira/jira.go +187 -29
  75. package/internal/task/jira/lifecycle_inheritance_test.go +172 -0
  76. package/internal/task/jira/rest/adf.go +119 -82
  77. package/internal/task/jira/rest/adf_test.go +60 -0
  78. package/internal/task/jira/rest/client_test.go +1 -1
  79. package/internal/task/jira/templates_test.go +118 -0
  80. package/internal/task/jira/transition_defaults_test.go +47 -2
  81. package/internal/task/task.go +40 -0
  82. package/internal/workflow/report_test.go +45 -0
  83. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # relay-flow
2
2
 
3
- Durable, graph-based agent workflow runner. A ticket is the unit of work; a workflow YAML declares nodes and routes; a durable engine (go-workflows + SQLite) drives progression, waits, retries, and recovery. The task system (Jira built-in) supplies parent tickets and mailbox subtasks; the runner (Orca built-in) owns worktrees and terminals; the harness (OpenCode built-in) owns agent sessions and report semantics. All three are pluggable.
3
+ Durable, graph-based agent workflow runner. A ticket is the unit of work; a workflow YAML declares nodes and routes; a durable engine (go-workflows + SQLite) drives progression, waits, retries, and recovery. The task system (Jira and Beads built-ins) supplies parent tickets and mailbox subtasks; the runner (Orca built-in) owns worktrees and terminals; the harness (OpenCode built-in) owns agent sessions and report semantics. All three are pluggable.
4
4
 
5
5
  This is a ground-up rewrite. The previous per-workflow, in-memory daemon is gone. There is no migration path and no compatibility layer.
6
6
 
@@ -14,7 +14,9 @@ This is a ground-up rewrite. The previous per-workflow, in-memory daemon is gone
14
14
  |---|---|
15
15
  | [opencode](https://opencode.ai) | Agents run in opencode sessions (harness) |
16
16
  | [Orca](https://github.com/Necmttn/orca) CLI + app | Worktrees + terminals (runner) |
17
- | Jira API token | Jira REST API v3 access (task system) |
17
+ | `bd` CLI | Beads task-system access (required when `taskPlugin: beads`) |
18
+ | Dolt | External/server-backed Beads only |
19
+ | Jira API token | Jira REST API v3 access (required when `taskPlugin: jira`) |
18
20
  | Go 1.24+ | Build the CLI |
19
21
 
20
22
  ### Install
@@ -23,7 +25,7 @@ This is a ground-up rewrite. The previous per-workflow, in-memory daemon is gone
23
25
  go install github.com/rajpopat27/relay-flow/cmd/relay-flow@latest
24
26
  ```
25
27
 
26
- OpenCode plugin: add `"relay-flow-plugin"` to the `plugin` array in your repo's `opencode.json`:
28
+ OpenCode plugin configuration uses both entrypoints. The server entrypoint is listed in `opencode.json`:
27
29
 
28
30
  ```json
29
31
  {
@@ -32,7 +34,22 @@ OpenCode plugin: add `"relay-flow-plugin"` to the `plugin` array in your repo's
32
34
  }
33
35
  ```
34
36
 
35
- The plugin is the report-path half of the harness contract: it registers each emitted harness session with `{runId, node, sessionId}`, parses the agent's structured report, applies the agent/HITL nudge policy, and delivers `{runId, node, reportId, report}` via `relay-flow report` with retry. `reportId` comes from the harness session/message identity; `nodeVisitID` is internal and is never part of either plugin payload.
37
+ The native HITL approval entrypoint is listed in `.opencode/tui.json`:
38
+
39
+ ```json
40
+ {
41
+ "$schema": "https://opencode.ai/tui.json",
42
+ "plugin": ["relay-flow-plugin"]
43
+ }
44
+ ```
45
+
46
+ The OpenCode harness adds both entries when a repo is registered. The server
47
+ entrypoint registers sessions, handles agent reports, and nudges invalid agent
48
+ output. The TUI entrypoint handles only HITL reports: after a valid completed
49
+ assistant report it shows a native Approve/Reject dialog. Approval delivers
50
+ `{runId, node, reportId, report}` via `relay-flow report` with retry; rejection
51
+ delivers nothing. `reportId` comes from the harness session/message identity;
52
+ `nodeVisitID` is internal and is never part of either plugin payload.
36
53
 
37
54
  ### One-time machine setup
38
55
 
@@ -43,6 +60,14 @@ relay-flow task auth
43
60
 
44
61
  `init` only selects the task system, runner, and harness (singleton options are automatic), writes machine config, and initializes SQLite. `task auth` delegates authentication to that selected task plug-in. Jira prompts for its site, email, and masked API token, validates `/myself`, and owns the system-wide `credentials.yaml`; for scripts, pass `task auth --site`, `--email`, and `--token`. A normal init rerun refuses existing state. `relay-flow init --force` updates safe stopped instances while preserving durable and repo state.
45
62
 
63
+ For Beads, select the plugin explicitly when scripting setup:
64
+
65
+ ```sh
66
+ relay-flow init --task-plugin beads --runner-plugin orca --harness-plugin opencode
67
+ ```
68
+
69
+ Beads authentication is owned by the Beads workspace and its `bd`/Dolt configuration. `relay-flow task auth` is a no-op for Beads and does not create relay-flow credentials; do not add a Jira token to a Beads-only installation.
70
+
46
71
  The full machine layout is fixed under `~/.relay-flow` (0700):
47
72
 
48
73
  ```
@@ -58,6 +83,23 @@ workflows/<name>.yaml 0644 submitted workflow definitions
58
83
 
59
84
  ### Register a repo
60
85
 
86
+ `repo register` and `workflow submit` are server-backed commands: start the
87
+ server first, otherwise they fail with `dial unix ~/.relay-flow/server.sock:
88
+ connect: no such file or directory`.
89
+
90
+ ```sh
91
+ relay-flow serve --background
92
+ ```
93
+
94
+ The repo must already exist in the runner. For the Orca runner, add it first
95
+ and keep the names aligned — the runner resolves a repo by path **and** display
96
+ name, so `--name` must equal the Orca display name (Orca derives it from the
97
+ directory name):
98
+
99
+ ```sh
100
+ orca repo add --path /work/payments # displayName becomes "payments"
101
+ ```
102
+
61
103
  ```sh
62
104
  relay-flow repo register
63
105
  ```
@@ -68,6 +110,78 @@ Each Jira poll uses REST v3 enhanced search and requests linked-issue status wit
68
110
 
69
111
  For scripts, use `relay-flow repo register --name <name> --path <path> --set project=<project>`. Component is always derived from `--name` and cannot be overridden. Registration is rejected while another repo already holds the same canonical task scope.
70
112
 
113
+ ### Beads task system
114
+
115
+ Beads uses the local `bd` CLI and supports both an embedded workspace and a workspace backed by an externally managed Dolt server. Install and verify the tools before registering a Beads repo:
116
+
117
+ ```sh
118
+ bd --version
119
+ # Required only for server-backed workspaces:
120
+ dolt version
121
+ ```
122
+
123
+ Initialize the Beads workspace before `repo register`; relay-flow never initializes a workspace, runs migrations, or starts `bd serve`.
124
+
125
+ For a local workspace, keep the workspace beside the code repository and use its `.beads` directory as `beadsDir`:
126
+
127
+ ```sh
128
+ cd /work/payments
129
+ bd init --prefix payments
130
+ # code repository: /work/payments
131
+ # Beads workspace: /work/payments/.beads
132
+ ```
133
+
134
+ For a server-backed workspace, an operator starts and manages Dolt separately, then initializes Beads with external-server metadata. The exact server host, port, credentials, and data directory belong to that Beads/Dolt deployment; relay-flow does not manage their lifecycle:
135
+
136
+ ```sh
137
+ # Run this from the externally managed Beads/Dolt environment, not from relay-flow.
138
+ BEADS_DOLT_SERVER_TLS=0 \
139
+ BEADS_DOLT_PASSWORD= \
140
+ bd init \
141
+ --server \
142
+ --external \
143
+ --server-host 127.0.0.1 \
144
+ --server-port 13307 \
145
+ --server-user root \
146
+ --prefix payments \
147
+ --non-interactive \
148
+ --skip-hooks \
149
+ --skip-agents
150
+ # Example external workspace: /var/lib/beads/payments/.beads
151
+ ```
152
+
153
+ Register the code repository and its Beads workspace separately. `beadsDir` is required for every Beads repo, must name an existing directory, and is the task scope used to reject duplicate workspace registration:
154
+
155
+ ```sh
156
+ # Local/embedded workspace
157
+ relay-flow repo register \
158
+ --name payments \
159
+ --path /work/payments \
160
+ --set beadsDir=/work/payments/.beads
161
+
162
+ # External/server-backed workspace
163
+ relay-flow repo register \
164
+ --name payments \
165
+ --path /work/payments \
166
+ --set beadsDir=/var/lib/beads/payments/.beads
167
+ ```
168
+
169
+ The registered `--path` remains the code/runner repository. Every `bd` command runs with that path as its working directory and the configured `beadsDir` as `BEADS_DIR`, even when unrelated Beads selector variables exist in the relay-flow environment. Two repos may register different canonical `beadsDir` values; a second repo pointing at the same workspace is rejected. A Beads prefix such as `payments-...` is optional and only makes issue IDs recognizable—it is not a component, workspace selector, poller selector, or database isolation mechanism.
170
+
171
+ Beads workflow filters are structured and evaluated in relay-flow. For example, `examples/beads-workflow.yaml` uses the Beads status and issue-type fields:
172
+
173
+ ```yaml
174
+ taskConfig:
175
+ filters:
176
+ parentStatuses: [open]
177
+ issueTypes: [epic]
178
+ labels: [relay-ready]
179
+ ```
180
+
181
+ The supported Beads status names are `open`, `in_progress`, `blocked`, `deferred`, `hooked`, and `closed`. The claimed-parent poll uses the canonical active set `open,in_progress,blocked,deferred`; it intentionally does not substitute `hooked` for `deferred`. Omitted lifecycle settings move the parent to `in_progress` at `start`, a work-node mailbox to `in_progress`, and the parent to `closed` at `end` — the same shape as Jira, with Beads-native values. Relay-flow creates one Repo Poller per registered repo, not one poller per workflow. Each poll reads ready top-level parents and relay-owned active parents, deduplicates them, and never routes mailbox children. Claims are permanent `wf:<workflow>` labels.
182
+
183
+ Beads does not need relay-flow credentials or a Beads-specific poller. In server mode, leave Dolt and Beads server setup running outside relay-flow and point each repo at its own `beadsDir`.
184
+
71
185
  ### Submit a workflow
72
186
 
73
187
  ```sh
@@ -76,10 +190,13 @@ relay-flow workflow submit --file <path>
76
190
 
77
191
  Workflows live at `~/.relay-flow/workflows/<name>.yaml` after submit. Replacement and removal are rejected while any run of that workflow is active.
78
192
 
79
- Use [`examples/default-story-workflow.yaml`](examples/default-story-workflow.yaml) as a fully annotated starting point. Replace its repo name and uncomment only the optional fields you need.
193
+ Use [`examples/default-story-workflow.yaml`](examples/default-story-workflow.yaml) as a fully annotated Jira-oriented starting point, or [`examples/beads-workflow.yaml`](examples/beads-workflow.yaml) for the Beads filter and lifecycle shape. Replace the repo name and uncomment only the optional fields you need.
80
194
 
81
195
  ### Run
82
196
 
197
+ The server must already be running for `repo register` and `workflow submit`;
198
+ the same process polls repos and drives runs.
199
+
83
200
  ```sh
84
201
  relay-flow serve # normal start; requires an initialized database
85
202
  relay-flow serve --background # detached; returns after the server is ready
@@ -101,13 +218,14 @@ repos: [payments] # one or more registered repos, unique
101
218
  cleanupRunnerOnEnd: false # optional; when true the runner tears down at end
102
219
 
103
220
  taskConfig: # optional; adapter-owned; merged root → repo → workflow → node
104
- transitions:
105
- start: { parent: "In Progress" }
106
- work: { mailbox: "In Progress" }
107
- end: { parent: "Done" }
221
+ filters:
222
+ parentStatuses: [To Do]
108
223
 
109
224
  nodes:
110
225
  start:
226
+ taskConfig: # transitionTo belongs on a node: it applies to
227
+ transitionTo: # the lifecycle point the node represents
228
+ parentStatus: In Progress
111
229
  onSuccess: [{ target: coding }]
112
230
 
113
231
  coding:
@@ -140,7 +258,9 @@ Rules enforced at submit:
140
258
 
141
259
  ### Task-config merge
142
260
 
143
- `taskConfig` may appear at root, repo, workflow, and node scopes. The adapter merges in that order: maps merge recursively, later scalar/list replaces, omitted keys inherit, explicit YAML `null` is rejected. The merged values decode against one adapter-owned typed config at use time.
261
+ `taskConfig` may appear at root, repo, workflow, and node scopes. The adapter merges in that order: maps merge recursively, later scalar/list replaces, omitted keys inherit, explicit YAML `null` is rejected. The merged values decode against one adapter-owned typed config at use time. Adapter lifecycle defaults sit underneath all four scopes, so the effective precedence is `adapter default < root < repo < workflow < node`.
262
+
263
+ `transitionTo` describes one lifecycle point, so configure it on a node. A `transitionTo` set at root, repo, or workflow scope applies to **every** lifecycle point that reads it — including `end`, where a `parentStatus` other than the closing status stops the parent from being closed.
144
264
 
145
265
  ### Jira transition defaults
146
266
 
@@ -150,33 +270,81 @@ Omitted transitions default to:
150
270
  - work node: mailbox → `In Progress` (parent unchanged)
151
271
  - `end`: parent → `Done`
152
272
 
273
+ ### Beads transition defaults
274
+
275
+ Beads follows the same lifecycle shape with Beads-native values:
276
+
277
+ - `start`: parent → `in_progress`
278
+ - work node: mailbox → `in_progress` (parent unchanged)
279
+ - `end`: parent → `closed`
280
+
281
+ A parent moved to `in_progress` stays visible to the claimed-parent poll, which reads `open,in_progress,blocked,deferred`. Entering a node reuses that node's mailbox: a fresh mailbox moves `open → in_progress` and a revisited one moves `closed → in_progress`. Beads reads the issue before every status write, so an already-applied status is a no-op and a status relay-flow did not set (for example a human marking an issue `blocked`) blocks the transition and retries instead of being overwritten.
282
+
283
+ ### Shared task configuration and provider status values
284
+
285
+ Beads and Jira use the shared `filters`, `templates`, optional top-level
286
+ `assignee`, and `transitionTo` field names. `transitionTo` uses
287
+ `parentStatus` for the parent issue and `taskStatus` for a mailbox. In both
288
+ adapters `assignee` is the default assignee filter when `filters.assignees` is
289
+ absent, and an `assignee` in effect for a node also assigns that node's
290
+ mailbox. Beads requires the repo-only `taskConfig.beadsDir` shown above; Jira
291
+ instead uses its repo `project` and `component` keys. `project` and
292
+ `component` are not Beads fields, and a Beads issue prefix is not a component
293
+ or workspace selector. Beads status values remain native (`open`,
294
+ `in_progress`, `blocked`, `deferred`, `hooked`, `closed`), while Jira values
295
+ remain native (`In Progress`, `Done`, and so on); relay-flow does not
296
+ translate arbitrary values between providers. Beads rejects workflow/node-level
297
+ template overrides because the fixed task text rendering contract has no
298
+ lower-scope input.
299
+
153
300
  ---
154
301
 
155
302
  ## Structured node report
156
303
 
157
- Every visit (agent or HITL) ends with the same contract:
304
+ Every visit (agent or HITL) submits one report with the same fixed labels:
158
305
 
159
306
  ```
160
307
  STATUS: success | failure
161
308
  NEXT STEP: <one configured route for that status>
162
309
 
163
- SUMMARY
164
- - Completed: ...
165
- - Not completed: ... | None
166
- - Issues discovered: ... | None
167
- - Verification: ...
168
- - Notes: ... | None
169
-
170
- FEEDBACK
171
- - Reason for next step: ...
172
- - Required actions: ...
173
- - Relevant context: ...
174
- - Expected result: ...
310
+ SUMMARY:
311
+ COMPLETED: ...
312
+ COMMITS: <commit IDs or None>
313
+ NOT COMPLETED: ... | None
314
+ ISSUES DISCOVERED: ... | None
315
+ VERIFICATION: ...
316
+ NOTES: ... | None
317
+
318
+ FEEDBACK:
319
+ REASON FOR NEXT STEP: ...
320
+ REQUIRED ACTIONS: ...
321
+ RELEVANT CONTEXT: ...
322
+ EXPECTED RESULT: ...
175
323
  ```
176
324
 
177
- `None` is the literal marker for an intentionally empty section. When `NEXT STEP` is `end`, every FEEDBACK field must be `None` and no feedback comment is written.
325
+ The labels above are fixed; configurable templates do not change the parsed report contract. The plugin submits one `report` object containing both lower-camel `summary` and `feedback` objects. Relay-flow validates that complete shape once, renders `summaryReport` through the task system's summary-comment template on the current mailbox, and renders `feedbackReport` through its feedback-comment template on only the selected next mailbox. `None` is the literal marker for an intentionally empty section. When `NEXT STEP` is `end`, every FEEDBACK field must be `None` and no feedback comment is written.
326
+
327
+ The plugin delivers `{runId, node, reportId, report}` as one JSON object via `relay-flow report` stdin with the shared backoff (initial 2s, factor 2, jitter 0.2, max 5m) until acknowledged. It derives `reportId` from the harness session/message identity. Duplicate/stale reports are acked safely with no repeated graph effects. Invalid agent output is nudged; invalid or missing HITL output stays silent, while a valid HITL report opens the native TUI approval dialog. Relay-flow HITL approval does not use OpenCode's Question tool.
328
+
329
+ ---
330
+
331
+ ## Canceled run restart
332
+
333
+ Cancellation is permanent for the current execution. A canceled ticket is not
334
+ restarted by polling or by a ticket-status change. Start a fresh attempt
335
+ explicitly:
336
+
337
+ ```sh
338
+ relay-flow run restart --ticket PAY-101
339
+ ```
178
340
 
179
- The plugin delivers `{runId, node, reportId, report}` as one JSON object via `relay-flow report` stdin with the shared backoff (initial 2s, factor 2, jitter 0.2, max 5m) until acknowledged. It derives `reportId` from the harness session/message identity. Duplicate/stale reports are acked safely with no repeated graph effects. Invalid agent output is nudged; invalid HITL output stays silent.
341
+ The new attempt starts at `start`, preserves the existing worktree/mailboxes/
342
+ comments/labels, and uses a numeric attempt ID (`2`, `3`, ...), with a fenced
343
+ execution ID such as `payments/basicFlow/PAY-101~attempt~2`. If a human has
344
+ moved the parent ticket to an incompatible status, `run get` shows `blocked`
345
+ with an instruction to move it to an allowed active start status; relay-flow
346
+ retries automatically and never overwrites the human-owned status. Done/Closed
347
+ tickets are not reopened automatically.
180
348
 
181
349
  ---
182
350