@agentshouse/mdruntime-adapter 0.1.0-cd028205a5103 → 0.1.0-cd0511bd2d033

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 (72) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +4 -5
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +13 -322
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +285 -205
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +25 -14
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +104 -51
  17. package/dist/history.d.ts +12 -0
  18. package/dist/history.d.ts.map +1 -0
  19. package/dist/history.js +92 -0
  20. package/dist/house-model.d.ts +719 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +393 -0
  23. package/dist/index.d.ts +11 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +10 -0
  26. package/dist/model.d.ts +6 -3
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +15 -30
  29. package/dist/part.d.ts +14 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +90 -0
  32. package/dist/read.d.ts +59 -41
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +254 -231
  35. package/dist/refusal.d.ts +2 -8
  36. package/dist/refusal.d.ts.map +1 -1
  37. package/dist/refusal.js +6 -14
  38. package/dist/room-stream.d.ts +19 -0
  39. package/dist/room-stream.d.ts.map +1 -0
  40. package/dist/room-stream.js +57 -0
  41. package/dist/room-types.d.ts +7 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +125 -0
  44. package/dist/search.d.ts +5 -0
  45. package/dist/search.d.ts.map +1 -0
  46. package/dist/search.js +47 -0
  47. package/dist/site.d.ts +1 -1
  48. package/dist/site.d.ts.map +1 -1
  49. package/dist/site.js +130 -106
  50. package/dist/stream.d.ts +12 -12
  51. package/dist/stream.d.ts.map +1 -1
  52. package/dist/stream.js +204 -151
  53. package/dist/transport.d.ts +92 -24
  54. package/dist/transport.d.ts.map +1 -1
  55. package/dist/transport.js +55 -9
  56. package/dist/upload.d.ts +12 -0
  57. package/dist/upload.d.ts.map +1 -0
  58. package/dist/upload.js +63 -0
  59. package/dist/version.d.ts +1 -0
  60. package/dist/version.d.ts.map +1 -1
  61. package/dist/version.js +1 -1
  62. package/dist/write.d.ts +20 -10
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +162 -54
  65. package/package.json +9 -6
  66. package/AGENTS.md +0 -244
  67. package/dist/gather.d.ts +0 -3
  68. package/dist/gather.d.ts.map +0 -1
  69. package/dist/gather.js +0 -40
  70. package/dist/links.d.ts +0 -20
  71. package/dist/links.d.ts.map +0 -1
  72. package/dist/links.js +0 -104
package/dist/write.js CHANGED
@@ -1,4 +1,5 @@
1
- import { parseOriginals } from './read.js';
1
+ import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
2
3
  import { sha256Hex, textBytes } from './digest.js';
3
4
  import { nativePath, roomLocalPath } from './map.js';
4
5
  import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
@@ -73,6 +74,25 @@ function operationOf(batch, change, handle) {
73
74
  const operation = created(change, path);
74
75
  return operation === null ? { rule: 'type-missing' } : { operation };
75
76
  }
77
+ if (change.kind === 'binary') {
78
+ const written = {
79
+ op: 'upload',
80
+ path,
81
+ local_id: change.localId,
82
+ bytes: change.byteLength,
83
+ sha256: change.sha256,
84
+ media_type: change.mediaType,
85
+ };
86
+ const from = departure(batch.changes, batch.changes.indexOf(change));
87
+ if (from === change.path && priorAbsence(batch, change.path) !== undefined)
88
+ return { operation: written };
89
+ const replaced = priorExistence(batch, from);
90
+ if (replaced === undefined)
91
+ return { rule: 'precondition-missing' };
92
+ if (!('base' in replaced))
93
+ return { rule: 'presence-base-unrepresentable' };
94
+ return { operation: { ...written, base: replaced.base } };
95
+ }
76
96
  const existence = priorExistence(batch, change.path);
77
97
  if (existence === undefined)
78
98
  return { rule: 'precondition-missing' };
@@ -100,16 +120,36 @@ export function houseChanges(batch, handle) {
100
120
  }
101
121
  return { kind: 'changes', changes };
102
122
  }
