@agentshouse/mdruntime 0.1.0-cff8ba8fa2542 → 0.1.0-cffcba9cd9c2f

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 (327) hide show
  1. package/README.md +24 -11
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +309 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +251 -0
  8. package/dist/adapter.d.ts +195 -88
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +7 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +40 -28
  13. package/dist/attempt.d.ts +16 -0
  14. package/dist/attempt.d.ts.map +1 -0
  15. package/dist/attempt.js +70 -0
  16. package/dist/binary.d.ts +18 -0
  17. package/dist/binary.d.ts.map +1 -0
  18. package/dist/binary.js +8 -0
  19. package/dist/bootstrap.d.ts +37 -5
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +324 -51
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +12 -0
  26. package/dist/chain.d.ts.map +1 -0
  27. package/dist/chain.js +64 -0
  28. package/dist/change-set.d.ts +13 -14
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -56
  31. package/dist/change.d.ts +46 -0
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +36 -0
  34. package/dist/chat-types.d.ts +5 -0
  35. package/dist/chat-types.d.ts.map +1 -0
  36. package/dist/chat-types.js +13 -0
  37. package/dist/client.d.ts +56 -18
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +164 -23
  40. package/dist/collection.d.ts +31 -14
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +61 -55
  43. package/dist/compile.d.ts +16 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +711 -0
  46. package/dist/connection.d.ts +8 -103
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +103 -2076
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/context.js +7 -0
  52. package/dist/conversation-live.d.ts +135 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +247 -0
  55. package/dist/conversation-row.d.ts +33 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +53 -0
  58. package/dist/conversation.d.ts +67 -44
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1010 -549
  61. package/dist/declaration.d.ts +10 -0
  62. package/dist/declaration.d.ts.map +1 -0
  63. package/dist/declaration.js +24 -0
  64. package/dist/digest.d.ts +7 -0
  65. package/dist/digest.d.ts.map +1 -0
  66. package/dist/digest.js +113 -0
  67. package/dist/discovery.d.ts +10 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +177 -0
  70. package/dist/durability.d.ts +19 -1
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +5 -0
  73. package/dist/entry.d.ts +20 -0
  74. package/dist/entry.d.ts.map +1 -0
  75. package/dist/entry.js +161 -0
  76. package/dist/expectation.d.ts +23 -0
  77. package/dist/expectation.d.ts.map +1 -0
  78. package/dist/expectation.js +92 -0
  79. package/dist/failure.d.ts +14 -0
  80. package/dist/failure.d.ts.map +1 -0
  81. package/dist/failure.js +22 -0
  82. package/dist/figures.d.ts +49 -0
  83. package/dist/figures.d.ts.map +1 -0
  84. package/dist/figures.js +197 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +7 -122
  88. package/dist/holdings.d.ts +29 -0
  89. package/dist/holdings.d.ts.map +1 -0
  90. package/dist/holdings.js +95 -0
  91. package/dist/host.d.ts +28 -3
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +149 -26
  94. package/dist/identity.d.ts +3 -0
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +13 -1
  97. package/dist/index.d.ts +39 -10
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +16 -0
  100. package/dist/install.d.ts +55 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +543 -0
  103. package/dist/job.d.ts +5 -0
  104. package/dist/job.d.ts.map +1 -0
  105. package/dist/job.js +7 -0
  106. package/dist/lifecycle.d.ts +7 -0
  107. package/dist/lifecycle.d.ts.map +1 -0
  108. package/dist/lifecycle.js +271 -0
  109. package/dist/listing.d.ts +52 -0
  110. package/dist/listing.d.ts.map +1 -0
  111. package/dist/listing.js +168 -0
  112. package/dist/live.d.ts +23 -0
  113. package/dist/live.d.ts.map +1 -0
  114. package/dist/live.js +165 -0
  115. package/dist/locks.d.ts +9 -0
  116. package/dist/locks.d.ts.map +1 -0
  117. package/dist/locks.js +62 -0
  118. package/dist/log.d.ts +1 -0
  119. package/dist/log.d.ts.map +1 -1
  120. package/dist/lost.d.ts +5 -0
  121. package/dist/lost.d.ts.map +1 -0
  122. package/dist/lost.js +61 -0
  123. package/dist/media.d.ts +8 -0
  124. package/dist/media.d.ts.map +1 -0
  125. package/dist/media.js +218 -0
  126. package/dist/memory.d.ts +25 -8
  127. package/dist/memory.d.ts.map +1 -1
  128. package/dist/memory.js +296 -93
  129. package/dist/messages.d.ts +49 -0
  130. package/dist/messages.d.ts.map +1 -0
  131. package/dist/messages.js +148 -0
  132. package/dist/model.d.ts +16 -9
  133. package/dist/model.d.ts.map +1 -1
  134. package/dist/model.js +9 -15
  135. package/dist/models.d.ts +10 -0
  136. package/dist/models.d.ts.map +1 -0
  137. package/dist/models.js +170 -0
  138. package/dist/name.d.ts +4 -0
  139. package/dist/name.d.ts.map +1 -0
  140. package/dist/name.js +122 -0
  141. package/dist/observation.d.ts +22 -4
  142. package/dist/observation.d.ts.map +1 -1
  143. package/dist/observation.js +127 -26
  144. package/dist/open.d.ts +2 -0
  145. package/dist/open.d.ts.map +1 -0
  146. package/dist/open.js +1 -0
  147. package/dist/opened.d.ts +22 -0
  148. package/dist/opened.d.ts.map +1 -0
  149. package/dist/opened.js +107 -0
  150. package/dist/opening.d.ts +4 -0
  151. package/dist/opening.d.ts.map +1 -0
  152. package/dist/opening.js +59 -0
  153. package/dist/outcome.d.ts +75 -5
  154. package/dist/outcome.d.ts.map +1 -1
  155. package/dist/outcome.js +84 -1
  156. package/dist/overlay.d.ts +17 -5
  157. package/dist/overlay.d.ts.map +1 -1
  158. package/dist/overlay.js +168 -190
  159. package/dist/parts.d.ts +11 -0
  160. package/dist/parts.d.ts.map +1 -0
  161. package/dist/parts.js +21 -0
  162. package/dist/paths.d.ts +2 -1
  163. package/dist/paths.d.ts.map +1 -1
  164. package/dist/paths.js +26 -16
  165. package/dist/preparation.d.ts +20 -0
  166. package/dist/preparation.d.ts.map +1 -0
  167. package/dist/preparation.js +233 -0
  168. package/dist/queries.d.ts +16 -0
  169. package/dist/queries.d.ts.map +1 -0
  170. package/dist/queries.js +272 -0
  171. package/dist/query.d.ts +51 -181
  172. package/dist/query.d.ts.map +1 -1
  173. package/dist/query.js +3 -431
  174. package/dist/questions.d.ts +34 -0
  175. package/dist/questions.d.ts.map +1 -0
  176. package/dist/questions.js +122 -0
  177. package/dist/queue.d.ts +32 -0
  178. package/dist/queue.d.ts.map +1 -0
  179. package/dist/queue.js +402 -0
  180. package/dist/reach.d.ts +21 -5
  181. package/dist/reach.d.ts.map +1 -1
  182. package/dist/reach.js +306 -96
  183. package/dist/react.d.ts +43 -19
  184. package/dist/react.d.ts.map +1 -1
  185. package/dist/react.js +22 -21
  186. package/dist/read.d.ts +7 -0
  187. package/dist/read.d.ts.map +1 -0
  188. package/dist/read.js +17 -0
  189. package/dist/readiness.d.ts +49 -0
  190. package/dist/readiness.d.ts.map +1 -0
  191. package/dist/readiness.js +27 -0
  192. package/dist/reads.d.ts +37 -0
  193. package/dist/reads.d.ts.map +1 -0
  194. package/dist/reads.js +174 -0
  195. package/dist/recovery.d.ts +26 -0
  196. package/dist/recovery.d.ts.map +1 -0
  197. package/dist/recovery.js +232 -0
  198. package/dist/refresh.d.ts +20 -7
  199. package/dist/refresh.d.ts.map +1 -1
  200. package/dist/refresh.js +155 -59
  201. package/dist/refusal.d.ts +5 -0
  202. package/dist/refusal.d.ts.map +1 -0
  203. package/dist/refusal.js +57 -0
  204. package/dist/replica.d.ts +53 -33
  205. package/dist/replica.d.ts.map +1 -1
  206. package/dist/replica.js +361 -164
  207. package/dist/room-draft.d.ts +59 -12
  208. package/dist/room-draft.d.ts.map +1 -1
  209. package/dist/room-draft.js +299 -90
  210. package/dist/room-drafts.d.ts +24 -0
  211. package/dist/room-drafts.d.ts.map +1 -0
  212. package/dist/room-drafts.js +217 -0
  213. package/dist/rows.d.ts +32 -34
  214. package/dist/rows.d.ts.map +1 -1
  215. package/dist/rows.js +67 -87
  216. package/dist/runtime.d.ts +32 -0
  217. package/dist/runtime.d.ts.map +1 -0
  218. package/dist/runtime.js +1 -0
  219. package/dist/save.d.ts +74 -5
  220. package/dist/save.d.ts.map +1 -1
  221. package/dist/save.js +914 -188
  222. package/dist/saves.d.ts +32 -0
  223. package/dist/saves.d.ts.map +1 -0
  224. package/dist/saves.js +679 -0
  225. package/dist/search.d.ts +15 -54
  226. package/dist/search.d.ts.map +1 -1
  227. package/dist/search.js +10 -121
  228. package/dist/seed.d.ts +25 -0
  229. package/dist/seed.d.ts.map +1 -0
  230. package/dist/seed.js +145 -0
  231. package/dist/shared.d.ts +10 -0
  232. package/dist/shared.d.ts.map +1 -0
  233. package/dist/shared.js +339 -0
  234. package/dist/shown.d.ts +32 -0
  235. package/dist/shown.d.ts.map +1 -0
  236. package/dist/shown.js +299 -0
  237. package/dist/socket/admission.d.ts +7 -0
  238. package/dist/socket/admission.d.ts.map +1 -0
  239. package/dist/socket/admission.js +39 -0
  240. package/dist/socket/answers.d.ts +6 -0
  241. package/dist/socket/answers.d.ts.map +1 -0
  242. package/dist/socket/answers.js +20 -0
  243. package/dist/socket/lanes.d.ts +20 -0
  244. package/dist/socket/lanes.d.ts.map +1 -0
  245. package/dist/socket/lanes.js +77 -0
  246. package/dist/socket/reads.d.ts +10 -0
  247. package/dist/socket/reads.d.ts.map +1 -0
  248. package/dist/socket/reads.js +31 -0
  249. package/dist/socket/rooms.d.ts +41 -0
  250. package/dist/socket/rooms.d.ts.map +1 -0
  251. package/dist/socket/rooms.js +90 -0
  252. package/dist/socket/session.d.ts +38 -0
  253. package/dist/socket/session.d.ts.map +1 -0
  254. package/dist/socket/session.js +23 -0
  255. package/dist/socket.d.ts +69 -0
  256. package/dist/socket.d.ts.map +1 -0
  257. package/dist/socket.js +175 -0
  258. package/dist/source.d.ts +61 -0
  259. package/dist/source.d.ts.map +1 -0
  260. package/dist/source.js +82 -0
  261. package/dist/status.d.ts +7 -4
  262. package/dist/status.d.ts.map +1 -1
  263. package/dist/status.js +3 -15
  264. package/dist/store/fences.d.ts +16 -0
  265. package/dist/store/fences.d.ts.map +1 -0
  266. package/dist/store/fences.js +26 -0
  267. package/dist/store/installs.d.ts +30 -0
  268. package/dist/store/installs.d.ts.map +1 -0
  269. package/dist/store/installs.js +34 -0
  270. package/dist/store/readiness.d.ts +10 -0
  271. package/dist/store/readiness.d.ts.map +1 -0
  272. package/dist/store/readiness.js +52 -0
  273. package/dist/store/records.d.ts +210 -0
  274. package/dist/store/records.d.ts.map +1 -0
  275. package/dist/store/records.js +428 -0
  276. package/dist/store/room-held.d.ts +8 -0
  277. package/dist/store/room-held.d.ts.map +1 -0
  278. package/dist/store/room-held.js +17 -0
  279. package/dist/store/space.d.ts +11 -0
  280. package/dist/store/space.d.ts.map +1 -0
  281. package/dist/store/space.js +41 -0
  282. package/dist/store/watchers.d.ts +17 -0
  283. package/dist/store/watchers.d.ts.map +1 -0
  284. package/dist/store/watchers.js +56 -0
  285. package/dist/store/writes.d.ts +24 -0
  286. package/dist/store/writes.d.ts.map +1 -0
  287. package/dist/store/writes.js +125 -0
  288. package/dist/store.d.ts +106 -92
  289. package/dist/store.d.ts.map +1 -1
  290. package/dist/store.js +142 -385
  291. package/dist/stored.d.ts +156 -0
  292. package/dist/stored.d.ts.map +1 -0
  293. package/dist/stored.js +649 -0
  294. package/dist/surface.d.ts +88 -0
  295. package/dist/surface.d.ts.map +1 -0
  296. package/dist/surface.js +224 -0
  297. package/dist/sync.d.ts +19 -0
  298. package/dist/sync.d.ts.map +1 -0
  299. package/dist/sync.js +530 -0
  300. package/dist/tables.d.ts +412 -0
  301. package/dist/tables.d.ts.map +1 -0
  302. package/dist/tables.js +737 -0
  303. package/dist/tallies.d.ts +18 -0
  304. package/dist/tallies.d.ts.map +1 -0
  305. package/dist/tallies.js +129 -0
  306. package/dist/transfer.d.ts +0 -5
  307. package/dist/transfer.d.ts.map +1 -1
  308. package/dist/turn.d.ts +9 -0
  309. package/dist/turn.d.ts.map +1 -0
  310. package/dist/turn.js +75 -0
  311. package/dist/validation.d.ts +29 -0
  312. package/dist/validation.d.ts.map +1 -0
  313. package/dist/validation.js +104 -0
  314. package/dist/windows.d.ts +11 -0
  315. package/dist/windows.d.ts.map +1 -0
  316. package/dist/windows.js +16 -0
  317. package/dist/wire.d.ts +189 -37
  318. package/dist/wire.d.ts.map +1 -1
  319. package/dist/wire.js +77 -33
  320. package/package.json +27 -15
  321. package/AGENTS.md +0 -231
  322. package/dist/attachment.d.ts +0 -3
  323. package/dist/attachment.d.ts.map +0 -1
  324. package/dist/attachment.js +0 -8
  325. package/dist/read-side.d.ts +0 -18
  326. package/dist/read-side.d.ts.map +0 -1
  327. package/dist/read-side.js +0 -377
