@agentshouse/mdruntime-adapter 0.1.0-cc63dd043d0e2 → 0.1.0-cc65657e82614

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