benjivers/notes Public Public: anyone can read this; nobody can change it.

Files 9a96f69e35aa62daafc52ed3af566f73004b8e77
126 lines · 7.6 KB · ~1.9k tok Raw History
1
# notes
2
3
A personal linked-notes vault, in the spirit of Obsidian — markdown,
4
`[[wikilinks]]`, backlinks, tags and a graph — kept on the forge.
5
6
## Using it
7
8
Open the app and **create a vault** with an email and password, or sign in
9
with a forge account. Your notes are **yours alone**: the contract gives
10
every verb on a note to its author, so nobody else who uses the app —
11
admins included — can list, read or change them.
12
13
**Email accounts** (`src/accounts.ts`) are the app's own: argon2id password
14
hashes, a random session token in an HttpOnly cookie (only its SHA-256 is
15
stored), 30-day sessions, log-in attempts rationed per email. The account
16
page changes the password (ending every other session) or deletes the
17
account with all its notes. There is no email-based reset — the app sends
18
no mail. Set `NOTES_SIGNUP_CODE` in Settings → App → Environment to require
19
a code for new accounts (closing open sign-up without a deploy). A vault
20
holds at most 5,000 notes. Email accounts reach the page and the JSON API;
21
the MCP endpoint and the terminal are for forge accounts.
22
23
- **Write** in markdown. It saves as you type (and with ⌘S). Edit, Split
24
  (side by side) and Read views; ⌘E flips between reading and writing.
25
- **Link** with `[[Another note]]`, `[[Note|shown text]]` or
26
  `[[Note#Heading]]`. Typing `[[` suggests titles. A link to a note not
27
  written yet is drawn dashed; following it creates the note.
28
- **Backlinks**: the right panel shows every note that links here, with the
29
  line it said it in, plus links out, the outline, tags and a local graph.
30
- **Rename** a note and every link to it in your vault is rewritten.
31
- **Tags**: `#tag`, nested as `#area/topic`. Click one to see every note
32
  carrying it (`#area` also finds `#area/topic`).
33
- **Search**: words, `"a phrase"`, `#tag` or `tag:name`, combined.
34
- **Graph**: every note and link, force-laid-out. Drag, zoom, click to open.
35
- **Daily note**: the calendar button (⌘⇧D) opens today's `YYYY-MM-DD` note.
36
- **Quick switcher**: ⌘K / Ctrl K — jump to a note, or ⇧↵ to create one.
37
- Editor keys: ⌘B bold, ⌘I italic, ⌘⇧H highlight, ⌘↵ cycles a line
38
  through task / done / plain, Enter continues a list, Tab indents it.
39
- Markdown: headings, emphasis, `==highlight==`, `~~strike~~`, code,
40
  fenced blocks, lists, `- [ ]` tasks (tick them in the reading view),
41
  quotes, Obsidian callouts (`> [!tip] Title`), tables, links.
42
- **Your data**: every note downloads as `.md`; the sidebar's download
43
  button exports the whole vault as JSON.
