@agentshouse/mdruntime-adapter 0.1.0-c1ae4a2aa7934 → 0.1.0-c1e7ca2d5752d

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