feat: add content targets and loop expansion for target templates
Content targets write literal text to files via 'content:' field, without requiring an AI provider or API keys. They are not archived when overwritten. Loop expansion allows defining 'loops:' at the top level with named lists of values. Targets with [var] in their name are expanded via cartesian product. Variables are substituted in all string fields. Explicit targets override expanded ones. Escaping: \[var] -> [var]. Expansion happens at config load time so the rest of the system (builder, graph, state) sees only expanded targets.
This commit is contained in:
parent
bb03975ece
commit
7503672942
7 changed files with 581 additions and 2 deletions
90
README.md
90
README.md
|
|
@ -67,6 +67,7 @@ The config file must be named `<anything>.hokusai.yaml` and placed in your proje
|
|||
| Field | Description |
|
||||
|---|---|
|
||||
| `defaults` | Default model names (optional) |
|
||||
| `loops` | Loop variables for target template expansion (optional) |
|
||||
| `archive_folder` | Directory to move previous outputs into before rebuilding (optional) |
|
||||
| `targets` | Map of output filenames to their configuration |
|
||||
|
||||
|
|
@ -90,6 +91,7 @@ defaults:
|
|||
| `width` | int | Image width in pixels |
|
||||
| `height` | int | Image height in pixels |
|
||||
| `download` | string | URL to download instead of generating (mutually exclusive with prompt) |
|
||||
| `content` | string | Literal text to write to the file (mutually exclusive with prompt/download) |
|
||||
|
||||
Target type is inferred from the file extension:
|
||||
- **Image**: `.png`, `.jpg`, `.jpeg`, `.webp`
|
||||
|
|
@ -151,6 +153,94 @@ targets:
|
|||
|
||||
Download targets participate in dependency resolution like any other target. They are skipped if the URL hasn't changed.
|
||||
|
||||
### Content targets
|
||||
|
||||
Targets can write literal text content directly to a file without invoking any AI provider:
|
||||
|
||||
```yaml
|
||||
targets:
|
||||
config.txt:
|
||||
content: "Some static configuration"
|
||||
|
||||
data.csv:
|
||||
content: |
|
||||
name,value
|
||||
alpha,1
|
||||
beta,2
|
||||
```
|
||||
|
||||
Content targets don't require API keys and are not archived when overwritten. They participate in dependency resolution like any other target, so generated targets can depend on them.
|
||||
|
||||
### Loops
|
||||
|
||||
Define `loops` at the top level to generate multiple targets from a template using cartesian products:
|
||||
|
||||
```yaml
|
||||
loops:
|
||||
color:
|
||||
- red
|
||||
- blue
|
||||
- green
|
||||
size:
|
||||
- small
|
||||
- large
|
||||
|
||||
targets:
|
||||
card-[color]-[size].png:
|
||||
prompt: "A [color] card in [size] format"
|
||||
width: 1024
|
||||
height: 768
|
||||
```
|
||||
|
||||
This expands to 6 targets: `card-red-small.png`, `card-red-large.png`, `card-blue-small.png`, etc. Loop variables are substituted in all string fields: prompts, inputs, reference images, control images, download URLs, and content.
|
||||
|
||||
Only variables that appear in the target name cause expansion. A target without any `[var]` references in its name is not looped:
|
||||
|
||||
```yaml
|
||||
loops:
|
||||
id:
|
||||
- 1
|
||||
- 2
|
||||
|
||||
targets:
|
||||
data-[id].txt:
|
||||
content: "Data for [id]"
|
||||
|
||||
# This target depends on ALL expanded data files
|
||||
summary.md:
|
||||
prompt: "Summarize everything"
|
||||
inputs:
|
||||
- data-1.txt
|
||||
- data-2.txt
|
||||
```
|
||||
|
||||
Loop variables also work across dependent targets:
|
||||
|
||||
```yaml
|
||||
targets:
|
||||
data-[id].txt:
|
||||
content: "Data for item [id]"
|
||||
|
||||
report-[id].md:
|
||||
prompt: "Write a report about item [id]"
|
||||
inputs:
|
||||
- data-[id].txt
|
||||
```
|
||||
|
||||
**Explicit overrides**: If you define both a template and an explicit target that would collide, the explicit target wins:
|
||||
|
||||
```yaml
|
||||
targets:
|
||||
image-[n].png:
|
||||
prompt: "Generic image [n]"
|
||||
image-3.png:
|
||||
prompt: "Special custom image" # this overrides the template for n=3
|
||||
```
|
||||
|
||||
**Escaping**: Use `\[var]` to produce a literal `[var]` in the output.
|
||||
|
||||
Loop values are always treated as strings. Numbers and booleans in YAML are automatically converted.
|
||||
|
||||
### Archiving previous outputs
|
||||
|
||||
Set `archive_folder` at the top level to preserve previous versions of generated files. When a target is rebuilt, the existing output is moved to the archive folder with an incrementing numeric suffix:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue