Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .docs/wiki/API-and-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ The first call opens a page in form.md asking which workspaces the agent may use

### What a read-only credential can do

The credential decides what an agent may do; there is no separate question in the window. A read-only token or OAuth grant can read and search pages, databases, comments and agent runs, build a context pack and search or review the knowledge bank (it cannot record or confirm knowledge), and every request that changes something is refused with `403 read_only`. `tools/list` shows it only the tools that announce themselves as read-only, plus `window_command_run`, which stays listed because the window also offers commands that change nothing, such as opening a page or switching a view. That tool is announced as able to change the workspace, and a read-only credential is refused any window command that the window marks as changing it. `extension_command` is a write tool, so a read-only credential does not see it and cannot call it. A read and write credential sees every tool.
The credential decides what an agent may do; there is no separate question in the window.

- **Read-only.** A read-only token or OAuth grant can read and search pages, databases, comments and agent runs, build a context pack and search or review the knowledge bank (it cannot record or confirm knowledge), and every request that changes something is refused with `403 read_only`.
- **What a read-only credential is shown.** `tools/list` shows it only the tools that announce themselves as read-only, plus `window_command_run`, which stays listed because the window also offers commands that change nothing, such as opening a page or switching a view. That tool is announced as able to change the workspace, and a read-only credential is refused any window command that the window marks as changing it.
- **Extensions.** `extension_command` is a write tool, so a read-only credential does not see it and cannot call it.
- **Read and write.** A read and write credential sees every tool.

`agents/manifest.json` in the repository lists each tool and which of them are read-only; `./form-md agents manifest` writes it from the server's own tool list and `./form-md agents manifest --check` fails when it is out of date.

