flow-like-a-river 0.1.0__tar.gz

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.
@@ -0,0 +1,477 @@
1
+ Metadata-Version: 2.4
2
+ Name: flow-like-a-river
3
+ Version: 0.1.0
4
+ Summary: Flow-driven CLI runtime for Codex agent sessions.
5
+ Project-URL: Homepage, https://github.com/yieldthought/flow
6
+ Project-URL: Repository, https://github.com/yieldthought/flow
7
+ Project-URL: Issues, https://github.com/yieldthought/flow/issues
8
+ Keywords: agent,codex,cli,workflow,flowchart,tmux
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Software Development
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: PyYAML>=6.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: build>=1.2; extra == "dev"
22
+ Requires-Dist: pytest>=8.0; extra == "dev"
23
+ Requires-Dist: twine>=5.0; extra == "dev"
24
+
25
+ # flow
26
+
27
+ `flow` runs agents through flowchart-like workflows in the background. You can watch them and help if they need it. An simple flow:
28
+
29
+ ```yaml
30
+ flow:
31
+ name: agi-watcher
32
+ mode: read-only
33
+ args:
34
+ site:
35
+ help: news site to monitor
36
+
37
+ check-news:
38
+ start: true
39
+ thinking: low
40
+ prompt: Check {{site}} to see if there's a story about AGI being achieved
41
+ transitions:
42
+ - if: there is news that AGI has been acheived
43
+ go: investigate
44
+ - if: there are no stories about AGI being achieved
45
+ wait: 60m
46
+ go: check-news
47
+
48
+ investigate:
49
+ thinking: xhigh
50
+ prompt: |
51
+ Read the article, comments and any sources you can find.
52
+ Decide whether AGI really has been achieved or if this is just hype.
53
+ transitions:
54
+ - if: AGI really has been acheived
55
+ go: its-over
56
+ - if: AGI has probably not been achieved
57
+ go: check-news
58
+
59
+ its-over:
60
+ mode: yolo
61
+ prompt: |
62
+ Use pushover to send the user a short summary of the situation.
63
+ Then send another reminding them to go outside, lie on the grass and enjoy the sun.
64
+ end: true
65
+ ```
66
+
67
+ Use it like this:
68
+
69
+ ```bash
70
+ $ flow start agi-watcher.yaml --site news.ycombinator.com
71
+ ```
72
+
73
+ Monitor the situation:
74
+
75
+ ```bash
76
+ $ flow list
77
+ $ flow list --top
78
+ Runtime active | uptime 00:18:01 | active agents 3 | total agents 4 | cumulative agent time 00:11:18
79
+
80
+ agi-watcher
81
+ check-news
82
+ #6 waiting 00:42:32 ~/work/agent-flows site=news.ycombinator.com
83
+ #7 waiting 00:42:43 ~/work/agent-flows site=reddit.com/r/locallama
84
+ #8 working 00:00:19 ~/work/agent-flows site=https://karpathy.github.io
85
+ ```
86
+
87
+ Check what a specific agent has been up to:
88
+
89
+ ```bash
90
+ $ flow show 6
91
+ $ flow show 6 --top
92
+ agi-watcher in ~/work/agent-flows (started 23:57 on Apr 1 | 0h 0m running, 0h 6m waiting)
93
+ State check-news | Substate normal | Phase waiting
94
+ Status Waiting until 2026-04-01T22:58:16Z
95
+ site: news.ycombinator.com
96
+
97
+ Events
98
+ 23:57 on Apr 1 (0h 0m): check-news started
99
+ 23:58 on Apr 1 (0h 0m): check-news -> check-news "Checked the live Hacker News front page and relevant HN search results; no current story claims AGI has been achieved."
100
+ 23:58 on Apr 1 (0h 0m): check-news wait for 60m until 00:58 on Apr 2
101
+ ```
102
+
103
+ View and interact with any codex session directly in your terminal:
104
+
105
+ ```bash
106
+ $ flow view 6
107
+ ```
108
+
109
+ View many agents in lots of little windows:
110
+
111
+ ```bash
112
+ $ flow view --all
113
+ ```
114
+
115
+ You have complete control at all times, including pausing and resuming automation for an agent, interrupting it, moving to another state and more. Read the CLI overview for the details.
116
+
117
+ The main idea is simple:
118
+
119
+ - a flow is a graph of named states
120
+ - each state can give the agent a prompt
121
+ - each state has outgoing transitions
122
+ - after a turn, the agent chooses the next transition in JSON
123
+ - the runtime moves the agent, waits, pauses, or asks for help as needed
124
+ - every agent is running in a tmux session you can attach to and view or interact with if you have to
125
+
126
+ `flow` is built for asynchronous work. You start agents, the runtime keeps them moving through a flowchart in the background, and you inspect or intervene only when you want to.
127
+
128
+ ## Principles
129
+
130
+ - Each agent is always in exactly one state.
131
+ - Flows are plain YAML, meant to be easy for both humans and agents to read and write.
132
+ - Starting an agent snapshots the flow file. Later edits only affect new agents.
133
+ - The runtime is persistent. Agent state lives in `~/.flow` by default.
134
+ - Each agent gets its own tmux session and long-lived Codex process.
135
+ - Codex uses your normal shared `~/.codex` home, so your usual config, auth, and skills still apply.
136
+ - Waiting, pausing, interruption, and recovery are first-class runtime concepts.
137
+
138
+ ## Requirements
139
+
140
+ - Python 3.10+
141
+ - `tmux`
142
+ - a working Codex CLI setup
143
+
144
+ ## Installation
145
+
146
+ Install the published package:
147
+
148
+ ```bash
149
+ python -m pip install flow-like-a-river
150
+ ```
151
+
152
+ This installs the `flow` CLI command.
153
+
154
+ Development setup in a fresh virtual environment:
155
+
156
+ ```bash
157
+ python -m venv .venv
158
+ . .venv/bin/activate
159
+ python -m pip install --upgrade pip
160
+ python -m pip install -e ".[dev]"
161
+ pytest
162
+ ```
163
+
164
+ ## Runtime model
165
+
166
+ The runtime runs as a detached background process.
167
+
168
+ - `flow init` starts it if needed
169
+ - `flow start ...` also starts it automatically
170
+ - `flow restart` gracefully stops it and starts it again
171
+ - `flow shutdown` lets agents finish their current turn and then stops the runtime
172
+ - `flow shutdown now` kills agents and tmux sessions immediately
173
+
174
+ State is stored in:
175
+
176
+ - `~/.flow/runtime.sqlite3`
177
+ - `~/.flow/logs/daemon.log`
178
+
179
+ You can override the home directory with `FLOW_HOME`.
180
+
181
+ ## Flow files
182
+
183
+ A flow file has:
184
+
185
+ - one top-level `flow:` header block
186
+ - one block per state, e.g. `my-state:`
187
+
188
+ Top-level `flow:` fields:
189
+
190
+ - `name`: flow name
191
+ - `version`: of the flow file format (optional, currently always `1`)
192
+ - `path`: initial working directory for new agents (optional, defaults to the current working directory where `flow start` is run)
193
+ - `mode`: default Codex permissions mode (optional, defaults to `yolo`, other options are `danger-full-access`, `full-auto`, `workspace-write`, `read-only`)
194
+ - `thinking`: default flow reasoning effort (optional, default `xhigh`, other options are `high`, `medium` and `low`)
195
+ - `args`: named CLI arguments for placeholders (optional)
196
+
197
+ State fields:
198
+
199
+ - `start: true`: marks a start state (optional)
200
+ - `end: true`: marks an end state (optional)
201
+ - `wait`: default delay before the state runs (optional)
202
+ - `prompt`: text sent to the agent on entry (optional, state moves directly to transition questions if empty)
203
+ - `mode`: per-state mode override (optional default set in `flow:` header)
204
+ - `thinking`: per-state thinking override (optional, default set in `flow:` header)
205
+ - `transitions`: list of outgoing transitions (optional only if `end: true`)
206
+
207
+ Transition fields:
208
+
209
+ - `if`: natural-language condition, e.g. "the CI tests have all passed"
210
+ - `wait`: optional delay before entering the target state, e.g. "10m"
211
+ - `go`: target state name
212
+
213
+ Placeholders like `{{repo}}` can appear in strings. They become CLI arguments at `flow start` time.
214
+
215
+ Example:
216
+
217
+ ```yaml
218
+ flow:
219
+ name: check-ci
220
+ path: ~/project
221
+ args:
222
+ run_url:
223
+ help: GitHub Actions run URL
224
+
225
+ check:
226
+ start: true
227
+ prompt: |
228
+ Inspect the CI run at {{run_url}}.
229
+ transitions:
230
+ - if: still running
231
+ wait: 10m
232
+ go: check
233
+ - if: passed
234
+ go: notify-pass
235
+ - if: failed
236
+ go: investigate
237
+
238
+ notify-pass:
239
+ prompt: |
240
+ Send a success notification.
241
+ transitions:
242
+ - go: done
243
+
244
+ investigate:
245
+ prompt: |
246
+ Investigate the failure and write a short report.
247
+ transitions:
248
+ - go: done
249
+
250
+ done:
251
+ end: true
252
+ ```
253
+
254
+ ## How a state runs
255
+
256
+ When an agent enters a normal state:
257
+
258
+ 1. Flow sends the state prompt to Codex (optionally after a wait period).
259
+ 2. Codex works until its turn completes.
260
+ 3. Flow asks Codex to choose one transition in strict JSON.
261
+ 4. Flow follows that transition.
262
+
263
+ There are also two implicit choices that change the status of an agent without changing its state:
264
+
265
+ - `keep_working`: stays in the same state and tells Codex to continue working
266
+ - `needs_help`: stops automation for this agent and waits for someone to assist it
267
+
268
+ If a state has no prompt and exactly one unconditional transition, Flow auto-advances without asking Codex anything. This is useful for pure wait states.
269
+
270
+ ## Waiting
271
+
272
+ `wait` can appear on:
273
+
274
+ - a state: default delay when entering that state
275
+ - a transition: override delay for that specific entry
276
+
277
+ Internally, waits become an absolute `ready_at` timestamp.
278
+
279
+ Useful patterns:
280
+
281
+ - poll every 10 minutes by looping back to the same state with `wait: 10m`
282
+ - define a pure wait state with no prompt and one unconditional transition
283
+
284
+ If you want to cancel a wait early:
285
+
286
+ ```bash
287
+ flow wake <agent-id>
288
+ ```
289
+
290
+ `wake` only clears the timer. It does not resume an agent that is paused in `interaction` or `needs_help`.
291
+
292
+ ## CLI overview
293
+
294
+ Validate one or more flow files:
295
+
296
+ ```bash
297
+ flow validate examples/agi-watcher.yaml examples/ci-notify.yaml
298
+ ```
299
+
300
+ Start an agent:
301
+
302
+ ```bash
303
+ flow start examples/agi-watcher.yaml --site news.ycombinator.com
304
+ ```
305
+
306
+ If the flow has more than one start state:
307
+
308
+ ```bash
309
+ flow start my-flow.yaml start-state-name --path ~/work/repo
310
+ ```
311
+
312
+ List active and archived agents:
313
+
314
+ ```bash
315
+ flow list
316
+ flow list agi-watcher
317
+ flow list --top
318
+ ```
319
+
320
+ Show one agent in detail:
321
+
322
+ ```bash
323
+ flow show 12
324
+ flow show 12 --top
325
+ ```
326
+
327
+ `flow show` displays:
328
+
329
+ - flow name and working path
330
+ - start time
331
+ - total running time
332
+ - total waiting time
333
+ - args
334
+ - a timestamped event log
335
+
336
+ With `--top`, `flow list` and `flow show` clear and redraw the screen every five seconds. Press `space` to refresh immediately and `q` to exit.
337
+
338
+ View live tmux sessions:
339
+
340
+ ```bash
341
+ flow view 12
342
+ flow view 12 15 18
343
+ flow view --all
344
+ ```
345
+
346
+ With multiple ids, `flow view` opens a tiled tmux dashboard with one read-only pane per agent.
347
+
348
+ Pause, interrupt, and resume automation:
349
+
350
+ ```bash
351
+ flow pause 12
352
+ flow interrupt 12
353
+ flow resume 12
354
+ ```
355
+
356
+ - `flow pause`: pause automation without sending `Ctrl-C`; if Codex is already working on a turn, that turn is allowed to finish naturally
357
+ - `flow interrupt`: pause automation and also send `Ctrl-C` to the live Codex session
358
+ - `flow resume`: leave `interaction` or `needs_help` and let automation continue
359
+
360
+ Move or stop an agent:
361
+
362
+ ```bash
363
+ flow move 12 investigate
364
+ flow stop 12
365
+ flow stop 12 done
366
+ ```
367
+
368
+ Delete an archived agent entirely:
369
+
370
+ ```bash
371
+ flow delete 12
372
+ ```
373
+
374
+ Manage the runtime:
375
+
376
+ ```bash
377
+ flow init
378
+ flow restart
379
+ flow shutdown
380
+ flow shutdown now
381
+ ```
382
+
383
+ ## Agent states you will see
384
+
385
+ Normal runtime state:
386
+
387
+ - the agent is in a flow state and automation is active
388
+
389
+ Special substates:
390
+
391
+ - `interaction`: you paused or interrupted the agent, and automation is paused
392
+ - `needs_help`: the agent asked for human help and automation is paused
393
+
394
+ Other useful runtime phases:
395
+
396
+ - `waiting`: waiting for `ready_at`
397
+ - `working`: Codex is still working on the current prompt
398
+ - `finished`: the agent reached an end state
399
+
400
+ ## Diagnostics
401
+
402
+ `flow list` includes runtime diagnostics before the state list when relevant.
403
+
404
+ It can show:
405
+
406
+ - daemon crash details if the runtime exited with an error
407
+ - new runtime warnings and errors since the last time you ran `flow list`
408
+ - agent-level `error` and `needs_help` events
409
+
410
+ This is driven by structured runtime diagnostics, not just raw log scraping.
411
+
412
+ ## Example files
413
+
414
+ - `examples/agi-watcher.yaml`
415
+ - `examples/ci-notify.yaml`
416
+
417
+ The examples cover:
418
+
419
+ - placeholders
420
+ - polling with `wait`
421
+ - success and failure transitions
422
+ - push-notification follow-up states
423
+ - a simple realistic monitoring flow
424
+
425
+ ## A typical session
426
+
427
+ Validate a flow:
428
+
429
+ ```bash
430
+ flow validate examples/agi-watcher.yaml
431
+ ```
432
+
433
+ Start an agent:
434
+
435
+ ```bash
436
+ flow start examples/agi-watcher.yaml --site news.ycombinator.com
437
+ ```
438
+
439
+ Watch progress:
440
+
441
+ ```bash
442
+ flow list
443
+ flow list --top
444
+ flow show 1
445
+ flow show 1 --top
446
+ flow view 1
447
+ ```
448
+
449
+ Intervene if needed:
450
+
451
+ ```bash
452
+ flow pause 1
453
+ flow interrupt 1
454
+ flow resume 1
455
+ flow wake 1
456
+ flow move 1 investigate-failure
457
+ ```
458
+
459
+ Restart the runtime after code changes:
460
+
461
+ ```bash
462
+ flow restart
463
+ ```
464
+
465
+ Stop everything cleanly:
466
+
467
+ ```bash
468
+ flow shutdown
469
+ ```
470
+
471
+ ## Notes
472
+
473
+ - Reserved state names are `stopped`, `needs_help`, and `interaction`.
474
+ - End states cannot define `wait`.
475
+ - A state can only have one unconditional transition, and it must be last.
476
+ - Relative paths and `~` in `flow.path` are expanded to absolute paths.
477
+ - Absolute and relative times in `flow show` use your local timezone for display.