> ## 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.

# Bookmark triage

> T2 fan-out · personal / research: the bookmark pile triaged into one table — dead links survive the batch instead of killing it.

> **T2 fan-out · personal / research**: `for_each` fans one
> `nika:fetch` with `mode: metadata` per URL — the page's OG/meta head
> as typed data, not a scrape — with `retry:` for transient blips and
> `on_error: recover:` so a dead link degrades to a `{ dead: true }`
> row instead of failing the batch. `nika:jq` renders the triage
> table; `nika:write` persists it.

## The job

Every bookmark pile has the same two questions: *what is this, and is
it even alive?* Answering them by hand means opening every tab. This
workflow answers both in one run — title/description/site from each
page's own metadata, dead links marked as dead — and leaves a table
you can sort, grep, and prune from.

## The shape

```mermaid theme={"system"}
flowchart LR
  pages["pages · ∥ for_each · nika:fetch"]:::invoke
  table["table · nika:jq"]:::invoke
  report["report · nika:write"]:::invoke
  pages --> table
  table --> report
  classDef invoke fill:#22d3ee22,stroke:#22d3ee,color:#22d3ee
```

## The file

```yaml bookmark-triage.nika theme={"system"}
nika: bookmark-triage

const:
  bookmarks:
    # The saved-links pile to triage.
    #
    # A TYPED constant is `{ type, value }` — both keys, exactly those two
    # (`description:` here is NIKA-PARSE-005 · unknown field). The
    # discriminator is normative (01-envelope.md §const): an object missing
    # either key is a bare literal object constant. So `{ type, default }` is
    # not a declaration at all — `${{ const.bookmarks }}` would yield the whole
    # `{type, default}` map and `for_each` would die NIKA-VAR-006 ·
    # « for_each collection must be an array · got object ».
    type: { array: string }
    value:
      - "https://example.com"
      - "https://github.com/supernovae-st/nika"
      - "https://this-domain-does-not-exist-0000.invalid" # the dead one · the recover path IS the demo

permits:
  exec: false
  tools: ["nika:fetch", "nika:jq", "nika:write"]
  net:
    http: ["example.com", "github.com", "this-domain-does-not-exist-0000.invalid"]
  fs:
    # One report, one literal: the body's only write is this exact static path,
    # so the grant names it — the audit line reads `risk supervised` where
    # `out/**` read `risk unbounded`.
    write: ["out/bookmarks.md"]

tasks:
  # The fan-out · one metadata fetch per URL · a dead link recovers to a
  # marker object (the batch NEVER dies at bookmark 14).
  pages:
    for_each:
      items: ${{ const.bookmarks }}
      max_parallel: 3
      fail_fast: false
    retry: { max_attempts: 2, backoff_ms: 500 } # a transient blip retries BEFORE the dead verdict
    on_error:
      recover: { dead: true } # a YAML value, not a JSON string — the marker row
    invoke:
      tool: "nika:fetch"
      args:
        url: "${{ item }}"
        mode: metadata

  # The fan-in · zip results back to their URLs · split live from dead.
  table:
    with:
      pages: ${{ tasks.pages.output }}
    invoke:
      tool: "nika:jq"
      args:
        input:
          urls: ${{ const.bookmarks }}
          pages: ${{ with.pages }}
        expression: >-
          def esc: tostring | gsub("\\|"; "\\|") | gsub("\n"; " ");
          ([.urls, .pages] | transpose | map({ url: .[0], page: .[1] })) as $rows |
          {
            live: ([$rows[] | select(.page.dead != true) |
              "| \(.url) | \(.page.title // "—" | esc) | \((.page.description // "—" | esc) | .[0:80]) |"] | join("\n")),
            dead: ([$rows[] | select(.page.dead == true) | "| \(.url) | DEAD | link rot |"] | join("\n"))
          }

  report:
    with:
      table_live: ${{ tasks.table.output.live }}
      table_dead: ${{ tasks.table.output.dead }}
    invoke:
      tool: "nika:write"
      args:
        path: out/bookmarks.md
        create_dirs: true
        content: |
          # Bookmark triage

          | url | title | description |
          | --- | --- | --- |
          ${{ with.table_live }}
          ${{ with.table_dead }}

          *Generated by [nika](https://nika.sh) — dead links survived the batch (`on_error: recover:`).*

outputs:
  table:
    value: ${{ tasks.table.output }}
    description: "Live rows + dead rows · the triage split"
```

## The resilience ladder, in order

1. **`retry: { max_attempts: 2, backoff_ms: 500 }`** — a transient
   blip gets a second chance BEFORE any verdict.
2. **`on_error: recover:`** — a link that still fails becomes
   `{ dead: true }` and the batch keeps walking. `recover:` takes a
   YAML *value*, not a JSON string: quote it and jq downstream sees an
   unindexable string instead of an object.
3. **The table renders both worlds** — the jq step escapes pipes and
   newlines from page-controlled metadata (a `|` in someone's OG title
   must not break your markdown table), and dead rows print as `DEAD`
   instead of vanishing.

The quiet lesson: `mode: metadata` fetches the page's *head*, typed —
when all you need is identity, don't ask for the body.

## Run it

> [!NOTE]
>
> **What it needs:** Network access to `example.com` and `github.com`. No model and no key. With no network the run still succeeds: every row takes the `recover:` path and the table lists it as dead.

**1. Rehearse it**

```bash theme={"system"}
nika try bookmark-triage
```

Nothing is written in your folder. Its network fetches still go out: a rehearsal replaces the model, not the tools. Before it runs, `nika try` names those hosts: `may reach: example.com · github.com · this-domain-does-not-exist-0000.invalid — the mock replaces the model, not the network`.

**2. Get your own copy**

Save the file above as `bookmark-triage.nika` in a new folder. It reads no sample file.

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

```bash theme={"system"}
nika check bookmark-triage.nika
nika run bookmark-triage.nika
```

The run writes `out/bookmarks.md`.

Replace `const.bookmarks` with your own list (most browsers export bookmarks as HTML; one jq pass turns that into the URL list this file expects), and add each new host to `permits.net.http`.


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