# Set up Plancia on this repo

> Instructions for a coding agent (Claude Code, Codex, Cursor or similar). The person asked you to set up Plancia on the repo you are working in. Follow the steps in order. Plancia is open source under Apache 2.0.

## What Plancia is

Plancia reads the Markdown files a project already has (tasks, decisions, roadmap steps, people, logs) and builds an index of them. The `plancia` command answers from that index in compact tables with file and line, including what `grep` cannot see: who cites an item, its history, what an edit touches elsewhere. What saves tokens is items with IDs and one home per fact; the index keeps them in check. An optional web app shows the same index to the people on the team.

Plancia adapts to the repo. One file, `.plancia/schema.yaml`, says where each kind of item lives and how to read it. Your job is to write that file for this repo.

**An empty repo** (no Markdown of its own, or only a README) has no structure to adapt to. Tell the person, and offer Plancia's template, the layout Plancia was designed around: a map for the agent, a to-do with IDs, decisions, people, a roadmap in phases, sources, a daily log, and a schema that already reads them. After a yes, copy it without overwriting anything: `t="$(mktemp -d)/template" && npx -y degit LorenzoLodigiani/plancia/template "$t" && cp -Rn "$t"/. .`. Then fill its `{{…}}` placeholders from what the person tells you about the project, and for its blocks marked `optional:` in `CLAUDE.md` and `.plancia/schema.yaml` (business registries; two folders, one per area), ask whether to keep each. In Claude Code with the plugin, `/setup` does all of this. The steps below are for a repo that has a structure of its own.

## Rules

1. **Do not move, rename or rewrite any existing file.** The repo's structure and formats stay as they are.
2. **The only file you create is `.plancia/schema.yaml`.** Anything else (the plugin, the GitHub App, IDs added to existing lines) is proposed to the person first and done only after a yes.
3. **Nothing leaves the machine.** Every command below runs locally and writes nothing but what this guide says.

## Steps

### 1. Look at the repo

- List the Markdown files: `git ls-files '*.md'`.
- Find what repeats. For each candidate, note the file or glob and an example line:
  - **lines**: one item per line with a recognisable shape, such as `- [ ] **T4 · Call the bank** — owner: Ana · due: 2026-12-04` or `- ⬜ 2.1 Choose the supplier`;
  - **tables**: one item per row, such as a table of decisions or customers;
  - **file per record**: one file per item with YAML front matter, such as `people/ana.md` or `docs/adr/0007-use-postgres.md`;
  - **documents**: everything else (logs, notes, specs). They are indexed too, with their links and the IDs they cite.
- Find the IDs already in use (`T12`, `D3`, `ADR-7`, `2.1`) and the status words (`[x]`, `✅`, `shipped`, `parked`).

### 2. Write `.plancia/schema.yaml`

Start from a draft. `init` reads the repo, proposes a schema for what repeats, and writes nothing:

```bash
npx plancia-cli init --json
```

It returns `schema` (the proposed YAML), `types` (each with its `format`, `source`, `count`, `items`, how many the index reads, and `examples`, the first three with file and line), `problems` (what `check` would report with that schema: `code`, `where`, `message`, at most 30; `problemCount` has the total) and `exists` (true when the repo already has a schema). Compare it with what you saw in step 1: drop the types that are noise, give the others the names the project uses, and fix the patterns that miss lines. Then save it with `npx plancia-cli init --write`, which refuses to overwrite an existing schema, and edit it, or write the file yourself.

The shape of a schema, by hand:

```yaml
project: <name of the project>
index: ["**/*.md"]             # globs of what is read
exclude: ["node_modules/**"]   # folders that are not even visited
types:
  task:
    source: <file or glob>
    format: lines
    pattern: '<regular expression with named groups: id, status, title, and any field such as owner or due>'
    statuses: { " ": to do, "~": in progress, "!": blocked, "x": done }
  decision:
    source: <file>
    format: table
    id: 'D\d+'
  person:
    source: "<folder>/*.md"
    format: file-per-record
    fields: [role, organization, stage]
citable_ids: '\b([TD]\d+)\b'   # IDs that count as a citation when written in the text
status_words:                  # only for words Plancia does not know already
  done: [shipped]
  blocked: [parked]
```

Reference:

