@agentshouse/mdruntime 0.1.0-c009335e08279 → 0.1.0-c05b32a1b6587

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