@agentshouse/mdruntime-adapter 0.1.0-cb89e0425af50 → 0.1.0-cb9b1f8bb3e9a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/AGENTS.md +255 -224
  2. package/dist/actions.d.ts +61 -1
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +80 -86
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +229 -63
  8. package/dist/discovery.d.ts +1 -0
  9. package/dist/discovery.d.ts.map +1 -1
  10. package/dist/discovery.js +6 -2
  11. package/dist/handed.d.ts +15 -0
  12. package/dist/handed.d.ts.map +1 -0
  13. package/dist/handed.js +38 -0
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/model.d.ts +0 -1
  18. package/dist/model.d.ts.map +1 -1
  19. package/dist/model.js +0 -3
  20. package/dist/read.d.ts +26 -7
  21. package/dist/read.d.ts.map +1 -1
  22. package/dist/read.js +136 -78
  23. package/dist/referrer.d.ts +7 -0
  24. package/dist/referrer.d.ts.map +1 -0
  25. package/dist/referrer.js +35 -0
  26. package/dist/refusal.d.ts.map +1 -1
  27. package/dist/refusal.js +2 -1
  28. package/dist/site.d.ts +1 -1
  29. package/dist/site.d.ts.map +1 -1
  30. package/dist/site.js +157 -47
  31. package/dist/stream.d.ts +5 -4
  32. package/dist/stream.d.ts.map +1 -1
  33. package/dist/stream.js +300 -14
  34. package/dist/transport.d.ts +48 -10
  35. package/dist/transport.d.ts.map +1 -1
  36. package/dist/transport.js +3 -0
  37. package/dist/version.d.ts +1 -0
  38. package/dist/version.d.ts.map +1 -1
  39. package/dist/version.js +1 -1
  40. package/dist/write.d.ts +2 -9
  41. package/dist/write.d.ts.map +1 -1
  42. package/dist/write.js +59 -10
  43. package/package.json +2 -3
  44. package/dist/links.d.ts +0 -20
  45. package/dist/links.d.ts.map +0 -1
  46. package/dist/links.js +0 -104
package/AGENTS.md CHANGED
@@ -1,72 +1,76 @@
1
1
  # Instructions for the App Creator's agent
2
2
 
3
- These instructions address an agent in an environment with Git. Obtain the
4
- App Repository, change it, build, and push. They are documentation, not
5
- enforcement.
3
+ These instructions address an agent in an environment with Git. Obtain the App
4
+ Repository, change it, build, and push. They are documentation, not enforcement.
6
5
 
7
6
  ## The MD Runtime API
8
7
 
9
- App code reaches the MD Runtime through the remote client. The surfaces are
10
- Rooms, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
- the reported persistence answer, reauthorization, conversation, the chat draft,
12
- and Presentation State. Sync Status, the Service Mode, the storage-loss
8
+ App code reaches the MD Runtime through the remote client. The surfaces are Rooms,
9
+ Query, Search, Observe, Types, Room Draft, Save, History, the binary file reads, Call,
10
+ Reached, Log, the reported persistence answer, reauthorization, conversation, the chat
11
+ draft, and Presentation State. Sync Status, readiness, the Service Mode, the storage-loss
13
12
  statement, the deployment facts and the signed-in member are observations only.
14
13
 