44
45
Everything is real: notes live in SQLite under `FORGE_APP_DATA`. A preview
46
of a pull gets a copy of production data; production is the default branch.
47
48
## Claude can use it too
49
50
`POST /mcp` is an MCP server with `list_notes`, `search_notes`,
51
`read_note`, `create_note`, `update_note`, `append_to_note` (with no
52
title: today's daily note) and `delete_note` — as whoever the forge grant
53
belongs to:
54
55
```sh
56
claude mcp add --transport http notes https://notes--forge-apps.benjivers.com/mcp
57
```
58
59
The terminal (`FORGE_APP_SSH`) lists, reads and searches the vault, adds a
60
line to today's note (`a`) and makes new notes (`n`).
61
62
## Running it here
63
64
```sh
65
PORT=8080 FORGE_APP_DATA=./data bun run src/server.ts   # signed out without FORGE_APP_IDENTITY_KEY
66
bun test                                                # what forge.json's app.test runs on every push
67
FORGE_APP_DATA=./data bun run src/tty.ts                # the terminal
68
bun run lint:design                                     # no colour but the tokens'
69
bun run contract:emit                                   # rewrite contract/openapi.json from the routes
70
```
71
72
## The shape
73
74
One implementation, many doors. `src/actions.ts` is every operation as a
75
plain function — `(db, who, input)` in, data or a named failure out — and
76
the page, the JSON API, the MCP server and the terminal all call it and
77
decide nothing themselves. `AGENTS.md` says how to add to it.
78
79
| file                               | what it is                                                     |
80
| ---------------------------------- | -------------------------------------------------------------- |
81
| `src/actions.ts`                   | notes: list, add, rename (relinks), pin, delete, search; audit |
82
| `src/vault.ts`                     | links, backlinks, tags, graph, search — pure, over notes       |
83
| `static/md.js`                     | the markdown renderer, shared by the server and the browser    |
84
| `contract.json`                    | who may do what: roles, and the least role each verb needs     |
85
| `src/contract.ts`, `src/can.ts`    | the table, read at boot; the forge's evaluator, verbatim       |
86
| `src/security.ts`                  | the door: rationing, same origin, the table before the body    |
87
| `src/audit.ts`                     | every change and every refused one, as a row                   |
88
| `src/who.ts`                       | who is asking, from the forge's signed headers                 |
89
| `src/db.ts`                        | SQLite under `FORGE_APP_DATA`, WAL, forward-only migrations    |
90
| `src/live.ts`                      | the in-process bus and `GET /events`                           |
91
| `src/mcp.ts`                       | the actions as MCP tools at `POST /mcp`                        |
92
| `src/routes.ts`                    | every path, in one table, each API route described beside it   |
93
| `src/openapi.ts`                   | the routes as OpenAPI; committed at `contract/openapi.json`    |
94
| `src/page.ts`                      | the HTML, rendered on the server, with its share metadata      |
95
| `design/tokens.json`, `src/tokens.ts` | the look as data, light and dark; compiled to `/tokens.css` |
96
| `src/http.ts`                      | the floor: headers, body cap, files                            |
97
| `src/server.ts`                    | boot: open the database, serve                                 |
98
| `src/tty.ts`                       | the terminal, over the same actions                            |
99
| `src/env.ts`                       | what the forge told this process                               |
100
| `static/app.css`, `static/live.js` | the look in the tokens' words, and the panels that stay current |
101
| `static/app.js`, `static/graph.js` | the editor, switcher and keys; the force-directed graph        |
102
103
## What every app stands on
104
105
- **The door.** Before a route sees a request, `src/security.ts` rations
106
  writes (and a stranger's API calls), refuses a write from another site,
107
  and turns away — before the body is read — anyone the table lets through
108
  a resource's door for no row at all: 401 for a stranger, 403 for anyone
109
  else. The action still decides about the real row.
110
- **The audit trail.** Every change, and every change refused, is a row:
111
  who, which resource and verb, which row, when, and whether they were
112
  let. Admins read it at `GET /api/audit`. A row that cannot be written
113
  is a log line, never a failed request.
114
- **The API, described.** `GET /openapi.json` is `contract/openapi.json`,
115
  written from the routes by `bun run contract:emit`; each operation names
116
  its cell of the table (`x-contract`). `bun test` fails while it is stale.
117
- **Up, or not.** `GET /healthz` answers `{ ok, version, uptime }`; the
118
  forge waits on it before it sends anyone to a deploy.
119
- **The look.** `design/tokens.json` holds every colour, space and size,
120
  light and dark; nothing else spells out a colour (`bun run lint:design`),
121
  and every pair a person reads meets 4.5:1 in both themes.
122
- **The open web.** A shared link unfurls (description, Open Graph, a
123
  card); `/robots.txt` keeps crawlers to the page, and out of previews
124
  entirely; `/.well-known/security.txt` sends a reporter to the forge
125
  that runs the app.
126
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts