# Lilac graph: guide for agents

A graph is a library of rows. A row is a file, a note or a web link, with a summary, a group, links to related rows and searchable text. You can read a graph, search it and add to it. Use `lilac-graph` for everything below.

## Set up

No key yet? Log in. The user only opens a link and approves; you need nothing else.

    npx -y lilac-graph login --name "<your name, such as Claude Code>"   # prints a link: show it to the user
    npx -y lilac-graph login --wait                                     # once they approved: saves the key
    npx -y lilac-graph graphs                                           # the graphs you may use

- The key opens graphs only. It can make graphs and fill the ones it made, and a graph the user has if you log in with `--graph <name>`. Never print it.
- To make a graph, propose a name and one line, and ask the user to confirm. Then `lilac-graph new <name> --about "One line"`.
- Pick the graph with `--graph <name>` on any command, or `export LILAC_GRAPH=<name>`. A key the user gave you goes in `LILAC_API_TOKEN`.

Every command takes `--json`. Nothing asks you a question. Each error says what to do next. A read-only key can only read.

## Answer a question

Look cheaply first, then read only what you picked.

1. `lilac-graph map` shows what the graph is about, its groups, its newest rows and its size. If it says the graph is small enough to read whole, `read` every row and skip the rest.
2. `lilac-graph search "your question in plain words"` returns the best passages, each with its row, its part number and a link. `--exact` finds an exact string. `--limit 1-25` caps the hits and `--budget 200-20000` the answer size in tokens.
3. `lilac-graph read <row> --part <n>` reads one part of a row, and `--part 3-5` a range. `read <row>` alone lists the parts, the summary, the digest and the related rows, and shows the text itself when the row has one part.
   A hit can be a row's digest card or one table entry (with an address such as `tasks/some-name`). `read <row> --table tasks` reads that table, and `--entry tasks/some-name` one line of it. Both are far smaller than the text.
4. Follow links: `read` the rows named under `related` or `One step away`, then search again with new words.

Cite a row by its link. If nothing matches, say so. Do not guess.

## Add files

    lilac-graph add ./notes --group tasks

- One row per file, known by its path (`notes/a.md`). Run it again and nothing changes. A changed file updates its row; `--group` places new rows only, so move a row with `set`.
- A folder is walked. Hidden files, `node_modules` and what `.gitignore` lists are skipped. A subfolder becomes a subgroup.
- A link from one Markdown file to another becomes a related link.
- `lilac-graph add https://example.com/page` adds a web link. `--dry-run` shows what would be added.
- When adding a paper, read it once and write its digest (run `guide digest`), so later agents skip the source. Give it a real `--title`, then `set` a summary and `--relate` the rows it belongs with. Related links are drawn from the summary, and a bare URL only gets citations.
- Text is read from Markdown, plain text, code, HTML and PDF. Other files are found by title and summary only.

## Make it findable

You have read each file, so you write its summary, its group and its links. The service writes none of them.

    lilac-graph set <row> --summary "What it says, and when to use it." --group tasks/design --relate other-row
    lilac-graph group tasks/design --about "One line on what belongs here."

- A summary is one or two plain sentences, with no jargon.
- A group is a path such as `tasks/design`. Reuse the names `map` shows.
- `--relate` links rows that belong together. Take ids from `map` or `search`. Remove one with `--relate=-id`.
- You may place only the rows you added. For anyone else's row, `--group` is a suggestion.
- `lilac-graph digest <row> --file digest.md` stores a digest: the facts and tables later agents read instead of the source.
- The owner's notes are theirs. A key cannot change them.

## Without Node

    curl -H "Authorization: Bearer $LILAC_API_TOKEN" "https://api.lilac-research.com/v1/graphs/$LILAC_GRAPH/map"
    curl -H "Authorization: Bearer $LILAC_API_TOKEN" "https://api.lilac-research.com/v1/graphs/$LILAC_GRAPH/passages?q=your+question"
    curl -X PUT -H "Authorization: Bearer $LILAC_API_TOKEN" --data-binary @note.md "https://api.lilac-research.com/v1/graphs/$LILAC_GRAPH/files?path=notes/note.md"

Exit codes: 0 done, 1 error, 2 bad usage, 4 not found. `lilac-graph guide` prints this page again.