15
- The host attaches each port with its reach, and every member and observation
16
- answers within it: a Room outside it answers as one the replica does not hold,
17
- Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
- shows only those Documents and the Types of the models that govern them, and
19
- without conversations the conversation members, the chat draft and the
20
- conversation observation hold none.
21
- A change of the reach reaches every open observation as its new value, a query
22
- keeping every unchanged Document the same object.
23
-
24
- Every `observe` resolves, once its first value has arrived, to a handle:
25
- `current()` is the latest complete value, `subscribe(listener)` hears each later
26
- value whole and returns its unsubscribe, and `close()` ends the observation.
27
- Closing the port ends every handle and rejects every pending call and
28
- observation; a client that reconnects observes again.
29
-
30
- Each conversation the Provider's conversation list names is held complete in the
31
- browser. `conversation.list()` and `observe('conversations')` answer each with its
32
- Agent's identity and name, its name, created and finished times, last outcome and live
33
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
34
- and `started`, when the running turn began, or `null`.
35
- Observe one with `observe('conversation', id, { limit })`: the view
36
- holds its latest `limit` messages, or all of them, oldest first, its chat
37
- draft, and what the Provider streams for it whether or not anything views it:
38
- the running `turn` with its message parts and its context in use and window, the
39
- open questions, the process state, and the CLI's commands and options. These live
40
- only in memory: the message accepted under the turn's id replaces the running turn,
41
- and none of them is stored or searchable.
42
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
43
- sending it is a Provider Action that needs the Provider reachable and is never
44
- queued.
45
-
46
- Each Room in Rooms lists its `attachments`, the files the Provider holds for it
47
- that its Documents link by the Provider's reference, ordered by `reference`,
48
- each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
49
- `entry`. They are as the Provider last declared them and hold no bytes;
50
- open one through the Provider Action that serves it.
51
-
52
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
53
- touch the network.
54
- History and Call go to the Provider through the Adapter. Call takes the Action names
55
- the Adapter declares; any other name answers `undeclared` without reaching the
56
- Provider. A Call result whose
57
- effect the Provider places in a Room carries `at`, that Room and Room Version;
58
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
59
- reached it, and the MD Runtime keeps refreshing that Room until it has;
60
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
61
- that document was written at a later Room Version. Each History revision
62
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
63
- History of a Path no current document holds answers the removed document's
64
- revisions with `deleted: true`, newest first; that revision is what a link to
65
- the Path opens. Every
66
- member of the
67
- client is asynchronous. Results are detached snapshots. Nothing in this
68
- surface returns the authorization, performs a request the App's code
69
- composes, or exposes the browser store.
14
+ The host attaches each port with its reach, and every member and observation answers
15
+ within it: a Room outside it answers as one the replica does not hold, Rooms lists only
16
+ the Rooms reached whole, a Room reached for single Documents shows only those Documents
17
+ and the Types of the models that govern them, and without conversations the conversation
18
+ members, the chat draft and the conversation observation hold none. A change of the
19
+ reach reaches every open observation as its new value, a query keeping unchanged
20
+ Documents the same objects.
21
+
22
+ Every `observe` resolves, once its first value has arrived, to a handle: `current()` is
23
+ the latest complete value, `subscribe(listener)` hears each later value whole and
24
+ returns its unsubscribe, and `close()` ends the observation. Closing the port ends every
25
+ handle and rejects every pending call and observation; a client that reconnects observes
26
+ again.
27
+
28
+ `observe('agents')` answers every Agent a new conversation can go to, each `{ identity,
29
+ name }`, whether or not it has a conversation yet. Each conversation the Provider's
30
+ conversation list names is held complete in the browser. `conversation.list()` and
31
+ `observe('conversations')` answer each with its Agent's identity and name, its name,
32
+ created and finished times, last outcome and live `state`: `asking` while a question
33
+ waits, `working` while a turn runs, else `idle`, and `started`, when the running turn
34
+ began, or `null`. Observe one with `observe('conversation', id, { limit })`: the view
35
+ holds a window of its latest `limit` messages, or all of them, oldest first, its chat
36
+ draft, and what the Provider streams for it whether or not anything views it: the
37
+ running `turn` with its message parts and its context in use and window, the open
38
+ questions, the process state, and the CLI's commands and options. These live only in
39
+ memory: the message accepted under the turn's id replaces the running turn, and none of
40
+ them is stored or searchable. `chatDraft.write` and `chatDraft.discard` keep what the
41
+ App Creator composes; sending it is a Provider Action that needs the Provider reachable
42
+ and is never queued.
43
+
44
+ A binary file at a Path is a binary Path entry. Query lists it by `path`, and History
45
+ each of its revisions, with its `binaryFile` record and never its bytes: `{ state:
46
+ 'accepted', revision, path, fileRef, byteLength, mediaType, sha256 }`, or, from a Save
47
+ until the Provider accepts it, `{ state: 'pending', localId, path, byteLength,
48
+ mediaType, sha256 }`. Write one with a Room Draft whose only part is `file: { blob }`,
49
+ the `Blob`'s `type` its media type: Save keeps the bytes in its Pending Change, offline
50
+ too, and acceptance gives the record the Provider's revision. Move or remove one as a
51
+ Document, a pending one before or after Save too, its bytes following; once its Pending
52
+ Change has gone to the Provider, Save refuses that as `unknown-revision` until it is
53
+ accepted. `binaryFile.read(room, path, revision?)` answers a pending record's saved
54
+ bytes, or asks the Provider again on every read of an accepted one or of a History
55
+ revision, a removed file's last included, keeping nothing. Text, a Record attachment or
56
+ a conversation message may name a file by its `fileRef`; read it with
57
+ `binaryFile.readReference({ fileRef, referrer })`, the referrer being the `referrer` the
58
+ Provider gave beside it, or `{ room, path }` of the document whose text names it. Both
59
+ answer `{ kind: 'binary', blob }` or a refusal or failure.
60
+
61
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never touch the
62
+ network. History, the binary file reads and Call go to the Provider through the Adapter.
63
+ Call takes the Action names the Adapter declares; any other name answers `undeclared`
64
+ without reaching the Provider. A Call result whose effect the Provider places in a Room
65
+ carries `at`, that Room and Room Version; `reached(room, roomVersion)` answers whether
66
+ the Room's confirmed state has reached it, and the MD Runtime keeps refreshing that Room
67
+ until it has; `reached(room, roomVersion, path)` answers whether the held confirmed copy
68
+ of that document was written at a later Room Version. Each History revision names its
69
+ author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. History of a Path no
70
+ current document holds answers the removed document's revisions with `deleted: true`,
71
+ newest first; that revision is what a link to the Path opens. Every member of the client
72
+ is asynchronous. Results are detached snapshots. Nothing in this surface returns the
73
+ authorization, performs a request the App's code composes, or exposes the browser store.
70
74
 