| Key | What |
|---|---|
| `project` | The project's name |
| `index`, `exclude` | Globs of the Markdown that is read, and of what is skipped |
| `areas` | Optional names for parts of the repo, by glob |
| `types` | The kinds of items: `source` (file or glob) and `format` |
| `citable_ids` | The regular expression of IDs that count as citations in the text |
| `status_words` | The project's own status words, mapped to `done`, `in_progress`, `blocked`, `open` |

A type can also declare `label` and `plural` (its name on screen), `statuses` (raw value to name), `role` (`task`, `decision` or `blocker`, whatever the type is called) and `registry: true` (people and companies).

Formats: `lines` (needs `pattern`), `table` (optional `sections`, `tables`, `title_column`, `status_from`), `file-per-record` (fields from front matter), `document`.

### 3. Check it

```bash
npx plancia-cli check      # problems in the schema and in the repo; exit 1 when there are problems
npx plancia-cli today      # what is due, blocked, to decide and in progress
npx plancia-cli find task  # one type as a table: compare the count with what you saw in step 1
```

Adjust the patterns until the counts match the repo. A line the pattern misses is an item lost; a pattern that is too loose picks up lines that are not items.

### 4. Report to the person

Say in a few lines: the types you found and how many items each has, what is due and blocked according to `plancia today`, and the problems `plancia check` reports (broken links, IDs cited but never defined). Show the schema.

### 5. Propose the optional parts, and wait for a yes on each

- **The Claude Code plugin**: `/plugin marketplace add LorenzoLodigiani/plancia`, then `/plugin install plancia@plancia`. It adds the `plancia` command to every session, a hook that says what an edit touches elsewhere, and the `/today` and `/log` routines.
- **The same hooks in Codex or Cursor**: `npx plancia-cli hooks codex --write` writes `.codex/hooks.json`, `npx plancia-cli hooks cursor --write` writes `.cursor/hooks.json` (an existing file keeps its other hooks). They brief the session at the start, say what an edit touches elsewhere, stop a `git push` that `plancia check` would fail, and ask for the log at the end. Codex runs them once the person trusts them with `/hooks`. Say that they follow each agent's documented hook format but have not been tried inside a real Codex or Cursor session yet.
- **Sources.** If the repo keeps external documents (reports, regulations, datasets, decks received), propose a `source` type: one card per document with an ID (`S1`, `S2`…), front matter (`type`, `author`, `date`, `authority`, `status`) and the facts with their page. With the plugin, `/source <file>` reads the document once, writes the card and checks every quote word for word. Numbers taken from a source cite it with the page: `S2, p. 9`.
- **IDs for items that have none.** `npx plancia-cli ids` lists them with the ID each would get: the next free number of the type, written the way the other lines write it. IDs make items citable, and they are what most of the token savings come from. After a yes, `npx plancia-cli ids --write` adds them.
- **A rollup for an index.** If the repo keeps a table of where each file of a type stands (the phases of a roadmap), propose a rollup in its place: the two lines `<!-- plancia:rollup <type> -->` and `<!-- /plancia:rollup -->`, filled by `npx plancia-cli rollup --write` with each file's status, how many items are done and what comes next, and kept current by the plugin's hook. Nobody writes those rows again.
- **The web app for the team**, self-hosted: the web app on the team's own Vercel and Supabase, and its GitHub App installed on the repo, which indexes it on every push with nothing added to the repo. Follow the [self-hosting guide](https://plancia.xyz/docs/self-hosting.md).

### 6. Experimental parts, only if the person chooses them

Say in one line that Plancia has experimental parts, and set one up only if the person asks for it after hearing what it is:

- **A mirror of Linear or Notion.** If part of the work lives in one of those tools and you have its MCP server, the issues or pages can come into the repo as read-only Markdown files in `.plancia/mirror/<tool>/`, so Plancia links them to the rest. Tell the person what it is: a copy as fresh as its last refresh, which the agent refreshes by hand, and items are still closed in the tool, never in the copy. How to write it and the type to add to the schema: [Linear and Notion mirrors](https://plancia.xyz/docs/mirrors.md).

## After setup

Use `plancia today`, `plancia show <ID>`, `plancia radius <ID>` and `plancia find <type>` before reading files by hand. With the Claude Code plugin `plancia` is on the path; otherwise run it as `npx plancia-cli <command>`, or install it once with `npm install -g plancia-cli`. When you change a decision or close a task, run `plancia radius <ID>` and update what cites it.
