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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Add a project rule in `.cursor/rules/` that tells the agent to take a `context_p

## Extensions in the window

Form extensions installed with FormPortal or run from form.ext live in the person's open window. `extensions_list` shows them (id, version, source, state, commands) and `extension_command` runs one of their commands with `id`, `command` and `args`. Both go through the window like `window_command_run`, so they fail when no window is open, and the window asks the person to allow an extension version the first time; a refusal is the person's answer, not a fault to retry. From a terminal: `form-md cli extensions` and `form-md cli extension ID COMMAND`.
Form extensions installed with FormPortal or run from form.ext live in the person's open window, and only the person runs them. `extensions_list` and `extension_command` are refused for an agent credential, as are window commands for import and export and for deleting from the trash for good; say so and ask the person to do it in the window rather than retrying. Opening the trash and restoring from it still work.

## When a call fails

Expand Down
4 changes: 2 additions & 2 deletions .docs/wiki/API-and-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Create one in **Account settings, API tokens**: give it a name, choose **Read an
curl -fsS -H "Authorization: Bearer fmd_..." https://notes.example.com/api/me
```

A token can only narrow what its owner can do. A read-only token gets an error on any request that changes something. Revoking one credential ends everything it holds open: deleting a token, signing out or removing a session, and revoking an OAuth grant or token close that credential's event stream, live editing sockets and terminal attachments straight away, and leave the person's other credentials connected. Expiry ends them the same way within about a minute: a session that runs past `auth.session_days`, and an OAuth grant whose last access token (one hour) runs out without a refreshed one; a client that refreshed in time keeps its streams. Some routes (instance administration, token management) accept only a signed-in browser session.
A token can only narrow what its owner can do. A read-only token gets an error on any request that changes something. Deleting a page from the trash for good (`DELETE /api/pages/{id}/forever`) and emptying a trash (`DELETE /api/workspaces/{id}/trash`) work only in a signed-in browser or the desktop app: a token or an OAuth grant gets `session_only`. Moving a page to the trash and restoring it still work with a token. Revoking one credential ends everything it holds open: deleting a token, signing out or removing a session, and revoking an OAuth grant or token close that credential's event stream, live editing sockets and terminal attachments straight away, and leave the person's other credentials connected. Expiry ends them the same way within about a minute: a session that runs past `auth.session_days`, and an OAuth grant whose last access token (one hour) runs out without a refreshed one; a client that refreshed in time keeps its streams. Some routes (instance administration, token management) accept only a signed-in browser session.

## OAuth 2.1

Expand Down Expand Up @@ -93,7 +93,7 @@ The credential decides what an agent may do; there is no separate question in th

- **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.
- **Extensions.** `extension_command` is a write tool, so a read-only credential does not see it and cannot call it. `extensions_list` and `extension_command` are refused for every agent credential, read-only or not: extensions are installed, allowed and run only by the person in the window.
- **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 Down
2 changes: 1 addition & 1 deletion .docs/wiki/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ The list needs a signed-in session or token. The file route needs none, because
| `./form-md cli extensions` | the same list from a terminal |
| `./form-md cli extension ID COMMAND key=value` | runs a contributed command |

They go through the window like `window_command_run` (see [[Terminal-and-Claude-Code]]), so a window must be open for the same account, and consent is asked there.
These commands are for the person signed in to the window. An agent, a token or a `form-md cli` script calling them is refused with a message saying so, because extension commands install, allow or run code; choose the command in the window yourself instead (see [[Terminal-and-Claude-Code]]).
2 changes: 2 additions & 0 deletions .docs/wiki/Terminal-and-Claude-Code.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ Every command in the window has an id, a label, a group and, for newer commands,
| `./form-md cli list`, `describe ID`, `run ID key=value` | the same from a terminal, with `FORMMD_MCP_TOKEN` |

A call needs a form.md window open for the same account; otherwise it fails with a message saying so. A read-only token can run only commands that change nothing.

Some commands stay with the person signed in to the window, and an agent, a token or a `form-md cli` script is refused them and does not see them listed: your account, admin, preferences, the terminal panel and its agents, making a workspace, extensions (installing, allowing, reloading or running them), import and export, and deleting pages from the trash for good. Opening the trash and restoring a page from it still work for agents.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ form.md is a server you sign in to, so what an agent may do is set by its creden

## Extensions