71
75
  Every refusal and failure carries `code` and `retryable`: each Call and History answer
72
76
  other than its result, a refused Save or Room Draft write, a returned Room Draft's
@@ -75,195 +79,222 @@ with, beside its message. A Provider refusal carries the Provider's own `retryab
75
79
  Every code and every value the API answers is open: handle one you do not know by its
76
80
  `code` and `retryable`.
77
81
 
78
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
79
- opaque value using the host's contract.
80
-
81
- `observe('member')` answers who uses the App: the User the Provider signed in,
82
- `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
83
- whose `change.author.id` equals its `id` is that User's own. It is `null` until
84
- the Provider first names one, and where it names none, such as a Site. The
85
- MD Runtime keeps it with the Local Replicas, so it answers offline once known,
86
- and every port hears the next member the Provider names; signing out answers
87
- `null`, then ends the observation with the authorization. It is the only way App code learns who
88
- uses it.
89
-
90
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
91
- ships in no bundle.
82
+ Read the deployment facts with `observe('deployment-facts')`, an opaque value the host's
83
+ contract interprets. `observe('member')` answers who uses the App: the User the Provider
84
+ signed in, `{ kind: 'user', id, name }` in the shape of a change's `author`, so a
85
+ Document whose `change.author.id` equals its `id` is that User's own. It is `null` until
86
+ the Provider first names one, and where it names none, such as a Site. The MD Runtime
87
+ keeps it with the Local Replicas, so it answers offline once known, and every port hears
88
+ the next member the Provider names; signing out answers `null`, then ends the
89
+ observation with the authorization. It is the only way App code learns who uses it.
92
90
 
93
91
  ## Local Query rules
94
92
 
95
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
96
- result and hears it again only when it changes, keeping every unchanged Document
97
- the same object, so a component can tell what changed by identity. A query is
98
- data:
99
-
100
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
101
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
102
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
93
+ `query(q)` answers once from local state; `observe('query', q)` holds the whole result
94
+ and hears it again only when it changes, keeping every unchanged Document the same
95
+ object, so a component can tell what changed by identity. An answer is complete or
96
+ pending: `{ documents, coverage }` or `{ groups, coverage }` is complete for the Rooms
97
+ its `coverage` names, and `{ pending }` names each Room not yet acquired or prepared,
98
+ `[{ room, awaits }]`. Never read a pending answer as empty: draw it as loading, and
99
+ observe the query to hear the complete one. A query is data:
100
+
101
+ - **Filter.** `rooms` names Room locators and defaults to every Room. `types` names MD
102
+ Types, and `any` names untyped Markdown Documents. `pathPrefix` is a directory:
103
+ `notes` keeps `notes/a.md` and not `notes2/a.md`.
103
104
  - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
104
- `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
105
- meets a list applies to every item and a number names one item. `where` names
106
- pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
107
- when any item satisfies it. A bare value is equality; the operators are `$eq`,
108
- `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
109
- `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
110
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
111
- text and `$size: 0` an empty list. A date compares in calendar order and never
112
- with a date-time. A reference compares by the Room Path it resolves to.
113
- Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
114
- values. There is no text containment or regular
105
+ `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that meets a
106
+ list applies to every item and a number names one item. `where` names pointers, ANDs
107
+ them, and nests `$and` and `$or`; a pointer through a list holds when any item
108
+ satisfies it. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
109
+ `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list asks
110
+ whether it contains the value. Missing, null and empty differ: `$exists: false` keeps
111
+ a missing field, `null` an explicit null, `''` empty text and `$size: 0` an empty
112
+ list. A date compares in calendar order and never with a date-time. A reference
113
+ compares by the Room Path it resolves to. Untyped frontmatter, and a value under
114
+ `oneOf` or a conditional, is plain values. There is no text containment or regular
115
115
  expression.