Expand All @@ -103,7 +108,11 @@ Below the snippets, **Connected apps** lists every agent you allowed, with its w
2. Access is decided by the policy gate for every credential kind; a route never checks the token type itself, except through `RequireSession`, `RequireAdmin` or `RequireOwner` for routes that must not be reachable by tokens.
3. A new MCP tool that changes anything is marked `Write`. The server then adds the `run_id` and `idempotency_key` arguments to its schema and handles both, and the tool records its changes in the agent run so **Undo this run** can reverse them.
4. Rate limits and audience checks live in `internal/auth/service.go` middleware; do not add per-route limits for tokens elsewhere.
5. An agent's edits merge with what a person is typing. `insert_blocks` and the REST Markdown writes in `append`, `prepend` and `after` mode apply to the server's copy of the page as CRDT transactions, the same way another person's keystrokes do, so both changes survive and every open editor receives them live. `replace_block` swaps one block and `replace_page_content` (and the `replace` mode) swaps the whole body, which is why both are marked destructive. For tokens and OAuth clients (not the person's own browser) the server refuses with `409 person_editing` a replace or delete of a block that holds a person's cursor, and a whole-body replace while anyone has the page's editor focused; each open editor reports the ids of the blocks around its cursor in its awareness state as `blocks`, and clears them when it loses focus. Agents should prefer inserts on pages people may have open. Pictures an agent writes as `![alt](https://...)` are fetched by the server through its guarded fetcher right after the write, stored as page files and swapped in, so public pages and exports show them; a picture that cannot be fetched stays a link.
5. An agent's edits merge with what a person is typing.
- **Inserts merge.** `insert_blocks` and the REST Markdown writes in `append`, `prepend` and `after` mode apply to the server's copy of the page as CRDT transactions, the same way another person's keystrokes do, so both changes survive and every open editor receives them live.
- **Replaces are destructive.** `replace_block` swaps one block and `replace_page_content` (and the `replace` mode) swaps the whole body, which is why both are marked destructive.
- **A person typing is protected.** For tokens and OAuth clients (not the person's own browser) the server refuses with `409 person_editing` a replace or delete of a block that holds a person's cursor, and a whole-body replace while anyone has the page's editor focused; each open editor reports the ids of the blocks around its cursor in its awareness state as `blocks`, and clears them when it loses focus. Agents should prefer inserts on pages people may have open.
- **Pictures.** Pictures an agent writes as `![alt](https://...)` are fetched by the server through its guarded fetcher right after the write, stored as page files and swapped in, so public pages and exports show them; a picture that cannot be fetched stays a link.
6. Before a task an agent calls `context_pack`; knowledge it learns goes in with `knowledge_record`. Numbers for both come from the `contextual-compression` skill's `policy.json`, never from constants in the code. See [[Context-and-knowledge]].

## Related
Expand Down
29 changes: 25 additions & 4 deletions .docs/wiki/Data-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ Rows are nodes and relation properties are links. Settings: colour by a select o

## Dashboards

Widgets sit on a four-column grid and are small (one column), medium (two) or full width; on narrow screens they stack. With rights to change the view's design, drag a widget by its grip to move it, or focus the grip and press the left and right (or up and down) arrow keys; focus stays on the grip and a screen reader hears the new position. Move earlier and Move later are also in each widget's menu then. **Add a KPI** adds a number widget with a trend: pick a date property and day, week or month, and the card shows the value, a sparkline of the last 24 buckets and the change of the last bucket against the one before.
- **Sizes.** Widgets sit on a four-column grid and are small (one column), medium (two) or full width; on narrow screens they stack.
- **Moving a widget.** With rights to change the view's design, drag a widget by its grip to move it, or focus the grip and press the left and right (or up and down) arrow keys; focus stays on the grip and a screen reader hears the new position. Move earlier and Move later are also in each widget's menu then.
- **KPI cards.** **Add a KPI** adds a number widget with a trend: pick a date property and day, week or month, and the card shows the value, a sparkline of the last 24 buckets and the change of the last bucket against the one before.

## Boards

Expand All @@ -91,7 +93,16 @@ The table renders only the rows near the viewport and asks the server for each w

`POST /api/collections/{id}/chart` takes `{"chart": {...}, "view_id": "...", "search": "...", "pick": {"x": "...", "series": "..."}, "date_range": {...}}`. The chart object has `kind`, `x` and `series` groupings (`prop`, `by`, `step`), `fn`, `prop`, `target`, `window`, `scale`, `filter`, `limit` and the style flags. A `pick` answers with `picked`, the ids of up to 500 rows behind that mark, instead of values. A `dots` chart answers with `points` (`id`, `title`, `group`, `value`). Calendar charts return up to 1,100 days.

`date_range`, on `POST /api/collections/{id}/query` and `/chart`, narrows the answer to rows whose date falls in a range: `{"prop": "<date property id>", "within": "today"}` with any Is within option (`today`, `past_7_days` and `past_30_days` are rolling whole days ending today, in the viewer's time zone), or `{"prop": "...", "from": "YYYY-MM-DD", "to": "YYYY-MM-DD"}` with both days included. It is ANDed with the view's filter, so it can only narrow what the view shows. The property must be a date, created time or edited time property of that database, `within` and `from`/`to` cannot be mixed, the days must be real dates and `from` must not be after `to`; anything else answers `400 bad_date_range`. The database toolbar's Date range control keeps each viewer's choice per view in the browser (`formmd.daterange.<view id>`) and sends it with every rows and chart request of that view.
`date_range`, on `POST /api/collections/{id}/query` and `/chart`, narrows the answer to rows whose date falls in a range:

- `{"prop": "<date property id>", "within": "today"}` with any Is within option (`today`, `past_7_days` and `past_30_days` are rolling whole days ending today, in the viewer's time zone), or
- `{"prop": "...", "from": "YYYY-MM-DD", "to": "YYYY-MM-DD"}` with both days included.

It is ANDed with the view's filter, so it can only narrow what the view shows.

**Rules.** The property must be a date, created time or edited time property of that database, `within` and `from`/`to` cannot be mixed, the days must be real dates and `from` must not be after `to`; anything else answers `400 bad_date_range`.

**In the window.** The database toolbar's Date range control keeps each viewer's choice per view in the browser (`formmd.daterange.<view id>`) and sends it with every rows and chart request of that view.

## The contract

Expand All @@ -101,11 +112,21 @@ The table renders only the rows near the viewport and asks the server for each w

## Templates that show every view

Since v0.45.0 Home leads with **Data & charts**: 15 featured templates (Sales dashboard, Website analytics, Project portfolio, Finance overview, Survey results, Inventory and stock levels, Team capacity, Customer map, Fitness tracker, Habit heatmap, Knowledge graph, Formula and rollup playground, Content library, Quarterly report, Diagram gallery) that between them use all 13 chart kinds and all 13 views, with real rows dated relative to the day they are added so calendars, heatmaps and timelines are never empty. **Example projects** follows: 14 projects, each a home page with inline dashboards, sub-pages and related databases. Both are built by `internal/templates/build.go`, which creates the page tree first and then fills `{{db:KEY}}` and `{{page:KEY}}` placeholders, relations given by row title, and relative dates. The catalogue is checked when the server starts, so a template that points at a missing database or option does not ship.
- **Data & charts.** Since v0.45.0 Home leads with **Data & charts**: 15 featured templates (Sales dashboard, Website analytics, Project portfolio, Finance overview, Survey results, Inventory and stock levels, Team capacity, Customer map, Fitness tracker, Habit heatmap, Knowledge graph, Formula and rollup playground, Content library, Quarterly report, Diagram gallery) that between them use all 13 chart kinds and all 13 views, with real rows dated relative to the day they are added so calendars, heatmaps and timelines are never empty.
- **Example projects.** **Example projects** follows: 14 projects, each a home page with inline dashboards, sub-pages and related databases.
- **How they are built.** Both are built by `internal/templates/build.go`, which creates the page tree first and then fills `{{db:KEY}}` and `{{page:KEY}}` placeholders, relations given by row title, and relative dates.
- **Checked at start.** The catalogue is checked when the server starts, so a template that points at a missing database or option does not ship.

## Forms and responses

A form view (and its public link) lists questions, each bound to one property of the database. `internal/collection/forms.go` validates a submission exactly as before: required questions, per-type normalising, select options and conditional questions. Since v0.47.0 the validated answers are stored as one response record on the new row (`collection_rows.response`: form id, form version, answers by question id, submitted time) and the row's own `vals` stay empty. The answer columns are computed from the record when a row is read (`effectiveVals` in `internal/collection/response.go`, applied where the snapshot is built and where the write paths read values), so views, filters, sorts, formulas, exports, the API and search see the same values as before. A cell a person edits is kept in the row's own `vals` as an override and wins over the computed value; clearing a computed cell keeps a null override. Rows made before v0.47.0 keep their stored values and need no migration. The page title still names the row from the title answer.
A form view (and its public link) lists questions, each bound to one property of the database.

- **Checking a submission.** `internal/collection/forms.go` validates a submission exactly as before: required questions, per-type normalising, select options and conditional questions.
- **Where the answers go.** Since v0.47.0 the validated answers are stored as one response record on the new row (`collection_rows.response`: form id, form version, answers by question id, submitted time) and the row's own `vals` stay empty.
- **How they show up as columns.** The answer columns are computed from the record when a row is read (`effectiveVals` in `internal/collection/response.go`, applied where the snapshot is built and where the write paths read values), so views, filters, sorts, formulas, exports, the API and search see the same values as before.
- **When a person edits a cell.** A cell a person edits is kept in the row's own `vals` as an override and wins over the computed value; clearing a computed cell keeps a null override.
- **Older rows.** Rows made before v0.47.0 keep their stored values and need no migration.
- **The row's title.** The page title still names the row from the title answer.

Automations on a form use their own trigger, **When a response is received**. The event carries the response record, and the trigger's condition is judged against the answers as submitted, not against stored properties. A **When a page is added** automation on a database with a form view was carried over to this trigger by migration 0031, with **Also when a page is added by hand** ticked so it keeps running for rows added by hand. Rows made by a form do not raise the plain row-added event for automations.

Expand Down
Loading
Loading