form.md loads Form extensions (Form Extension Contract, API 1): install them with FormPortal, or run a folder from form.ext. They appear under Extensions in the sidebar (and the desktop menu bar), in the Extensions panel on the right and in Find a Command; each runs in a sandboxed frame and changes the page only through form.md's own `doc.*` commands, as one undo step, after you allow it. Agents reach them with the MCP tools `extensions_list` and `extension_command`, or `./form-md cli extensions`. The API for extension authors is [`docs/EXTENSIONS.md`](docs/EXTENSIONS.md); the wiki page is Extensions.
form.md loads Form extensions (Form Extension Contract, API 1): install them with FormPortal, or run a folder from form.ext. They appear under Extensions in the sidebar (and the desktop menu bar), in the Extensions panel on the right and in Find a Command; each runs in a sandboxed frame and changes the page only through form.md's own `doc.*` commands, as one undo step, after you allow it. Extensions are installed, allowed and run only by the person in the window; agents and scripts are refused the extension commands. The API for extension authors is [`docs/EXTENSIONS.md`](docs/EXTENSIONS.md); the wiki page is Extensions.

## Under the hood

Expand Down
2 changes: 2 additions & 0 deletions docs/EXTENSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Commands marked risky in the catalogue, and the `extensions.*` commands themselv
- MCP `extension_command` with `id`, `command`, `args`: runs a contributed command in the open window. The window asks for consent first if the person has not allowed that version yet; the call waits up to 60 s.
- `form-md cli extensions` and `form-md cli extension ID COMMAND [key=value...]` do the same from a terminal.

These are refused for an agent, an API token or a script: extension commands stay with the person signed in to the window, who runs them from the Extensions menu, the Extensions panel or Find a Command.

## Running an extension

- **From a folder (form.ext Run in App)**: form.ext writes `extensions/formmd/dev.json` under the FormPortal root with the folder's path. form.md checks the file every 2 s while its window has focus, and on Reload Extensions, and shows the extension with the source Development and its folder.
Expand Down
17 changes: 17 additions & 0 deletions internal/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2656,3 +2656,20 @@ Owner request of 2026-11-22: a guide for taking one's own copy of form.md to one
The Auth0 page is derived from `internal/auth/oidc.go` and Auth0's documentation, with no Auth0 tenant involved. What the code settles: the issuer check uses the discovery document's own `issuer`, so Auth0's trailing slash is fine; only RS256 and ES256 verify; the client secret goes in the token request body; an existing account links only when both sides hold the email verified; a new account needs `SignupAllowed`; a provider sign-in starts a session without the form.md two-factor step. What it does not settle: `prompt=select_account` is sent to every provider, and Auth0 documents only `none` and `login` for it.

Ran: `bash -n` on the three scripts; the `example.com` guard and the host-name line of `install` on a copy of the env file; `go run ./tools/wikicheck` (22 pages agree). Not run: `provision`, `ship` and `install` against Google Cloud or any host.

## Window commands kept for the person {#window-person-only}

### internal/claudecode · extensions, transfer and deleting from the trash stay with the signed-in person
- refers-to: internal/claudecode/module.go :: `sessionOnlyPrefixes`, `agentTrashCommands`, `sessionOnly`, `RunCommand`; internal/claudecode/bridge_test.go :: `TestExtensionTransferAndEmptyTrashCommandsStayWithTheSignedInPerson`; internal/page/module.go :: `personRoute`; internal/server/trash_person_test.go :: `TestDeletingFromTheTrashForGoodStaysWithTheSignedInPerson`; internal/mcp/tools_window.go :: `extensions_list`, `extension_command`; cmd/form-md/cli.go :: `extensions`, `extension`
- kind: fix
- logged: v0.61.1 · 2026-11-29

Owner decision: three more families join `account.`, `admin.`, `prefs.`, `dock.`, `agent.` and `workspace.new` as window commands only the signed-in person runs. `extensions.` installs, allows, reloads or runs extension code; `transfer.` moves workspaces in or out (today `transfer.import`); `trash.` covers deleting pages for good. A token, an OAuth grant or a `form-md cli` script is refused with "ID works only for the person signed in to the window; an agent or script cannot run it", is not shown the command in `CatalogueFor` and gets no description from `DescribeFor`.