116
116
  - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
117
- reference at pointer `field`, at any depth, points to a matching Document of the
118
- same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
119
- matching Document of the same Room references. Each keeps a Document once.
117
+ reference at pointer `field`, at any depth, points to a matching Document of the same
118
+ Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a matching
119
+ Document of the same Room references. Each keeps a Document once.
120
120
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
121
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
122
- list of pointers and `sections` `'all'` or a list of names. Selected pointers
123
- return the frontmatter holding only them, nested as written. A backlink names
124
- the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
125
- Document also returns its MD Type. A non-Markdown Document or binary link
126
- target returns only Room and Path. An unselected part is absent. Select only
127
- what a screen shows: a list that selects the Markdown hears every edit of it.
128
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
129
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
130
- or `null` for a write the Provider made itself, and `time` is the Provider's
131
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
132
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
133
- saved write takes the Provider's own once it is Accepted. A
134
- Room's last change is its Document with the latest `time`.
135
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
136
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
137
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
138
- over every match and ordered by `count` or a key. A sort or group takes only a
139
- pointer that holds one value. `limit` bounds the Documents or the groups.
140
- - **Results and errors.** A result carries no Room Version: read freshness from
141
- Rooms and Sync Status. An invalid query fails with the `code`
142
- `invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
143
- and never answers an empty result in its place.
121
+ `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a list
122
+ of pointers and `sections` `'all'` or a list of names. Selected pointers return the
123
+ frontmatter holding only them, nested as written. A backlink names the referring Path,
124
+ MD Type and the pointer it came from as `field`. Room and Path always return; a
125
+ Markdown Document also returns its MD Type. A non-Markdown Document returns only Room
126
+ and Path, and a binary Path entry Room, Path and its `binaryFile` record, whatever is
127
+ selected. An unselected part is absent. Select only what a screen shows: a list that
128
+ selects the Markdown hears every edit of it.
129
+ - **Change.** `change` is `{ author, time }` of the Document's head revision as the
130
+ Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }` or
131
+ `null` for a write the Provider made itself, and `time` is the Provider's ISO 8601
132
+ change time. It is `null` where the Provider delivered no time, as at a Site. An
133
+ unsent edit or move keeps it, an unsent creation has none, and a saved write takes the
134
+ Provider's own once it is Accepted. A Room's last change is its Document with the
135
+ latest `time`.
136
+ - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }` with
137
+ TanStack DB's own options, and ties end with Room, then Path. `groupBy` by `room`,
138
+ `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted over every match
139
+ and ordered by `count` or a key. A sort or group takes only a pointer that holds one
140
+ value. `limit` bounds the Documents or the groups.
141
+ - **Results and errors.** A result carries no Room Version: read freshness from Rooms
142
+ and Sync Status. `coverage` names each Room read as `{ room, generation, current }`,
143
+ `current` false while a newer copy of that Room is being fetched, and the queued
144
+ changes it includes as `overlay`; a Save in a Room changes the `overlay` of every
145
+ query over it. An invalid query fails with the `code` `invalid-query`, `unknown-type`,
146
+ `unknown-field` or `wrong-kind`, naming where, and never answers an empty result in
147
+ its place.
144
148
 
145
149
  ## Local Search rules
146
150
 
147
- `search({ text, documents, conversations, limit })` answers once, by words, from
148
- local state, with MiniSearch at its default configuration. There is no observed
149
- search.
151
+ `search({ text, documents, conversations, limit })` answers once, by words, from local
152
+ state, with MiniSearch's defaults. There is no observed search.
150
153
 
151
- - **What is found.** A Document by its field values, its sections' headings and
152
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
153
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
154
- word forms, typo tolerance or prefix matching.
154
+ - **What is found.** A Document by its field values, its sections' headings and text,
155
+ its preamble and its Path; a message by its text. Frontmatter keys, Room Drafts, chat
156
+ drafts and a running turn's parts are never found. There are no phrases, word forms,
157
+ typo tolerance or prefix matching.
155
158
  - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
156
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
157
- apply before `limit`, which bounds each list; without it every hit returns.
158
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
159
- hits of one list of one search. A Document hit names its `room`, `path` and
160
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
161
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
162
- `path`, or `text`. A hit carries no position; mark the words in the text you
163
- show. An invalid filter fails with its Local Query error.
159
+ `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both apply
160
+ before `limit`, which bounds each list; without it every hit returns.
161
+ - **Results.** `{ documents, messages, coverage }`, or `{ pending }` naming each Room or
162
+ conversation the search waits for while its index is prepared: ask again, and never
163
+ read pending as no hits. `coverage` names the Rooms and conversations searched. Each
164
+ list is ranked by `score`, which compares hits of one list of one search. A Document
165
+ hit names its `room`, `path` and `type`, a message hit its `conversation` and
166
+ `identity`, and `matches` maps each matched word to the parts it matched in: `fields`,
167
+ `sections`, `preamble` or `path`, or `text`. A hit carries no position; mark the words
168
+ in the text you show. An invalid filter fails with its Local Query error.
164
169
 