103
- export function operationHead(batch) {
123
+ export function houseParts(saved, handle) {
124
+ return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
125
+ }
126
+ export function houseMove(batch, source, destination) {
127
+ const changes = [];
128
+ for (const { path, to } of batch.between?.moves ?? []) {
129
+ const existence = priorExistence(batch, path);
130
+ if (existence === undefined)
131
+ return { kind: 'unmapped', path, rule: 'precondition-missing' };
132
+ if (!('base' in existence)) {
133
+ return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
134
+ }
135
+ changes.push({
136
+ op: 'rename',
137
+ path: nativePath(path, source),
138
+ to: nativePath(to, destination),
139
+ base: existence.base,
140
+ });
141
+ }
142
+ return { kind: 'changes', changes };
143
+ }
144
+ export function operationHead(batch, room) {
104
145
  const writer = batch.writtenBy;
105
- return writer === undefined
106
- ? { operation_id: batch.id }
107
- : { operation_id: batch.id, app_ref: writer.app, release: writer.release };
146
+ const head = { operation_id: batch.id, room_ref: room };
147
+ return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
108
148
  }
109
149
  export function batchPaths(changes) {
110
150
  return [
111
151
  ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
112
- ].sort();
152
+ ];
113
153
  }
114
154
  export function deltaBody(changes) {
115
155
  return JSON.stringify({ changes });
@@ -124,20 +164,29 @@ export function uploadable(inline, bytes, bounds) {
124
164
  export function deltaDigest(delta) {
125
165
  return sha256Hex(delta);
126
166
  }
127
- function material(value, handle) {
167
+ function* material(value, handle, within = () => true) {
128
168
  if (!Array.isArray(value))
129
169
  return null;
130
170
  const held = [];
131
171
  for (const entry of value) {
172
+ yield ROW_WEIGHT;
132
173
  if (typeof entry !== 'object' || entry === null)
133
174
  return null;
134
175
  const file = entry;
135
176
  if (typeof file.path !== 'string')
136
177
  return null;
178
+ if (!within(file.path))
179
+ continue;
137
180
  if (file.content !== null && typeof file.content !== 'string')
138
181
  return null;
139
182
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
140
183
  return null;
184
+ const binary = binaryFileOf(file);
185
+ if (binary === null)
186
+ return null;
187
+ const head = headChange(file);
188
+ if (head === null)
189
+ return null;
141
190
  let path;
142
191
  try {
143
192
  path = roomLocalPath(file.path, handle);
@@ -149,29 +198,79 @@ function material(value, handle) {
149
198
  path,
150
199
  content: file.content,
151
200
  revision: typeof file.revision === 'string' ? file.revision : null,
201
+ ...(binary === undefined ? {} : { binary }),
202
+ ...(head === undefined ? {} : { head }),
152
203
  });
153
204
  }
154
205
  return held;
155
206
  }
156
- function affectedOf(held) {
207
+ function* affectedOf(held) {
157
208
  const affected = {};
158
209
  for (const entry of held) {
159
210
  if (entry.content !== null)
160
211
  affected[entry.path] = entry.content;
212
+ yield ROW_WEIGHT;
161
213
  }
162
214
  return affected;
163
215
  }
164
- export function mutationOutcome(status, body, locator, handle) {
216
+ function* acceptedOf(at, contents) {
217
+ const answer = answering();
218
+ for (const entry of contents) {
219
+ yield ROW_WEIGHT + (entry.content?.length ?? 0);
220
+ if (entry.revision === null) {
221
+ answer.removals.add(entry.path);
222
+ continue;
223
+ }
224
+ if (entry.content !== null)
225
+ answer.documents.set(entry.path, entry.content);
226
+ if (entry.binary !== undefined)
227
+ answer.binaryFiles.set(entry.path, entry.binary);
228
+ revised(answer, entry.path, entry.revision);
229
+ if (entry.head !== undefined)
230
+ answer.changes.set(entry.path, entry.head);
231
+ }
232
+ const unbinaried = answer.binaryFiles.size === 0;
233
+ const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
234
+ return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
235
+ }
236
+ function* movedOutcome(held, move) {
237
+ const authorities = Array.isArray(held.authorities) ? held.authorities : [];
238
+ const at = (authority) => {
239
+ const entry = authorities.find((one) => typeof one === 'object' &&
240
+ one !== null &&
241
+ one.authority === authority);
242
+ return entry === undefined ? null : readPosition(entry);
243
+ };
244
+ const left = at(move.source.authority);
245
+ const arrived = at(move.destination.authority);
246
+ if (left === null || arrived === null)
247
+ return { kind: 'transport-uncertainty' };
248
+ const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
249
+ const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
250
+ const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
251
+ if (leaving === null || arriving === null)
252
+ return { kind: 'transport-uncertainty' };
253
+ return {
254
+ kind: 'accepted',
255
+ ...(yield* acceptedOf(left, leaving)),
256
+ destination: yield* acceptedOf(arrived, arriving),
257
+ };
258
+ }
259
+ export function* mutationOutcome(status, body, locator, handle, move) {
165
260
  const refusal = doorRefusal(body);
166
261
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
167
262
  return { kind: 'write-halted' };
168
263
  }
169
- if (refusal !== null && refusal.code === 'expired')
170
- return { kind: 'expired' };
171
264
  if (refusal !== null && refusal.code === 'edit_conflict') {
172
265
  const { current, ...fields } = refusal.fields;
173
- const held = material(current, handle) ?? [];
174
- return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
266
+ const held = (yield* material(current, handle)) ?? [];
267
+ return {
268
+ kind: 'conflicted',
269
+ affected: yield* affectedOf(held),
270
+ code: refusal.code,
271
+ fields,
272
+ retryable: refusal.retryable,
273
+ };
175
274
  }
176
275
  if (refusal !== null && status === 404) {
177
276
  return scopedRefusal(locator, 'undisclosed', refusal);
@@ -181,47 +280,41 @@ export function mutationOutcome(status, body, locator, handle) {
181
280
  if (refusal?.retryable === true &&
182
281
  typeof reset === 'string' &&
183
282
  classified?.kind === 'transport-uncertainty') {
184
- return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
283
+ return {
284
+ kind: 'retryable-refusal',
285
+ code: refusal.code,
286
+ fields: refusal.fields,
287
+ retryable: true,
288
+ reset,
289
+ };
185
290
  }
186
291
  if (classified !== null && classified.kind !== 'scoped-refusal')
187
292
  return classified;
188
- if (classified !== null && status === 403)
293
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
189
294
  return classified;
295
+ }
190
296
  if (refusal !== null && status >= 400) {
191
- return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
297
+ return {
298
+ kind: 'rejected',
299
+ affected: {},
300
+ code: refusal.code,
301
+ fields: refusal.fields,
302
+ retryable: refusal.retryable,
303
+ };
192
304
  }
193
305
  if (status !== 200 || typeof body !== 'object' || body === null) {
194
306
  return { kind: 'transport-uncertainty' };
195
307
  }
196
308
  const held = body;
309
+ if (move !== undefined)
310
+ return yield* movedOutcome(held, move);
197
311
  const at = readPosition(held);
198
312
  if (at === null)
199
313
  return { kind: 'transport-uncertainty' };
200
- const contents = material(held.contents, handle);
314
+ const contents = yield* material(held.contents, handle);
201
315
  if (contents === null)
202
316
  return { kind: 'transport-uncertainty' };
203
- const originals = parseOriginals(held.originals);
204
- if (originals === null)
205
- return { kind: 'transport-uncertainty' };
206
- const documents = {};
207
- const revisions = {};
208
- const removals = [];
209
- for (const entry of contents) {
210
- if (entry.content === null || entry.revision === null) {
211
- removals.push(entry.path);
212
- continue;
213
- }
214
- documents[entry.path] = entry.content;
215
- revisions[entry.path] = entry.revision;
216
- }
217
- return {
218
- kind: 'accepted',
219
- roomVersion: roomVersion(at),
220
- documents,
221
- revisions,
222
- removals: removals.sort(),
223
- originals,
224
- };
317
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
225
318
  }
226
319
  export function rejectedMapping(mapping) {
227
320
  return {
@@ -229,6 +322,7 @@ export function rejectedMapping(mapping) {
229
322
  affected: {},
230
323
  code: mapping.rule,
231
324
  fields: { path: mapping.path },
325
+ retryable: false,
232
326
  };
233
327
  }
234
328
  export function revisionBody(input) {
@@ -240,13 +334,26 @@ export function revisionBody(input) {
240
334
  }
241
335
  function revisionAuthor(entry) {
242
336
  const user = entry.author_user;
337
+ const userName = entry.author_user_name;
243
338
  const site = entry.author_site;
244
- const name = entry.author_site_name;
245
- if (typeof user === 'string' && site === undefined && name === undefined) {
246
- return { kind: 'user', id: user };
339
+ const siteName = entry.author_site_name;
340
+ const inbox = entry.author_inbox;
341
+ const inboxName = entry.author_inbox_name;
342
+ const app = entry.author_app;
343
+ const appName = entry.author_app_name;
344
+ const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
345
+ if (typeof user === 'string' && typeof userName === 'string' && named.length === 0)
346
+ return { kind: 'user', id: user, name: userName };
347
+ if (user !== null || userName !== undefined || named.length !== 2)
348
+ return null;
349
+ if (typeof site === 'string' && typeof siteName === 'string') {
350
+ return { kind: 'site', id: site, name: siteName };
351
+ }
352
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
353
+ return { kind: 'inbox', id: inbox, name: inboxName };
247
354
  }
248
- if (user === null && typeof site === 'string' && typeof name === 'string') {
249
- return { kind: 'site', id: site, name };
355
+ if (typeof app === 'string' && typeof appName === 'string') {
356
+ return { kind: 'app', id: app, name: appName };
250
357
  }
251
358
  return null;
252
359
  }
@@ -270,15 +377,8 @@ export function historyOutcome(status, body, locator, request) {
270
377
  const named = entries[0];
271
378
  if (named === undefined)
272
379
  return { kind: 'no-history' };
273
- if (named.unavailable === true) {
274
- return {
275
- kind: 'scoped-refusal',
276
- locator,
277
- scope: 'content',
278
- code: 'retained_history_unavailable',
279
- fields: { path: request.path, revision: request.revision },
280
- };
281
- }
380
+ if (typeof named.media_type === 'string')
381
+ return { kind: 'no-history' };
282
382
  if (typeof named.content !== 'string')
283
383
  return { kind: 'transport-uncertainty' };
284
384
  return { kind: 'revision', content: named.content };
@@ -293,7 +393,15 @@ export function historyOutcome(status, body, locator, request) {
293
393
  typeof entry.created_at !== 'string') {
294
394
  return { kind: 'transport-uncertainty' };
295
395
  }
296
- revisions.push({ revision: entry.revision, author, time: entry.created_at });
396
+ const binaryFile = binaryFileOf(entry);
397
+ if (binaryFile === null)
398
+ return { kind: 'transport-uncertainty' };
399
+ revisions.push({
400
+ revision: entry.revision,
401
+ author,
402
+ time: entry.created_at,
403
+ ...(binaryFile === undefined ? {} : { binaryFile }),
404
+ });
297
405
  }
298
406
  const next = held.next_before;
299
407
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-cd028205a5103",
3
+ "version": "0.1.0-cd0511bd2d033",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,23 +9,26 @@
9
9
  "access": "public"
10
10
  },
11
11
  "engines": {
12
- "node": ">=24.21.0"
12
+ "node": ">=24.22.1"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
17
+ "default": "./dist/index.js"
18
18
  },
19
19
  "./package.json": "./package.json"
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
- "AGENTS.md",
24
23
  "README.md",
25
24
  "LICENSE"
26
25
  ],
27
26
  "dependencies": {
28
- "@agentshouse/mdmodel": "0.1.0-c3d58cb8652e6",
29
- "@agentshouse/mdruntime": "0.1.0-ca1eff92bbe73"
27
+ "@agentshouse/mdruntime": "0.1.0-cac707d698ca2"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/agentshouse/core.git",
32
+ "directory": "mdruntime/packages/mdruntime-adapter"
30
33
  }
31
34
  }
package/AGENTS.md DELETED
@@ -1,244 +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,
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. A Call result whose
55
- effect the Provider places in a Room carries `at`, that Room and Room Version;
56
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
57
- reached it, and the MD Runtime keeps refreshing that Room until it has;
58
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
59
- that document was written at a later Room Version. Each History revision
60
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
61
- History of a Path no current document holds answers the removed document's
62
- revisions with `deleted: true`, newest first; that revision is what a link to
63
- the Path opens. Every
64
- member of the
65
- client is asynchronous. Results are detached snapshots. Nothing in this
66
- surface returns the authorization, performs a request the App's code
67
- composes, or exposes the browser store.
68
-
69
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
70
- opaque value using the host's contract.
71
-
72
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
73
- ships in no bundle.
74
-
75
- ## Local Query rules
76
-
77
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
78
- result and hears it again only when it changes, keeping every unchanged Document
79
- the same object, so a component can tell what changed by identity. A query is
80
- data:
81
-
82
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
83
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
84
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
85
- - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
86
- `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
87
- meets a list applies to every item and a number names one item. `where` names
88
- pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
89
- when any item satisfies it. A bare value is equality; the operators are `$eq`,
90
- `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
91
- `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
92
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
93
- text and `$size: 0` an empty list. A date compares in calendar order and never
94
- with a date-time. A reference compares by the Room Path it resolves to.
95
- Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
96
- values. There is no text containment or regular
97
- expression.
98
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
99
- reference at pointer `field`, at any depth, points to a matching Document of the
100
- same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
101
- matching Document of the same Room references. Each keeps a Document once.
102
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
103
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
104
- list of pointers and `sections` `'all'` or a list of names. Selected pointers
105
- return the frontmatter holding only them, nested as written. A backlink names
106
- the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
107
- Document also returns its MD Type. A non-Markdown Document or binary link
108
- target returns only Room and Path. An unselected part is absent. Select only
109
- what a screen shows: a list that selects the Markdown hears every edit of it.
110
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
111
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
112
- or `null` for a write the Provider made itself, and `time` is the Provider's
113
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
114
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
115
- saved write takes the Provider's own once it is Accepted and refreshed. A
116
- Room's last change is its Document with the latest `time`.
117
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
118
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
119
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
120
- over every match and ordered by `count` or a key. A sort or group takes only a
121
- pointer that holds one value. `limit` bounds the Documents or the groups.
122
- - **Results and errors.** A result carries no Room Version: read freshness from
123
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
124
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
125
- answers an empty result in its place.
126
-
127
- ## Local Search rules
128
-
129
- `search({ text, documents, conversations, limit })` answers once, by words, from
130
- local state, with MiniSearch at its default configuration. There is no observed
131
- search.
132
-
133
- - **What is found.** A Document by its field values, its sections' headings and
134
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
135
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
136
- word forms, typo tolerance or prefix matching.
137
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
138
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
139
- apply before `limit`, which bounds each list; without it every hit returns.
140
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
141
- hits of one list of one search. A Document hit names its `room`, `path` and
142
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
143
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
144
- `path`, or `text`. A hit carries no position; mark the words in the text you
145
- show. An invalid filter fails with its Local Query error.
146
-
147
- ## Room Draft, Save, and outcome rules
148
-
149
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
150
- tab. It is durable: it survives reload and navigation. A Room that Discovery
151
- stops listing takes its Room Drafts and its queue with it.
152
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
153
- the revision you read, or `null` when there was none, and every part it should
154
- now change: fields, sections and the preamble, or the whole Markdown, a
155
- creation, a move, or a removal. A part new to the Room Draft names its base,
156
- the value you showed when it was opened; the MD Runtime keeps a part's first
157
- base. A binary link target has a Room Draft too, for a move or a removal, with
158
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
159
- the current Room Draft; read it and write again.
160
-
161
- Save takes one Room and the Room Drafts of it to save, each with its revision,
162
- validates locally, and on success appends one Change Batch to that Room's
163
- queue and removes those Room Drafts. It is refused as `stale`, as
164
- `changed-underneath` naming each part whose base no longer matches the visible
165
- state, or by a local validation rule, and then creates nothing and leaves every
166
- Room Draft in place. A directory move or removal is a move or removal part on
167
- each Document and binary link target beneath it, saved together.
168
-
169
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
170
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
171
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
172
- longer applies over the Room each leave the queue and return as Room Drafts on
173
- the Documents they changed, marked with why: the Provider's structured refusal
174
- code and fields as returned, not known to have applied, or withdrawn locally.
175
- The rest of the queue keeps synchronizing, and Sync Status requires attention
176
- until each returned Room Draft is saved again or discarded. A Change Batch
177
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
178
- Pending one, and a returned Room Draft says why it returned. Transport
179
- failure and Provider unavailability keep work Pending and do not infer a
180
- rejection. A refusal the Provider marks retryable stays Pending until the reset
181
- it names; the MD Runtime retries the same Change Batch identity and payload and
182
- never infers an outcome from transport uncertainty. The MD Runtime never
183
- combines, reorders, or rebases.
184
-
185
- `observe('service-mode')` answers the Provider's Service
186
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
187
- its Change Batch waits unsent, and the queue is submitted in order once the
188
- Provider reopens writes. An Action is never held: a write the Provider refuses
189
- for the halt returns that refusal to its caller. Show the Provider as read-only
190
- instead of retrying.
191
-
192
- ## The neutrality rule
193
-
194
- No module outside an Adapter package imports, names, or special-cases a
195
- Provider. MD UI and every App reach data only through the client entry.
196
-
197
- ## Content-safety rules
198
-
199
- The Provider authorization belongs to the Runtime host and is never readable
200
- by the App's code. The App's code reaches the network only at the external
201
- origins its manifest declares, empty by default, and the Provider enforces
202
- that set. Every request to the Provider itself goes through the MD Runtime.
203
- Rendered Markdown never executes scripts, renders raw HTML only for the
204
- details and summary elements, and loads images and other resources only from
205
- origins the Provider's policy allows.
206
-
207
- ## Launch promises MD UI keeps
208
-
209
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
210
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
211
- a desktop. Its strings are English only, dates and numbers follow the
212
- browser locale, and content is never translated. Light and dark themes come
213
- from CSS custom properties with the browser's preference as the default and
214
- an App's override respected. What an App Creator's agent adds carries none
215
- of these promises by itself. Reading, querying and searching never wait for
216
- the network. Data lives only in the App Creator's browser and with the Provider.
217
-
218
- ## App code takes the client its host hands it and never constructs a Runtime
219
-
220
- App code takes the client its host hands it: in House,
221
- `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
222
- client House built into the page. It never constructs a Runtime or a client.
223
- It imports only types from `@agentshouse/mdruntime/client`, does not call
224
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
225
- the host entry, or the Adapter package. Hosts and tests use those entries; the
226
- served App does not.
227
-
228
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
229
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
230
- the arguments of `observe` and returns the topic's current value, `undefined`
231
- until it arrives, re-rendering on each change; a `null` client observes
232
- nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
233
- `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
234
- already there, keeping the bases its parts have, or onto a new one, and saves
235
- them together. A refused Save leaves the Room Drafts for the App to save again
236
- or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
237
- roomDrafts)` is that save outside a component. A react-admin or Refine App
238
- reads and writes its Rooms through the data providers of
239
- `@agentshouse/mdruntime-families`.
240
-
241
- ## What an agent must never do
242
-
243
- An agent must never read the authorization, load code from a Room, call the
244
- Provider directly, or rebase a refused Change Batch.
package/dist/gather.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
2
- export declare function selections<T>(items: readonly T[], weight: (item: T) => number, limit: number): readonly (readonly T[])[];
3
- //# sourceMappingURL=gather.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,GAClD,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CA0BxB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAgB3B"}
package/dist/gather.js DELETED
@@ -1,40 +0,0 @@
1
- export function gathered(send) {
2
- let held = [];
3
- function flush() {
4
- const taken = held;
5
- held = [];
6
- send(taken.map((entry) => entry.ask)).then((answers) => {
7
- taken.forEach((entry, index) => {
8
- entry.resolve(answers[index]);
9
- });
10
- }, (reason) => {
11
- for (const entry of taken)
12
- entry.reject(reason);
13
- });
14
- }
15
- return (ask) => new Promise((resolve, reject) => {
16
- if (held.length === 0) {
17
- // Asks made in one task wait a single event-loop turn so they leave as one batch.
18
- setTimeout(flush, 0);
19
- }
20
- held.push({ ask, resolve, reject });
21
- });
22
- }
23
- export function selections(items, weight, limit) {
24
- const parts = [];
25
- let part = [];
26
- let carried = 0;
27
- for (const item of items) {
28
- const weighed = weight(item);
29
- if (part.length > 0 && carried + weighed > limit) {
30
- parts.push(part);
31
- part = [];
32
- carried = 0;
33
- }
34
- part.push(item);
35
- carried += weighed;
36
- }
37
- if (part.length > 0)
38
- parts.push(part);
39
- return parts;
40
- }