The trash rule is closed by default: every `trash.` id is person-only except those in `agentTrashCommands` (`trash.open` and `trash.restore`), so a future command that empties the trash or deletes a page for good is covered without being named, and a new harmless trash command needs adding there to reach agents. `page.trash` moves a page to the trash, where it can be restored, and stays open. The window has no command that empties the trash today; the Empty trash and Delete forever buttons in the trash view call `DELETE /api/workspaces/{id}/trash` and `DELETE /api/pages/{id}/forever` directly, so those two routes are mounted with `RequireSession`: a token or an OAuth grant gets `session_only`. `POST /api/pages/{id}/restore` and `DELETE /api/pages/{id}` (move to the trash) keep `Require`.

Consequence: MCP never runs as a session, so `extensions_list` and `extension_command`, and `form-md cli extensions` / `form-md cli extension`, now always end in that refusal. They are left in place, with the docs saying so, until the owner decides whether to remove them. Extension-contributed commands are registered as `ext.<extension id>.<command id>` and run the same code as `extensions.run`, so `ext.` is person-only too; otherwise `window_command_run` with an `ext.` id would do what `extension_command` is refused.

Ran: the new test failed on the code before the change (`extensions.list` ran for a token credential) and passes after it; `go test ./internal/claudecode` passes. The `ext.` case (`ext.sample.render` ran for a token credential) and the trash routes (a token deleted a page for good, 204) each failed before their change and pass after it.