165
170
  ## Room Draft, Save, and outcome rules
166
171
 
167
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
168
- tab. It is durable: it survives reload and navigation. A Room that Discovery
169
- stops listing takes its Room Drafts and its queue with it.
170
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
171
- the revision you read, or `null` when there was none, and every part it should
172
- now change: fields, sections and the preamble, or the whole Markdown, a
173
- creation, a move, or a removal. A part new to the Room Draft names its base,
174
- the value you showed when it was opened; the MD Runtime keeps a part's first
175
- base. A binary link target has a Room Draft too, for a move or a removal, with
176
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
177
- the current Room Draft; read it and write again.
178
-
179
- Save takes one Room and the Room Drafts of it to save, each with its revision,
180
- validates locally, and on success appends one Change Batch to that Room's
181
- queue and removes those Room Drafts. It is refused with the `code` `stale`,
182
- `changed-underneath` naming each part whose base no longer matches the visible
183
- state, or a local validation rule, and then creates nothing and leaves every
184
- Room Draft in place. A directory move or removal is a move or removal part on
185
- each Document and binary link target beneath it, saved together.
186
-
187
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
188
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
189
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
190
- longer applies over the Room each leave the queue and return as Room Drafts on
191
- the Documents they changed, marked with why: the Provider's structured refusal
192
- code and fields as returned, not known to have applied, or withdrawn locally.
193
- The rest of the queue keeps synchronizing, and Sync Status requires attention
194
- until each returned Room Draft is saved again or discarded. A Change Batch
195
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
196
- Pending one, and a returned Room Draft says why it returned. Transport
197
- failure and Provider unavailability keep work Pending and do not infer a
198
- rejection. A refusal the Provider marks retryable stays Pending until the reset
199
- it names; the MD Runtime retries the same Change Batch identity and payload and
200
- never infers an outcome from transport uncertainty. The MD Runtime never
201
- combines, reorders, or rebases.
202
-
203
- On a Site, every Save stays in the visitor's browser. Write grants and
204
- revisions do not refuse it, and its Pending Change shows in every query and
205
- across reloads until the browser's storage is cleared. It is never sent:
206
- `observe('queue', room)` shows it `local`, and Sync Status never waits on it.
207
- Once the Room changes so that it no longer applies, it leaves the queue and
208
- returns no Room Draft.
209
-
210
- `observe('service-mode')` answers the Provider's Service
211
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
212
- its Change Batch waits unsent, and the queue is submitted in order once the
213
- Provider reopens writes. An Action is never held: a write the Provider refuses
214
- for the halt returns that refusal to its caller. Show the Provider as read-only
215
- instead of retrying.
172
+ The MD Runtime owns one Room Draft per Room and Path, shared by every App and tab. It is
173
+ durable: it survives reload and navigation. A Room that Discovery stops listing takes
174
+ its Room Drafts and its queue with it. Write a Room Draft with `roomDraft.write(room,
175
+ path, revision, parts)`, naming the revision you read, or `null` when there was none,
176
+ and every part it should now change: fields, sections and the preamble, or the whole
177
+ Markdown, a creation, a move, or a removal. A part new to the Room Draft names its base,
178
+ the value you showed when it was opened; the MD Runtime keeps a part's first base; a
179
+ binary Path entry's move or removal takes `null` as its base. A write or a discard from
180
+ an older revision is refused as `stale` with the current Room Draft; read it and write
181
+ again.
182
+
183
+ Save takes one Room and the Room Drafts of it to save, each with its revision, validates
184
+ locally, and on success appends one Change Batch to that Room's queue and removes those
185
+ Room Drafts. It is refused with the `code` `stale`, `changed-underneath` naming each
186
+ part whose base no longer matches the visible state, or a local validation rule, and
187
+ then creates nothing and leaves every Room Draft in place. A directory move or removal
188
+ is a move or removal part on each Document and binary Path entry beneath it, saved
189
+ together.
190
+
191
+ Outcomes follow the Provider's answer. An Accepted Change Batch stays in the queue,
192
+ drawn over the confirmed layer, until the confirmed layer reaches the Room Version it
193
+ was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and
194
+ a change that no longer applies over the Room each leave the queue and return as Room
195
+ Drafts on the Documents they changed, marked with why: the Provider's structured refusal
196
+ code and fields as returned, not known to have applied, or withdrawn locally. The rest
197
+ of the queue keeps synchronizing, and Sync Status requires attention until each returned
198
+ Room Draft is saved again or discarded. A Change Batch keeps no outcome once it leaves
199
+ the queue; `observe('queue', room)` shows each Pending one, and a returned Room Draft
200
+ says why it returned. Transport failure and Provider unavailability keep work Pending
201
+ and do not infer a rejection. A refusal the Provider marks retryable stays Pending until
202
+ the reset it names; the MD Runtime retries the same Change Batch identity and payload
203
+ and never infers an outcome from transport uncertainty. The MD Runtime never combines,
204
+ reorders, or rebases.
205
+
206
+ On a Site, every Save stays in the visitor's browser. Write grants and revisions do not
207
+ refuse it, and its Pending Change shows in every query and across reloads until the
208
+ browser's storage is cleared. It is never sent: `observe('queue', room)` shows it
209
+ `local`, and Sync Status never waits on it. Once the Room changes so that it no longer
210
+ applies, it leaves the queue and returns no Room Draft.
211
+
212
+ `observe('service-mode')` answers the Provider's Service Mode, `open` or `write-halted`.
213
+ While writes are halted, Save still succeeds, its Change Batch waits unsent, and the
214
+ queue is submitted in order once the Provider reopens writes. An Action is never held: a
215
+ write the Provider refuses for the halt returns that refusal to its caller. Show the
216
+ Provider as read-only instead of retrying.
217
+
218
+ `observe('readiness')` tells whether the App's code and bound Rooms are held locally
219
+ (`ready`), each Room's state, each refused Room's file and rule, the persistence answer
220
+ and a paused preparation's `capacity` cause; `retry()` resumes a paused preparation.
216
221
 