package/AGENTS.md DELETED
@@ -1,231 +0,0 @@
1
- # Instructions for the App Creator's agent
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.
6
-
7
- ## The MD Runtime API
8
-
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
13
- statement and the deployment facts 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, a
17
- Room reached for single Documents shows only those Documents, the Types of the
18
- models that govern them and no attachments, and without conversations the
19
- conversation members, the chat draft and the conversation observation hold none.
20
- A change of the reach reaches every open observation as its new value, a query
21
- keeping every unchanged Document the same object.
22
-
23
- Every `observe` resolves, once its first value has arrived, to a handle:
24
- `current()` is the latest complete value, `subscribe(listener)` hears each later
25
- value whole and returns its unsubscribe, and `close()` ends the observation.
26
- Closing the port ends every handle and rejects every pending call and
27
- observation; a client that reconnects observes again.
28
-
29
- Each conversation the Provider's conversation list names is held complete in the
30
- browser. `conversation.list()` and `observe('conversations')` answer each with its
31
- Agent's identity and name, its name, created and finished times, last outcome and live
32
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
33
- and `started`, when the running turn began, or `null`.
34
- Observe one with `observe('conversation', id, { limit })`: the view
35
- holds 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:
37
- the running `turn` with its message parts and its context in use and window, the
38
- open questions, the process state, and the CLI's commands and options. These live
39
- only in memory: the message accepted under the turn's id replaces the running turn,
40
- and none of them is stored or searchable.
41
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
42
- sending it is a Provider Action that needs the Provider reachable and is never
43
- queued.
44
-
45
- Each Room in Rooms lists its `attachments`, the files the Provider holds for it
46
- that its Documents link by the Provider's reference, ordered by `reference`,
47
- each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
48
- `entry`. They are as the Provider last declared them and hold no bytes;
49
- open one through the Provider Action that serves it.
50
-
51
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
52
- touch the network.
53
- History and Call go to the Provider through the Adapter. A Call result whose
54
- effect the Provider places in a Room carries `at`, that Room and Room Version;
55
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
56
- reached it, and the MD Runtime keeps refreshing that Room until it has;
57
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
58
- that document was written at a later Room Version. Each History revision
59
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
60
- member of the
61
- client is asynchronous. Results are detached snapshots. Nothing in this
62
- surface returns the authorization, performs a request the App's code
63
- composes, or exposes the browser store.
64
-
65
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
66
- opaque value using the host's contract.
67
-
68
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
69
- ships in no bundle.
70
-
71
- ## Local Query rules
72
-
73
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
74
- result and hears it again only when it changes, keeping every unchanged Document
75
- the same object, so a component can tell what changed by identity. A query is
76
- data:
77
-
78
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
79
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
80
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
81
- - **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
82
- `$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
83
- `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
84
- asks whether it contains the value. Missing, null and empty differ:
85
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
86
- text and `$size: 0` an empty list. A date compares in calendar order and never
87
- with a date-time. A reference compares by the Room Path it resolves to.
88
- Untyped frontmatter is plain values. There is no text containment or regular
89
- expression.
90
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
91
- reference `field` points to a matching Document of the same Room.
92
- `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
93
- matching Document of the same Room references. Each keeps a Document once.
94
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
95
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
96
- are `'all'` or a list of names. Room and Path always return; a Markdown
97
- Document also returns its MD Type. A non-Markdown Document or binary link
98
- target returns only Room and Path. An unselected part is absent. Select only
99
- what a screen shows: a list that selects the Markdown hears every edit of it.
100
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
101
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
102
- or `null` for a write the Provider made itself, and `time` is the Provider's
103
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
104
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
105
- saved write takes the Provider's own once it is Accepted and refreshed. A
106
- Room's last change is its Document with the latest `time`.
107
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
108
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
109
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
110
- over every match and ordered by `count` or a key. `limit` bounds the Documents
111
- or the groups.
112
- - **Results and errors.** A result carries no Room Version: read freshness from
113
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
114
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
115
- answers an empty result in its place.
116
-
117
- ## Local Search rules
118
-
119
- `search({ text, documents, conversations, limit })` answers once, by words, from
120
- local state, with MiniSearch at its default configuration. There is no observed
121
- search.
122
-
123
- - **What is found.** A Document by its field values, its sections' headings and
124
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
125
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
126
- word forms, typo tolerance or prefix matching.
127
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
128
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
129
- apply before `limit`, which bounds each list; without it every hit returns.
130
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
131
- hits of one list of one search. A Document hit names its `room`, `path` and
132
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
133
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
134
- `path`, or `text`. A hit carries no position; mark the words in the text you
135
- show. An invalid filter fails with its Local Query error.
136
-
137
- ## Room Draft, Save, and outcome rules
138
-
139
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
140
- tab. It is durable: it survives reload and navigation. A Room that Discovery
141
- stops listing takes its Room Drafts and its queue with it.
142
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
143
- the revision you read, or `null` when there was none, and every part it should
144
- now change: fields, sections and the preamble, or the whole Markdown, a
145
- creation, a move, or a removal. A part new to the Room Draft names its base,
146
- the value you showed when it was opened; the MD Runtime keeps a part's first
147
- base. A binary link target has a Room Draft too, for a move or a removal, with
148
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
149
- the current Room Draft; read it and write again.
150
-
151
- Save takes one Room and the Room Drafts of it to save, each with its revision,
152
- validates locally, and on success appends one Change Batch to that Room's
153
- queue and removes those Room Drafts. It is refused as `stale`, as
154
- `changed-underneath` naming each part whose base no longer matches the visible
155
- state, or by a local validation rule, and then creates nothing and leaves every
156
- Room Draft in place. A directory move or removal is a move or removal part on
157
- each Document and binary link target beneath it, saved together.
158
-
159
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
160
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
161
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
162
- longer applies over the Room each leave the queue and return as Room Drafts on
163
- the Documents they changed, marked with why: the Provider's structured refusal
164
- code and fields as returned, not known to have applied, or withdrawn locally.
165
- The rest of the queue keeps synchronizing, and Sync Status requires attention
166
- until each returned Room Draft is saved again or discarded. A Change Batch
167
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
168
- Pending one, and a returned Room Draft says why it returned. Transport
169
- failure and Provider unavailability keep work Pending and do not infer a
170
- rejection. A refusal the Provider marks retryable stays Pending until the reset
171
- it names; the MD Runtime retries the same Change Batch identity and payload and
172
- never infers an outcome from transport uncertainty. The MD Runtime never
173
- combines, reorders, or rebases.
174
-
175
- `observe('service-mode')` answers the Provider's Service
176
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
177
- its Change Batch waits unsent, and the queue is submitted in order once the
178
- Provider reopens writes. An Action is never held: a write the Provider refuses
179
- for the halt returns that refusal to its caller. Show the Provider as read-only
180
- instead of retrying.
181
-
182
- ## The neutrality rule
183
-
184
- No module outside an Adapter package imports, names, or special-cases a
185
- Provider. MD UI and every App reach data only through the client entry.
186
-
187
- ## Content-safety rules
188
-
189
- The Provider authorization belongs to the Runtime host and is never readable
190
- by the App's code. The App's code reaches the network only at the external
191
- origins its manifest declares, empty by default, and the Provider enforces
192
- that set. Every request to the Provider itself goes through the MD Runtime.
193
- Rendered Markdown never executes scripts, renders raw HTML only for the
194
- details and summary elements, and loads images and other resources only from
195
- origins the Provider's policy allows.
196
-
197
- ## Launch promises MD UI keeps
198
-
199
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
200
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
201
- a desktop. Its strings are English only, dates and numbers follow the
202
- browser locale, and content is never translated. Light and dark themes come
203
- from CSS custom properties with the browser's preference as the default and
204
- an App's override respected. What an App Creator's agent adds carries none
205
- of these promises by itself. Reading, querying and searching never wait for
206
- the network. Data lives only in the App Creator's browser and with the Provider.
207
-
208
- ## App code takes the client its host hands it and never constructs a Runtime
209
-
210
- App code takes the client its host hands it: in House,
211
- `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
212
- client House built into the page. It never constructs a Runtime or a client.
213
- It imports only types from `@agentshouse/mdruntime/client`, does not call
214
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
215
- the host entry, or the Adapter package. Hosts and tests use those entries; the
216
- served App does not.
217
-
218
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
219
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
220
- the arguments of `observe` and returns the topic's current value, `undefined`
221
- until it arrives, re-rendering on each change; a `null` client observes
222
- nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
223
- `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
224
- already there, keeping the bases its parts have, or onto a new one, and saves
225
- them together. A refused Save leaves the Room Drafts for the App to save again
226
- or discard; a failure is recorded and rejects.
227
-
228
- ## What an agent must never do
229
-
230
- An agent must never read the authorization, load code from a Room, call the
231
- Provider directly, or rebase a refused Change Batch.
@@ -1,3 +0,0 @@
1
- import type { RoomAttachment } from './adapter.js';
2
- export declare function declaredAttachments(pages: readonly (readonly RoomAttachment[])[]): readonly RoomAttachment[];
3
- //# sourceMappingURL=attachment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../src/attachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,CAAC,SAAS,cAAc,EAAE,CAAC,EAAE,GAC5C,SAAS,cAAc,EAAE,CAQ3B"}
@@ -1,8 +0,0 @@
1
- export function declaredAttachments(pages) {
2
- const byReference = new Map();
3
- for (const page of pages) {
4
- for (const attachment of page)
5
- byReference.set(attachment.reference, attachment);
6
- }
7
- return [...byReference.values()].sort((left, right) => left.reference < right.reference ? -1 : left.reference > right.reference ? 1 : 0);
8
- }
@@ -1,18 +0,0 @@
1
- import type { ChangeSet } from './change-set.js';
2
- import { type KeyedResult, type QueryChange } from './observation.js';
3
- import type { Plan, QueryResult } from './query.js';
4
- import type { SearchedDocument } from './search.js';
5
- export type ReadSide = {
6
- apply(set: ChangeSet): void;
7
- query(plan: Plan): Promise<QueryResult>;
8
- watch(plan: Plan, identity: string, deliver: (message: KeyedResult | QueryChange) => void): () => void;
9
- documents(): readonly SearchedDocument[];
10
- document(room: string, path: string): SearchedDocument | null;
11
- close(): void;
12
- };
13
- export declare function reconciled(previous: KeyedResult, next: KeyedResult): {
14
- keyed: KeyedResult;
15
- change: QueryChange;
16
- } | null;
17
- export declare function createReadSide(): ReadSide;
18
- //# sourceMappingURL=read-side.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC3F,OAAO,KAAK,EAOV,IAAI,EAIJ,WAAW,EAIZ,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAqDpD,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CACH,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,KAAK,IAAI,GACpD,MAAM,IAAI,CAAC;IACd,SAAS,IAAI,SAAS,gBAAgB,EAAE,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC9D,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AA8RF,wBAAgB,UAAU,CACxB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,WAAW,GAChB;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,CA4BpD;AAED,wBAAgB,cAAc,IAAI,QAAQ,CA4HzC"}
package/dist/read-side.js DELETED
@@ -1,377 +0,0 @@
1
- import { and, BasicIndex, configureIndexDevMode, count, createCollection, createLiveQueryCollection, deepEquals, eq, gt, gte, inArray, isNull, isUndefined, lt, lte, not, or, toArray, } from '@tanstack/db';
2
- import { rowsOf } from './observation.js';
3
- import { documentKey } from './rows.js';
4
- function every(expressions) {
5
- const [first, second, ...rest] = expressions;
6
- return second === undefined ? first : and(first, second, ...rest);
7
- }
8
- function some(expressions) {
9
- const [first, second, ...rest] = expressions;
10
- return second === undefined ? first : or(first, second, ...rest);
11
- }
12
- function equal(field, value) {
13
- return or(eq(field, value), inArray(value, field));
14
- }
15
- function tested(test, field, size, written) {
16
- if (test.op === 'eq')
17
- return test.value === null ? isNull(field) : equal(field, test.value);
18
- if (test.op === 'ne') {
19
- return test.value === null
20
- ? not(isNull(field))
21
- : or(isUndefined(field), isNull(field), not(equal(field, test.value)));
22
- }
23
- if (test.op === 'in' || test.op === 'nin') {
24
- const matches = test.values.length === 0
25
- ? inArray(field, [])
26
- : some(test.values.map((value) => (value === null ? isNull(field) : equal(field, value))));
27
- if (test.op === 'in')
28
- return matches;
29
- return some([
30
- isUndefined(field),
31
- ...(test.values.includes(null) ? [] : [isNull(field)]),
32
- not(matches),
33
- ]);
34
- }
35
- if (test.op === 'range') {
36
- const compare = { gt, gte, lt, lte };
37
- return every(test.bounds.map(([operator, bound]) => compare[operator](field, bound)));
38
- }
39
- if (test.op === 'all') {
40
- return every([not(isUndefined(size)), ...test.values.map((value) => inArray(value, field))]);
41
- }
42
- if (test.op === 'size')
43
- return eq(size, test.size);
44
- return test.exists ? not(isUndefined(written)) : isUndefined(written);
45
- }
46
- function conditioned(condition, row) {
47
- if ('every' in condition)
48
- return every(condition.every.map((item) => conditioned(item, row)));
49
- if ('some' in condition)
50
- return some(condition.some.map((item) => conditioned(item, row)));
51
- return tested(condition.test, row.values[condition.field], row.sizes[condition.field], row.fields[condition.field]);
52
- }
53
- function reached(reach, room, document) {
54
- return reach === null
55
- ? []
56
- : [or(inArray(room, [...reach.rooms]), inArray(document, [...reach.documents]))];
57
- }
58
- function scoped(scope, row, rooms, reach) {
59
- return every([
60
- eq(row.kind, 'document'),
61
- ...(rooms === null ? [] : [inArray(row.room, [...rooms])]),
62
- ...reached(reach, row.room, row.key),
63
- ...(scope.types === null ? [] : [inArray(row.type, [...scope.types])]),
64
- ...(scope.pathPrefix === null ? [] : [inArray(scope.pathPrefix, row.directories)]),
65
- ...(scope.where === null ? [] : [conditioned(scope.where, row)]),
66
- ]);
67
- }
68
- function keyed(key, row) {
69
- return key.of === 'field' ? row.values[key.field] : row[key.of];
70
- }
71
- function live(query) {
72
- return createLiveQueryCollection({
73
- query: query,
74
- startSync: true,
75
- });
76
- }
77
- function related(q, rows, scope, field, kept, reach) {
78
- const matched = kept === 'source' ? 'target' : 'source';
79
- const from = q.from({ r: rows });
80
- return from
81
- .where(({ r }) => every([eq(r.kind, 'reference'), ...(field === null ? [] : [eq(r.field, field)])]))
82
- .innerJoin({ m: rows }, ({ r, m }) => eq(r[matched], m.key))
83
- .where(({ m }) => scoped(scope, m, null, reach))
84
- .groupBy(({ r }) => r[kept])
85
- .select(({ r }) => ({ key: r[kept] }));
86
- }
87
- function filtered(q, rows, plan) {
88
- const from = q.from({ d: rows });
89
- let query = from.where(({ d }) => scoped(plan.root, d, plan.rooms, plan.reach));
90
- if (plan.hop !== null) {
91
- const hop = related(q, rows, plan.hop, plan.hop.field, 'source', plan.reach);
92
- query = query.innerJoin({ h: hop }, ({ d, h }) => eq(d.key, h.key));
93
- }
94
- if (plan.backlinks !== null) {
95
- const backlinks = related(q, rows, plan.backlinks, plan.backlinks.field, 'target', plan.reach);
96
- query = query.innerJoin({ k: backlinks }, ({ d, k }) => eq(d.key, k.key));
97
- }
98
- return query;
99
- }
100
- function named(prefix, names, source) {
101
- return Object.fromEntries(names.map((name, index) => [`${prefix}${index}`, source[name]]));
102
- }
103
- function documents(q, rows, plan, shape) {
104
- let query = filtered(q, rows, plan);
105
- if (shape.sections !== null || shape.preamble || shape.markdown) {
106
- query = query.leftJoin({ b: rows }, ({ d, b }) => eq(d.body, b.key));
107
- }
108
- for (const { key, options } of shape.orderBy) {
109
- query = query.orderBy(({ d }) => keyed(key, d), options);
110
- }
111
- if (shape.orderBy.length === 0 && plan.limit !== null) {
112
- query = query.orderBy(({ d }) => d.key, { stringSort: 'lexical' });
113
- }
114
- if (plan.limit !== null)
115
- query = query.limit(plan.limit);
116
- return query.select(({ d, b }) => ({
117
- room: d.room,
118
- path: d.path,
119
- type: d.type,
120
- ...(shape.fields === 'all' ? { fields: d.fields } : {}),
121
- ...(Array.isArray(shape.fields) ? named('field', shape.fields, d.fields) : {}),
122
- ...(shape.sections === 'all' ? { sections: b.sections } : {}),
123
- ...(Array.isArray(shape.sections) ? named('section', shape.sections, b.sections) : {}),
124
- ...(shape.preamble ? { preamble: b.preamble } : {}),
125
- ...(shape.markdown ? { markdown: b.markdown } : {}),
126
- ...(shape.backlinks ? { backlinks: toArray(backlinked(q, rows, d, plan.reach)) } : {}),
127
- ...(shape.change ? { change: d.change } : {}),
128
- }));
129
- }
130
- function backlinked(q, rows, document, reach) {
131
- const from = q.from({ r: rows });
132
- return from
133
- .where(({ r }) => every([eq(r.target, document.key), ...reached(reach, r.room, r.source)]))
134
- .orderBy(({ r }) => r.path, { stringSort: 'lexical' })
135
- .orderBy(({ r }) => r.field, { stringSort: 'lexical' })
136
- .select(({ r }) => ({ path: r.path, type: r.type, field: r.field }));
137
- }
138
- function groups(q, stage, shape, limit) {
139
- const keys = shape.groupBy.map((_, index) => `key${index}`);
140
- const from = q.from({ m: stage });
141
- let query = from.groupBy(({ m }) => keys.map((key) => m[key]));
142
- for (const { by, direction } of shape.orderBy) {
143
- query = query.orderBy(({ m }) => (by === 'count' ? count(m.key) : m[keys[by]]), direction);
144
- }
145
- if (limit !== null && shape.orderBy.length > 0)
146
- query = query.limit(limit);
147
- return query.select(({ m }) => ({
148
- ...Object.fromEntries(keys.map((key) => [key, m[key]])),
149
- count: count(m.key),
150
- }));
151
- }
152
- function built(rows, plan) {
153
- const shape = plan.shape;
154
- if (shape.kind === 'documents') {
155
- const collection = live((q) => documents(q, rows, plan, shape));
156
- return { live: collection, dispose: () => void collection.cleanup() };
157
- }
158
- const stage = live((q) => filtered(q, rows, plan).select(({ d }) => ({
159
- key: d.key,
160
- ...Object.fromEntries(shape.groupBy.map((key, index) => [`key${index}`, keyed(key, d)])),
161
- })));
162
- const collection = live((q) => groups(q, stage, shape, plan.limit));
163
- return {
164
- live: collection,
165
- dispose: () => {
166
- void collection.cleanup();
167
- void stage.cleanup();
168
- },
169
- };
170
- }
171
- function present(entries) {
172
- return Object.fromEntries(entries.filter(([, value]) => value !== undefined));
173
- }
174
- function part(row, prefix, names, whole) {
175
- if (names === 'all')
176
- return whole;
177
- return present(names.map((name, index) => [name, row[`${prefix}${index}`]]));
178
- }
179
- function documentOf(row, shape) {
180
- if (row.type === null)
181
- return { room: row.room, path: row.path };
182
- return {
183
- room: row.room,
184
- path: row.path,
185
- type: row.type,
186
- ...(shape.fields === null
187
- ? {}
188
- : { fields: part(row, 'field', shape.fields, row.fields) }),
189
- ...(shape.sections === null
190
- ? {}
191
- : {
192
- sections: part(row, 'section', shape.sections, row.sections),
193
- }),
194
- ...(shape.preamble ? { preamble: row.preamble } : {}),
195
- ...(shape.markdown ? { markdown: row.markdown } : {}),
196
- ...(shape.backlinks
197
- ? {
198
- backlinks: row.backlinks.map(({ path, type, field }) => ({ path, type, field })),
199
- }
200
- : {}),
201
- ...(shape.change ? { change: row.change } : {}),
202
- };
203
- }
204
- function keyedOf(plan, entries) {
205
- const shape = plan.shape;
206
- if (shape.kind === 'documents') {
207
- return {
208
- result: structuredClone({ documents: entries.map(([, row]) => documentOf(row, shape)) }),
209
- keys: entries.map(([key]) => key),
210
- };
211
- }
212
- const bounded = shape.orderBy.length === 0 && plan.limit !== null ? entries.slice(0, plan.limit) : entries;
213
- return {
214
- result: structuredClone({
215
- groups: bounded.map(([, row]) => ({
216
- key: shape.groupBy.map((_, index) => row[`key${index}`]),
217
- count: row.count,
218
- })),
219
- }),
220
- keys: bounded.map(([key]) => key),
221
- };
222
- }
223
- export function reconciled(previous, next) {
224
- const before = rowsOf(previous.result);
225
- const held = new Map(previous.keys.map((key, index) => [key, before[index]]));
226
- const changed = [];
227
- const rows = rowsOf(next.result).map((row, index) => {
228
- const key = next.keys[index];
229
- const kept = held.get(key);
230
- if (kept !== undefined && deepEquals(kept, row))
231
- return kept;
232
- changed.push([key, row]);
233
- return row;
234
- });
235
- const present = new Set(next.keys);
236
- const survivors = previous.keys.filter((key) => present.has(key));
237
- const removed = previous.keys.filter((key) => !present.has(key));
238
- const moved = survivors.length !== next.keys.length ||
239
- survivors.some((key, index) => key !== next.keys[index]);
240
- if (changed.length === 0 && removed.length === 0 && !moved)
241
- return null;
242
- return {
243
- keyed: {
244
- result: 'groups' in next.result
245
- ? { groups: rows }
246
- : { documents: rows },
247
- keys: next.keys,
248
- },
249
- change: { changed, removed, order: moved ? next.keys : null },
250
- };
251
- }
252
- export function createReadSide() {
253
- configureIndexDevMode({ enabled: false });
254
- let sync;
255
- const rows = createCollection({
256
- getKey: (row) => row.key,
257
- gcTime: 0,
258
- startSync: true,
259
- autoIndex: 'eager',
260
- defaultIndexType: BasicIndex,
261
- sync: {
262
- rowUpdateMode: 'full',
263
- sync: (params) => {
264
- sync = params;
265
- params.markReady();
266
- },
267
- },
268
- });
269
- const shared = new Map();
270
- function searched(row) {
271
- const body = rows.get(row.body);
272
- return {
273
- room: row.room,
274
- path: row.path,
275
- type: row.type,
276
- fields: row.fields,
277
- preamble: body.preamble,
278
- sections: body.sections,
279
- };
280
- }
281
- function publish(entry) {
282
- const next = reconciled(entry.result, keyedOf(entry.plan, [...entry.built.live.entries()]));
283
- if (next === null)
284
- return;
285
- entry.result = next.keyed;
286
- for (const listener of entry.listeners)
287
- listener(next.change);
288
- }
289
- return {
290
- apply(set) {
291
- const next = new Map();
292
- for (const change of set.documents) {
293
- for (const row of change.before)
294
- next.set(row.key, null);
295
- for (const row of change.after)
296
- next.set(row.key, row);
297
- }
298
- if (next.size === 0)
299
- return;
300
- sync.begin();
301
- for (const [key, row] of next) {
302
- if (row === null) {
303
- if (rows.has(key))
304
- sync.write({ type: 'delete', key });
305
- continue;
306
- }
307
- sync.write({ type: rows.has(key) ? 'update' : 'insert', value: row });
308
- }
309
- sync.commit();
310
- },
311
- async query(plan) {
312
- const { live: collection, dispose } = built(rows, plan);
313
- try {
314
- await collection.toArrayWhenReady();
315
- return keyedOf(plan, [...collection.entries()]).result;
316
- }
317
- finally {
318
- dispose();
319
- }
320
- },
321
- watch(plan, identity, deliver) {
322
- let entry = shared.get(identity);
323
- if (entry === undefined) {
324
- const created = {
325
- plan,
326
- built: built(rows, plan),
327
- result: undefined,
328
- listeners: new Set(),
329
- subscription: null,
330
- };
331
- created.built.live.on('status:change', ({ status }) => {
332
- if (status === 'cleaned-up' && created.listeners.size === 0)
333
- shared.delete(identity);
334
- });
335
- shared.set(identity, created);
336
- entry = created;
337
- }
338
- const observed = entry;
339
- observed.listeners.add(deliver);
340
- observed.built.live.onFirstReady(() => {
341
- if (!observed.listeners.has(deliver))
342
- return;
343
- if (observed.subscription === null) {
344
- observed.result = keyedOf(observed.plan, [...observed.built.live.entries()]);
345
- observed.subscription = observed.built.live.subscribeChanges(() => {
346
- publish(observed);
347
- }, { includeInitialState: false });
348
- }
349
- deliver(observed.result);
350
- });
351
- return () => {
352
- if (!observed.listeners.delete(deliver) || observed.listeners.size > 0)
353
- return;
354
- observed.subscription?.unsubscribe();
355
- observed.subscription = null;
356
- };
357
- },
358
- documents() {
359
- return rows.toArray
360
- .filter((row) => row.kind === 'document' && row.type !== null)
361
- .map(searched);
362
- },
363
- document(room, path) {
364
- const row = rows.get(documentKey(room, path));
365
- return row === undefined || row.type === null ? null : searched(row);
366
- },
367
- close() {
368
- for (const entry of shared.values()) {
369
- entry.listeners.clear();
370
- entry.subscription?.unsubscribe();
371
- entry.built.dispose();
372
- }
373
- shared.clear();
374
- void rows.cleanup();
375
- },
376
- };
377
- }