Open: an extension in the window can still run window commands that are not `extensions.`, `ext.` or marked risky, which includes the other person-only families; the window does not check the person-only list. Import and export over REST and MCP are unchanged; the decision covered the window's `transfer.` commands.
4 changes: 2 additions & 2 deletions internal/apidoc/apidoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func init() {
for k, v := range map[string]string{
"GET /.well-known/oauth-authorization-server": "OAuth 2.1 authorization server metadata",
"GET /.well-known/oauth-protected-resource/api": "Protected resource metadata for the REST API",
"DELETE /api/pages/{id}/forever": "Delete a trashed page permanently",
"DELETE /api/pages/{id}/forever": "Delete a trashed page permanently (signed-in browser only)",
"GET /api/views/{id}/export.csv": "Export a view as CSV",
"POST /api/public/forms/{token}": "Submit a public form",
"PATCH /api/me": "Update the signed-in account",
Expand All @@ -270,7 +270,7 @@ func init() {
"GET /api/events": "Live event stream (server-sent events)",
"POST /api/rows/{id}/buttons/{prop}": "Press a row's button property",
"POST /api/buttons/run": "Run a button block's server actions",
"DELETE /api/workspaces/{id}/trash": "Empty a workspace's trash",
"DELETE /api/workspaces/{id}/trash": "Empty a workspace's trash (signed-in browser only)",
"GET /api/workspaces/{id}/graph": "Get the link graph of a workspace",
"POST /api/views/{id}/calendar-feed": "Get or renew a private calendar subscription address",
"GET /api/public/calendar/{file}": "Calendar subscription feed (iCalendar)",
Expand Down
56 changes: 56 additions & 0 deletions internal/claudecode/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"reflect"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -119,3 +120,58 @@ func TestAccountAndAdminCommandsStayWithTheSignedInPerson(t *testing.T) {
t.Fatal(err)
}
}

func TestExtensionTransferAndEmptyTrashCommandsStayWithTheSignedInPerson(t *testing.T) {
hub := &windowHub{workspace: "w1"}
s := &Service{Bridge: NewBridge(hub)}
hub.bridge = s.Bridge
s.SetReach(reachW1)
personOnly := []string{"extensions.list", "extensions.run", "extensions.reload", "ext.sample.render", "transfer.import", "transfer.export", "trash.empty", "trash.deleteForever"}
open := []string{"trash.open", "trash.restore", "page.trash"}
var specs []CommandSpec
for _, id := range append(append([]string{}, personOnly...), open...) {
specs = append(specs, CommandSpec{ID: id, Mutates: true})
}
s.Bridge.SetCatalogue("u1", specs)
for _, kind := range []policy.Kind{policy.KindToken, policy.KindOAuth} {
agent := &policy.Principal{UserID: "u1", Kind: kind, Scope: "write", AllWorkspaces: true}
for _, id := range personOnly {
_, err := s.RunCommand(context.Background(), agent, id, nil)
if err == nil || !strings.Contains(err.Error(), "signed in to the window") {
t.Fatalf("%s for a %s credential: err = %v", id, kind, err)
}
if _, ok := s.DescribeFor(agent, id); ok {
t.Fatalf("%s described to a %s credential", id, kind)
}
}
listed := map[string]bool{}
for _, c := range s.CatalogueFor(agent, "").([]CommandSpec) {
listed[c.ID] = true
}
for _, id := range personOnly {
if listed[id] {
t.Fatalf("%s listed to a %s credential", id, kind)
}
}
for _, id := range open {
if !listed[id] {
t.Fatalf("%s hidden from a %s credential", id, kind)
}
}
}
if len(hub.sent) != 0 {
t.Fatal("a person-only command reached the window")
}
agent := &policy.Principal{UserID: "u1", Kind: policy.KindToken, Scope: "write", AllWorkspaces: true}
for _, id := range open {
if _, err := s.RunCommand(context.Background(), agent, id, nil); err != nil {
t.Fatalf("%s refused for an agent credential: %v", id, err)
}
}
session := &policy.Principal{UserID: "u1", Kind: policy.KindSession, Scope: "write"}
for _, id := range personOnly {
if _, err := s.RunCommand(context.Background(), session, id, nil); err != nil {
t.Fatalf("%s refused for the signed-in person: %v", id, err)
}
}
}
9 changes: 7 additions & 2 deletions internal/claudecode/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,19 @@ func (s *Service) SetReach(fn func(ctx context.Context, p *policy.Principal) ([]

var ErrNoReach = errors.New("this credential cannot reach a workspace the window can show")

var sessionOnlyPrefixes = []string{"account.", "admin.", "prefs.", "dock.", "agent."}
var sessionOnlyPrefixes = []string{"account.", "admin.", "prefs.", "dock.", "agent.", "extensions.", "ext.", "transfer.", "trash."}

var sessionOnlyCommands = map[string]bool{"workspace.new": true}

var agentTrashCommands = map[string]bool{"trash.open": true, "trash.restore": true}

func sessionOnly(id string) bool {
if sessionOnlyCommands[id] {
return true
}
if agentTrashCommands[id] {
return false
}
for _, pre := range sessionOnlyPrefixes {
if strings.HasPrefix(id, pre) {
return true
Expand All @@ -726,7 +731,7 @@ func sessionOnly(id string) bool {

func (s *Service) RunCommand(ctx context.Context, p *policy.Principal, id string, params map[string]any) (json.RawMessage, error) {
if !p.IsSession() && sessionOnly(id) {
return nil, fmt.Errorf("%s works only for the person signed in to the window", id)
return nil, fmt.Errorf("%s works only for the person signed in to the window; an agent or script cannot run it", id)
}
spec, ok := s.Bridge.Describe(p.UserID, id)
if ok && spec.Mutates && !p.CanWrite() {
Expand Down
5 changes: 3 additions & 2 deletions internal/page/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func done(w http.ResponseWriter) error {
func (m module) Mount(r *httpx.Router, _ *app.Deps) error {
s, a := m.s, m.auth
route := func(pattern string, h handler) { r.HandleFunc(pattern, a.Require(h)) }
personRoute := func(pattern string, h handler) { r.HandleFunc(pattern, a.RequireSession(h)) }

route("GET /api/workspaces/{id}/pages", func(w http.ResponseWriter, r *http.Request, p *policy.Principal) error {
pages, err := s.Tree(r.Context(), p, r.PathValue("id"))
Expand All @@ -57,7 +58,7 @@ func (m module) Mount(r *httpx.Router, _ *app.Deps) error {
}
return ok(w, map[string]any{"items": items})
})
route("DELETE /api/workspaces/{id}/trash", func(w http.ResponseWriter, r *http.Request, p *policy.Principal) error {
personRoute("DELETE /api/workspaces/{id}/trash", func(w http.ResponseWriter, r *http.Request, p *policy.Principal) error {
n, err := s.EmptyTrash(r.Context(), p, r.PathValue("id"))
if err != nil {
return err
Expand Down Expand Up @@ -153,7 +154,7 @@ func (m module) Mount(r *httpx.Router, _ *app.Deps) error {
}
return ok(w, map[string]any{"page": m})
})
route("DELETE /api/pages/{id}/forever", func(w http.ResponseWriter, r *http.Request, p *policy.Principal) error {
personRoute("DELETE /api/pages/{id}/forever", func(w http.ResponseWriter, r *http.Request, p *policy.Principal) error {
if err := s.DeleteForever(r.Context(), p, r.PathValue("id")); err != nil {
return err
}
Expand Down
Loading
Loading