217
222
  ## The neutrality rule
218
223
 
219
- No module outside an Adapter package imports, names, or special-cases a
220
- Provider. MD UI and every App reach data only through the client entry.
224
+ No module outside an Adapter package imports, names, or special-cases a Provider. MD UI
225
+ and every App reach data only through the client entry.
221
226
 
222
227
  ## Content-safety rules
223
228
 
224
- The Provider authorization belongs to the Runtime host and is never readable
225
- by the App's code. The App's code reaches the network only at the external
226
- origins its manifest declares, empty by default, and the Provider enforces
227
- that set. Every request to the Provider itself goes through the MD Runtime.
228
- Rendered Markdown never executes scripts, renders raw HTML only for the
229
- details and summary elements, and loads images and other resources only from
230
- origins the Provider's policy allows.
229
+ The Provider authorization belongs to the Runtime host and is never readable by the
230
+ App's code. The App's code reaches the network only at the external origins its manifest
231
+ declares, empty by default, and the Provider enforces that set. Every request to the
232
+ Provider itself goes through the MD Runtime. Rendered Markdown never executes scripts,
233
+ renders raw HTML only for the details and summary elements, and loads images and other
234
+ resources only from origins the Provider's policy allows.
231
235
 
232
236
  ## Launch promises MD UI keeps
