@agentshouse/mdruntime-adapter 0.1.0-c17fae3d012d0 → 0.1.0-c18e9b633b5bc

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