pi-taskflow 0.0.17 → 0.0.19

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.
@@ -50,7 +50,7 @@ Keys of each object in `phases[]`. Some only apply to specific `type`s.
50
50
  ```jsonc
51
51
  {
52
52
  "id": "audit", // required, unique — referenced via {steps.audit.output}
53
- "type": "map", // agent | parallel | map | gate | reduce (default: agent)
53
+ "type": "map", // agent | parallel | map | gate | reduce | approval | flow | loop | tournament (default: agent)
54
54
  "agent": "analyst", // agent name to run this phase
55
55
  "task": "Audit {item.route}…",
56
56
  "dependsOn": ["discover"],// DAG edges
@@ -71,7 +71,7 @@ Keys of each object in `phases[]`. Some only apply to specific `type`s.
71
71
  | Key | Applies to | Default | Notes |
72
72
  |-----|-----------|---------|-------|
73
73
  | `id` | all | — | **Required, unique.** Used in `{steps.<id>…}`. |
74
- | `type` | all | `agent` | One of the 5 phase types. |
74
+ | `type` | all | `agent` | One of the 9 phase types (agent, parallel, map, gate, reduce, approval, flow, loop, tournament). |
75
75
  | `agent` | all | first available | Agent name; resolved from the scoped pool. |
76
76
  | `task` | agent, gate, map, reduce | — | Prompt; supports interpolation. Required for these types. |
77
77
  | `over` | map | — | **Required for map.** Must resolve to an array. |
@@ -85,8 +85,52 @@ Keys of each object in `phases[]`. Some only apply to specific `type`s.
85
85
  | `tools` | all | agent default | Whitelist of tools for the subagent. See §5. |
86
86
  | `cwd` | all | flow cwd | Run this phase's subagent in a different directory. |
87
87
  | `concurrency` | map, parallel | flow concurrency | Fan-out cap for this phase only. See §4. |
88
+ | `context` | all | — | File paths / `{steps.X}` refs to **pre-read and inject** before the task. See §2.1. |
89
+ | `contextLimit` | all | `8000` | Max characters read **per file** in `context`. See §2.1. |
90
+ | `cache` | all | `run-only` | Per-phase cache policy (`scope`/`ttl`/`fingerprint`). See §11. |
88
91
  | `final` | all | last phase | Exactly one phase may be `final`; its output is returned. |
89
92
 
93
+ > Gate-only control fields (`eval`, `onBlock`) and the loop/tournament control
94
+ > fields (`until`/`maxIterations`/`convergence`, `variants`/`judge`/`judgeAgent`/`mode`)
95
+ > are documented in `SKILL.md` next to their phase types.
96
+
97
+ ---
98
+
99
+ ## 2.1 Context pre-reading (`context` / `contextLimit`)
100
+
101
+ Instead of making a subagent *discover* files by exploring (an O(N²) turn-cost
102
+ spiral), you can **pre-read** known files and inject their contents ahead of the
103
+ task prompt. List file paths and/or `{steps.X}` refs in `context`; the runtime
104
+ resolves interpolated refs first, then reads each file and prepends labeled
105
+ blocks to the task.
106
+
107
+ ```jsonc
108
+ {
109
+ "id": "review",
110
+ "type": "agent",
111
+ "agent": "reviewer",
112
+ "context": ["src/auth.ts", "src/middleware.ts", "{steps.spec.output}"],
113
+ "contextLimit": 12000,
114
+ "task": "Review the auth flow against the spec above. VERDICT: PASS or BLOCK.",
115
+ "dependsOn": ["spec"]
116
+ }
117
+ ```
118
+
119
+ **Behavior & limits (all enforced in the runtime):**
120
+
121
+ | Aspect | Rule |
122
+ |--------|------|
123
+ | Resolution order | interpolate `{steps.X}` / `{args.X}` refs **first**, then read file paths. |
124
+ | Per-file cap | `contextLimit` characters per file (default **8000**); longer files are truncated with a marker. |
125
+ | Total cap | the combined injected block is hard-capped at **200,000 chars**; overflow is truncated with a notice. |
126
+ | Unreadable file | skipped with a `console.warn` (never aborts the phase). |
127
+ | JSON-looking entry | a value that looks like a JSON blob (not a path) is diagnosed and skipped, not read as a file. |
128
+
129
+ Use `context` for **known, bounded** inputs (a handful of source files, an
130
+ upstream phase's output). For large/unknown exploration, let the agent use its
131
+ `read`/`grep` tools instead — pre-reading hundreds of files just hits the total
132
+ cap.
133
+
90
134
  ---
91
135
 
92
136
  ## 3. Declaring & passing arguments
@@ -209,7 +253,73 @@ Taskflow shares the subagent settings file at `~/.pi/agent/settings.json`:
209
253
 
210
254
  ---
211
255
 
212
- ## 8. Environment variables
256
+ ## 8. Cross-run caching (`cache`)
257
+
258
+ By default every phase is **`run-only`**: completed phases are reused only when
259
+ you *resume the same run* (the historical behavior). Opt a phase into the
260
+ persistent **cross-run** memoization store to reuse an identical-input result
261
+ from *any prior run* — instant, zero tokens. See `docs/rfc-cross-run-memoization.md`
262
+ for the design.
263
+
264
+ ```jsonc
265
+ {
266
+ "id": "summarize-deps",
267
+ "type": "agent",
268
+ "agent": "writer",
269
+ "task": "Summarize the dependency tree of this repo.",
270
+ "cache": {
271
+ "scope": "cross-run",
272
+ "ttl": "6h",
273
+ "fingerprint": ["git:HEAD", "file:package-lock.json"]
274
+ }
275
+ }
276
+ ```
277
+
278
+ ### `scope`
279
+
280
+ | Value | Meaning |
281
+ |-------|---------|
282
+ | `run-only` (default) | Reuse only within a resumed run — exactly the historical behavior. |
283
+ | `cross-run` | Reuse an identical-input result from **any** prior run (the persistent store). |
284
+ | `off` | Never reuse, even within a run (force re-execution every time). |
285
+
286
+ ### `ttl` (cross-run only)
287
+
288
+ Max age before a cross-run hit is treated as a miss: e.g. `"30m"`, `"6h"`, `"7d"`.
289
+ Omit for no time bound. A hit older than the TTL re-executes the phase.
290
+
291
+ ### `fingerprint` (cross-run only)
292
+
293
+ The cache key is normally `phaseId + agent + model + interpolated-task`. A
294
+ fingerprint folds **“did the world change?”** signals into that key, so an
295
+ external change becomes a cache **miss** even when the task text is identical.
296
+ Each entry is one of:
297
+
298
+ | Entry | Becomes a miss when… | Resolves to |
299
+ |-------|----------------------|-------------|
300
+ | `git:HEAD` / `git:<ref>` | the commit moves | the resolved SHA (30s timeout → `<timeout>`; no git → `<no-git>`) |
301
+ | `glob:<pattern>` | the **set of matching paths** changes | sorted path list (mtime-free) |
302
+ | `glob!:<pattern>` | the **contents** of matching files change | content hashes (capped at 5000 matches) |
303
+ | `file:<path>` | that file's content changes | sha256 of the file (>10 MB or missing → `<skip>`/`<missing>`) |
304
+ | `env:<NAME>` | the env var changes | the env value |
305
+
306
+ ### What is cached, and when
307
+
308
+ - Only phases whose **`status` is `done`** and that **were not themselves a cache
309
+ hit** are written to the store (no re-storing a value just read).
310
+ - The store is keyed by the full input hash + fingerprint, tagged with
311
+ `flowName`/`phaseId`/`runId`/`model` for inspection and LRU eviction.
312
+ - Cross-run reuse is **safe by construction**: a different agent, model, task, or
313
+ fingerprint produces a different key, so stale results are never served.
314
+
315
+ > **When to use it:** expensive, deterministic phases whose inputs rarely change
316
+ > (dependency summaries, doc generation, repeated audits of the same tree). For
317
+ > phases that *should* re-run every time (anything reading live external state
318
+ > without a fingerprint), leave the default `run-only` or set `off`.
319
+
320
+ ---
321
+
322
+ ## 9. Environment variables
213
323
 
214
324
  | Variable | Effect |
215
325
  |----------|--------|
@@ -217,7 +327,7 @@ Taskflow shares the subagent settings file at `~/.pi/agent/settings.json`:
217
327
 
218
328
  ---
219
329
 
220
- ## 9. Storage & file locations
330
+ ## 10. Storage & file locations
221
331
 
222
332
  | What | Path | Commit? |
223
333
  |------|------|---------|
@@ -233,7 +343,7 @@ Taskflow shares the subagent settings file at `~/.pi/agent/settings.json`:
233
343
 
234
344
  ---
235
345
 
236
- ## 10. Quick recipes
346
+ ## 11. Quick recipes
237
347
 
238
348
  **Pin a strong model only for the review gate:**
239
349
  ```jsonc