233
237
 
234
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
235
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
236
- a desktop. Its strings are English only, dates and numbers follow the
237
- browser locale, and content is never translated. Light and dark themes come
238
- from CSS custom properties with the browser's preference as the default and
239
- an App's override respected. What an App Creator's agent adds carries none
240
- of these promises by itself. Reading, querying and searching never wait for
241
- the network. Data lives only in the App Creator's browser and with the Provider.
238
+ MD UI uses semantic HTML, is fully operable from a keyboard with visible focus and
239
+ labelled controls, and lays out from a 360 pixel wide viewport to a desktop. Its strings
240
+ are English only, dates and numbers follow the browser locale, and content is never
241
+ translated. Light and dark themes come from CSS custom properties with the browser's
242
+ preference as the default and an App's override respected. What an App Creator's agent
243
+ adds carries none of these promises by itself. Reading, querying and searching never
244
+ wait for the network. Data lives only in the App Creator's browser and with the
245
+ Provider.
242
246
 
243
247
  ## App code takes the client its host hands it and never constructs a Runtime
244
248
 
245
- App code takes the client its host hands it: in House,
246
- `houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
247
- client House built into the page. It never constructs a Runtime or a client.
248
- It imports only types from `@agentshouse/mdruntime/client`, does not call
249
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
250
- the host entry, or the Adapter package. Hosts and tests use those entries; the
251
- served App does not.
252
-
253
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
254
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
255
- the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
256
- first value arrives, then `{ state: 'ready', value }`, re-rendering on each
257
- change; a `null` client observes nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
258
- `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
259
- already there, keeping the bases its parts have, or onto a new one, and saves
260
- them together. A refused Save leaves the Room Drafts for the App to save again
261
- or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
262
- roomDrafts)` is that save outside a component. A react-admin or Refine App
263
- reads and writes its Rooms through the data providers of
264
- `@agentshouse/mdruntime-families`.
249
+ App code takes the client its host hands it: in House, `houseBridge().runtime` from
250
+ `@agentshouse/app-bridge` resolves to the client House built into the page. It imports
251
+ only types from `@agentshouse/mdruntime/client`, never calls `connectMdRuntime` or
252
+ `serveMdRuntime`, and never imports the package main, the host entry or the Adapter
253
+ package, which hosts and tests use. The in-memory Adapter at
254
+ `@agentshouse/mdruntime/memory` is for tests and ships in no bundle. A Site's page fills
255
+ its Entry Data Contract's `{"$param": name}` arguments with `boundQuery` from
256
+ `@agentshouse/mdruntime/entry`, as House did for its HTML.
257
+
258
+ A React App may observe and save through `@agentshouse/mdruntime/react`, which names
259
+ React as a peer dependency. `useObserve(client, topic, ...input)` takes the arguments of
260
+ `observe` and returns `{ state: 'loading' }` until the topic's first value arrives, then
261
+ `{ state: 'ready', value }`, re-rendering on each change; a `null` client observes
262
+ nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or
263
+ `failure`, and `save(room, roomDrafts)`, which writes each Path's parts onto the Room
264
+ Draft already there, keeping the bases its parts have, or onto a new one, and saves them
265
+ together. A refused Save leaves the Room Drafts for the App to save again or discard; a
266
+ failure is recorded and rejects. `saveRoomDrafts(client, room, roomDrafts)` is that save
267
+ outside a component. A react-admin or Refine App reads and writes its Rooms through the
268
+ data providers of `@agentshouse/mdruntime-families`.
269
+
270
+ ## The Chat
271
+
272
+ `@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App; add React as
273
+ a dependency in any App, with React DOM and `@assistant-ui/react`.
274
+
275
+ Place the ready chat with `<Chat client={runtime} conversation={id} agent={agent}
276
+ width="1/3" showChats />`: `conversation` opens one, `null` for a new chat, `agent` is
277
+ the Agent a new chat goes to, `onOpen` hears each one it opens, and `width` is `full`
278
+ (the place you give it), or `3/4`, `1/2` or `1/3` of the window docked at its right
279
+ edge, whole on a narrow window. `showChats` adds its conversation list; or draw your own
280
+ inside a `ChatProvider` around a `<Chat />` with no `client`. It carries its own styles;
281
+ theme it with CSS custom properties on it or an ancestor: `--chat-background`,
282
+ `--chat-surface`, `--chat-text`, `--chat-text-muted`, `--chat-accent`, `--chat-line`,
283
+ `--chat-attention`, `--chat-danger`, `--chat-font`, `--chat-font-mono`,
284
+ `--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for spacing); an
285
+ unset one keeps House's light or dark look. `mountChat(element, { client })` places it
286
+ outside React and returns `update(props)` and `unmount()`.
287
+
288
+ Mix `ChatMessageList` (`components` takes your `UserMessage` and `AssistantMessage`),
289
+ `ChatInput` and `ChatQuestionCard` with your own design inside a `ChatProvider`, or
290
+ compose assistant-ui's primitives there; `useChat()` gives `send`, the conversations,
291
+ the Agents, questions to `answer`, `options` to `choose`, `commands`, the queue to
292
+ `edit` or `unqueue`, `stop`, `kill` and outcomes; never replace its messages, sending or
293
+ store. A secret question is never answered here; typed answers live in Presentation
294
+ State's `typed` key: keep it, and change Presentation State only inside `inTurn(client,
295
+ work)` from `@agentshouse/mdruntime/client`. `Markdown` draws Markdown safely.
265
296
 
266
297
  ## What an agent must never do
267
298
 
268
- An agent must never read the authorization, load code from a Room, call the
269
- Provider directly, or rebase a refused Change Batch.
299
+ An agent must never read the authorization, load code from a Room, call the Provider
300
+ directly, or rebase a refused Change Batch.