> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# SEO content brief

> T2 chain · SEO: a content brief grounded in what your competitor actually published, not vibes.

> **T2 chain · SEO / content marketing**: two `nika:fetch` extractions
> chained (`sitemap` mode, then `article` mode), a jq slice binding, CEL
> indexing, and a schema-typed brief at the end.

## The job

« Write something that ranks for X » usually starts with an hour of
tab-hopping through the competitor's site. This workflow maps their
sitemap, reads their best page on the topic, finds the gaps, and hands
your writer a typed brief: title, angle, outline, keywords.

## The shape

```mermaid theme={"system"}
flowchart LR
  map["map · nika:fetch"]:::invoke
  top_page["top_page · nika:fetch"]:::invoke
  brief["brief · typed"]:::infer
  save["save · nika:write"]:::invoke
  map --> top_page
  map --> brief
  top_page --> brief
  brief --> save
  classDef infer fill:#5b8cff22,stroke:#5b8cff,color:#5b8cff
  classDef invoke fill:#22d3ee22,stroke:#22d3ee,color:#22d3ee
```

## The file

```yaml seo-content-brief.nika theme={"system"}
nika: seo-content-brief

# The house seat — a THINKING model: the think block and the JSON both count
# against `max_tokens` (engine#428), so the brief ceiling below covers the
# reasoning AND the brief, not the brief alone.
model: ollama/qwen3.5:4b

inputs:
  topic:
    type: string
    # Slug-shaped on purpose: this value lands in a FILENAME below, and a
    # caller-supplied string that reaches a path is the tainted-value case the
    # checker polices (NIKA-AUTH-008). Keep it to one path segment — `*` in
    # the write bound never crosses `/`, so `a/b` is refused, by design.
    default: "rust-async-runtimes"
    description: "The keyword/topic you want to rank for (one path segment)"
const:
  competitor_sitemap: "https://competitor.example.com/sitemap.xml"
permits:
  tools: ["nika:fetch", "nika:write"]
  net:
    # Both fetches stay on the competitor's own host: the sitemap, then a URL
    # that same sitemap listed. Net entries are exact host names, never globs —
    # add YOUR competitor's host here when you point the const at it, or the
    # fetch is refused at run and the recover path quietly takes over.
    http: ["competitor.example.com"]
  fs:
    # One brief per topic, written DIRECTLY in out/briefs/. `*` matches a
    # single path segment and never crosses `/`, so a topic carrying a slash
    # is refused instead of steering the write into a subtree — which is
    # exactly why this is `out/briefs/*.json` and not `out/briefs/**`.
    write: ["out/briefs/*.json"]

tasks:
  map:
    invoke:
      tool: "nika:fetch"
      args:
        url: "${{ const.competitor_sitemap }}"
        mode: sitemap
    extract:
      top: ".[:5] | map(.loc)"
    on_error:
      # The recovery stands in for the RAW response, so it has the shape a
      # sitemap fetch returns — a root array of {loc, …} — and the `extract:`
      # jq above slices it exactly as it would slice the live one. Recover the
      # BINDING's shape instead and the jq runs against the wrong thing and
      # throws NIKA-VAR-004.
      recover:
        - { loc: "https://competitor.example.com/blog/async-runtimes-compared" }
        - { loc: "https://competitor.example.com/blog/tokio-vs-smol" }
        - { loc: "https://competitor.example.com/blog/choosing-an-executor" }

  top_page:
    with:
      map_top: ${{ tasks.map.top[0] }}
    invoke:
      tool: "nika:fetch"
      args:
        url: "${{ with.map_top }}"
        mode: article
    on_error:
      recover: |
        Async runtimes compared — we benchmarked four executors on the same
        workload. Tokio wins on ecosystem breadth; smol wins on binary size.
        We did not cover structured concurrency, cancellation safety, or how
        any of this behaves under a blocking call, which is where most teams
        actually get hurt.

  brief:
    with:
      map_top: ${{ tasks.map.top }}
      top_page: ${{ tasks.top_page.output }}
    infer:
      # a reasoning model needs 16384 here, or a documented run.reasoning.effort: low
      max_tokens: 3000                 # think block + the brief JSON
      prompt: |
        Topic to rank for · ${{ inputs.topic }}
        Competitor's top URLs · ${{ with.map_top }}
        Their best page on it ·
        ${{ with.top_page }}

        Write a content brief that BEATS this page · find the gaps they
        missed · angle for search intent.
      schema:
        type: object
        additionalProperties: false
        required: [title, angle, outline, keywords]
        properties:
          title: { type: string }
          angle: { type: string }
          outline: { type: array, items: { type: string } }
          keywords: { type: array, items: { type: string } }

  save:
    with:
      brief: ${{ tasks.brief.output }}
    invoke:
      tool: "nika:write"
      args:
        # `.json` content is ONE interpolated value — the engine serializes it.
        path: "out/briefs/${{ inputs.topic }}.json"
        content: "${{ with.brief }}"
        create_dirs: true
    # The topic names the output file, and an input is UNTRUSTED by default —
    # NEP-0004 law 2 re-gates the composed path at check (NIKA-AUTH-008). The
    # authored door says why THIS value is safe: the receipt records the taint
    # path · this because · the value digest, and the lifted value must
    # STILL fit fs.write ["out/briefs/*.json"] — a door, never a bypass.
    lift:
      - law: taint
        from: inputs.topic
        because: "the operator's own brief subject, typed at launch — it names the output file, nothing else"

outputs:
  brief:
    value: ${{ tasks.brief.output }}
    description: "The typed content brief"
```

## How it works

**1. Sitemap mode + a jq slice**

`mode: sitemap` returns the URL list; the `extract:` binding
`top: ".[:5] | map(.loc)"` keeps just the head of it, as bare
`loc` URLs. Bindings are jq: slices, filters, everything.

**2. CEL indexes into the binding**

The second fetch binds `map_top: ${{ tasks.map.top[0] }}` in
`with:`: index access is part of the CEL subset, and the binding IS
the edge — every reference is a visible edge, declared where the
data crosses.

**3. The brief is a contract**

title · angle · outline · keywords: your writer (or your next
workflow) consumes fields, not a wall of prose.

## Constructs you just used

| Construct | Where | Reference |
| - | - | - |
| `mode: sitemap` → `mode: article` | `map` · `top_page` | [Builtins](https://docs.nika.sh/reference/builtins.md) |
| `extract:` jq slice | `map.top` | [Bindings](https://docs.nika.sh/concepts/bindings.md) |
| CEL index access | `top_page.with` | [Workflows](https://docs.nika.sh/concepts/workflows.md) |
| `create_dirs: true` | `save.args` | [Builtins](https://docs.nika.sh/reference/builtins.md) |

## Run it

> [!NOTE]
>
> **What it needs:** A local model ([Ollama](https://ollama.com) serving `qwen3.5:4b`). Nothing else: the placeholder competitor host resolves nowhere and the recovered samples take over.

**1. Rehearse it**

```bash theme={"system"}
nika try seo-content-brief
```

A mock model answers and nothing is written in your folder. Before it runs, `nika try` names the hosts a step may reach: `may reach: competitor.example.com — the mock replaces the model, not the network`.

**2. Get your own copy**

Save the file above as `seo-content-brief.nika` in a new folder. It reads no sample file.

**3. Check it, then run it**

```bash theme={"system"}
nika check seo-content-brief.nika
nika run seo-content-brief.nika --model mock/echo   # a mock model, no key
ollama pull qwen3.5:4b   # once, for the real run
nika run seo-content-brief.nika
```

The run writes `out/briefs/<topic>.json`.

Any other model works: pass `--model <provider>/<name>` with its key, and cap a cloud model with `--max-cost-usd`.

For a real brief, point `const.competitor_sitemap` at a real sitemap and add its host to `permits.net.http`. `--var topic=your-keyword` picks the target.

## Make it yours

* Brief the top THREE pages instead of one: bind `top: ${{ tasks.map.top }}` in `with:` and fan out with `for_each: { items: ${{ with.top }} }`. The fan-out tier shows how ([Competitor radar](https://docs.nika.sh/examples/competitor-radar.md)).
* Feed your own sitemap too and ask the model for internal-linking opportunities.
* Pipe the brief straight into a draft: a second `infer` consuming `${{ tasks.brief.output.outline }}`.

> [card] [Next · Invoice chaser](https://docs.nika.sh/examples/invoice-chaser.md)
>
> CSV → JSON with `nika:convert`, a jq filter, and the three-line
> human-approval gate.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.