@agentshouse/mdruntime-adapter 0.1.0-c7d05e09c73b7 → 0.1.0-c7edf402e20a3

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 (75) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +6 -5
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +25 -322
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +278 -233
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/authored-path.d.ts +11 -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 +38 -0
  15. package/dist/chunks.d.ts.map +1 -0
  16. package/dist/chunks.js +247 -0
  17. package/dist/crockford.d.ts +4 -0
  18. package/dist/crockford.d.ts.map +1 -0
  19. package/dist/crockford.js +3 -0
  20. package/dist/discovery.d.ts +24 -14
  21. package/dist/discovery.d.ts.map +1 -1
  22. package/dist/discovery.js +98 -53
  23. package/dist/history.d.ts +12 -0
  24. package/dist/history.d.ts.map +1 -0
  25. package/dist/history.js +92 -0
  26. package/dist/house-model.d.ts +682 -0
  27. package/dist/house-model.d.ts.map +1 -0
  28. package/dist/house-model.js +397 -0
  29. package/dist/index.d.ts +12 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +11 -0
  32. package/dist/model.d.ts +5 -5
  33. package/dist/model.d.ts.map +1 -1
  34. package/dist/model.js +33 -43
  35. package/dist/read.d.ts +61 -46
  36. package/dist/read.d.ts.map +1 -1
  37. package/dist/read.js +176 -272
  38. package/dist/refusal.d.ts +3 -8
  39. package/dist/refusal.d.ts.map +1 -1
  40. package/dist/refusal.js +10 -14
  41. package/dist/room-types.d.ts +5 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +120 -0
  44. package/dist/search.d.ts +5 -0
  45. package/dist/search.d.ts.map +1 -0
  46. package/dist/search.js +47 -0
  47. package/dist/site.d.ts +1 -1
  48. package/dist/site.d.ts.map +1 -1
  49. package/dist/site.js +122 -106
  50. package/dist/space-schema.d.ts +7 -0
  51. package/dist/space-schema.d.ts.map +1 -0
  52. package/dist/space-schema.js +18 -0
  53. package/dist/stream.d.ts +15 -13
  54. package/dist/stream.d.ts.map +1 -1
  55. package/dist/stream.js +279 -152
  56. package/dist/transport.d.ts +89 -24
  57. package/dist/transport.d.ts.map +1 -1
  58. package/dist/transport.js +55 -9
  59. package/dist/upload.d.ts +12 -0
  60. package/dist/upload.d.ts.map +1 -0
  61. package/dist/upload.js +63 -0
  62. package/dist/version.d.ts +1 -0
  63. package/dist/version.d.ts.map +1 -1
  64. package/dist/version.js +1 -1
  65. package/dist/write.d.ts +20 -10
  66. package/dist/write.d.ts.map +1 -1
  67. package/dist/write.js +161 -63
  68. package/package.json +9 -6
  69. package/AGENTS.md +0 -253
  70. package/dist/gather.d.ts +0 -4
  71. package/dist/gather.d.ts.map +0 -1
  72. package/dist/gather.js +0 -45
  73. package/dist/links.d.ts +0 -20
  74. package/dist/links.d.ts.map +0 -1
  75. package/dist/links.js +0 -104
package/dist/write.js CHANGED
@@ -1,7 +1,8 @@
1
- import { headChange, 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,26 @@ 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;
141
187
  const head = headChange(file);
142
188
  if (head === null)
143
189
  return null;
@@ -152,84 +198,121 @@ function material(value, handle) {
152
198
  path,
153
199
  content: file.content,
154
200
  revision: typeof file.revision === 'string' ? file.revision : null,
201
+ ...(binary === undefined ? {} : { binary }),
155
202
  ...(head === undefined ? {} : { head }),
156
203
  });
157
204
  }
158
205
  return held;
159
206
  }
160
- function affectedOf(held) {
207
+ function* affectedOf(held) {
161
208
  const affected = {};
162
209
  for (const entry of held) {
163
210
  if (entry.content !== null)
164
211
  affected[entry.path] = entry.content;
212
+ yield ROW_WEIGHT;
165
213
  }
166
214
  return affected;
167
215
  }
168
- 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) {
169
260
  const refusal = doorRefusal(body);
170
261
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
171
262
  return { kind: 'write-halted' };
172
263
  }
173
- if (refusal !== null && refusal.code === 'expired')
174
- return { kind: 'expired' };
175
264
  if (refusal !== null && refusal.code === 'edit_conflict') {
176
265
  const { current, ...fields } = refusal.fields;
177
- const held = material(current, handle) ?? [];
178
- 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
+ };
179
274
  }
180
275
  if (refusal !== null && status === 404) {
181
276
  return scopedRefusal(locator, 'undisclosed', refusal);
182
277
  }
183
278
  const classified = classifyDoor(status, body, locator);
184
- const reset = refusal?.fields.retry_at;
185
- if (refusal?.retryable === true &&
186
- typeof reset === 'string' &&
187
- classified?.kind === 'transport-uncertainty') {
188
- return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
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
+ };
189
288
  }
190
289
  if (classified !== null && classified.kind !== 'scoped-refusal')
191
290
  return classified;
192
- if (classified !== null && status === 403)
291
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
193
292
  return classified;
293
+ }
194
294
  if (refusal !== null && status >= 400) {
195
- 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
+ };
196
302
  }
197
303
  if (status !== 200 || typeof body !== 'object' || body === null) {
198
304
  return { kind: 'transport-uncertainty' };
199
305
  }
200
306
  const held = body;
307
+ if (move !== undefined)
308
+ return yield* movedOutcome(held, move);
201
309
  const at = readPosition(held);
202
310
  if (at === null)
203
311
  return { kind: 'transport-uncertainty' };
204
- const contents = material(held.contents, handle);
312
+ const contents = yield* material(held.contents, handle);
205
313
  if (contents === null)
206
314
  return { kind: 'transport-uncertainty' };
207
- const originals = parseOriginals(held.originals);
208
- if (originals === null)
209
- return { kind: 'transport-uncertainty' };
210
- const documents = {};
211
- const revisions = {};
212
- const changes = {};
213
- const removals = [];
214
- for (const entry of contents) {
215
- if (entry.content === null || entry.revision === null) {
216
- removals.push(entry.path);
217
- continue;
218
- }
219
- documents[entry.path] = entry.content;
220
- revisions[entry.path] = entry.revision;
221
- if (entry.head !== undefined)
222
- changes[entry.path] = entry.head;
223
- }
224
- return {
225
- kind: 'accepted',
226
- roomVersion: roomVersion(at),
227
- documents,
228
- revisions,
229
- changes,
230
- removals: removals.sort(),
231
- originals,
232
- };
315
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
233
316
  }
234
317
  export function rejectedMapping(mapping) {
235
318
  return {
@@ -237,6 +320,7 @@ export function rejectedMapping(mapping) {
237
320
  affected: {},
238
321
  code: mapping.rule,
239
322
  fields: { path: mapping.path },
323
+ retryable: false,
240
324
  };
241
325
  }
242
326
  export function revisionBody(input) {
@@ -248,13 +332,26 @@ export function revisionBody(input) {
248
332
  }
249
333
  function revisionAuthor(entry) {
250
334
  const user = entry.author_user;
335
+ const userName = entry.author_user_name;
251
336
  const site = entry.author_site;
252
- const name = entry.author_site_name;
253
- if (typeof user === 'string' && site === undefined && name === undefined) {
254
- 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 };
255
352
  }
256
- if (user === null && typeof site === 'string' && typeof name === 'string') {
257
- return { kind: 'site', id: site, name };
353
+ if (typeof app === 'string' && typeof appName === 'string') {
354
+ return { kind: 'app', id: app, name: appName };
258
355
  }
259
356
  return null;
260
357
  }
@@ -278,15 +375,8 @@ export function historyOutcome(status, body, locator, request) {
278
375
  const named = entries[0];
279
376
  if (named === undefined)
280
377
  return { kind: 'no-history' };
281
- if (named.unavailable === true) {
282
- return {
283
- kind: 'scoped-refusal',
284
- locator,
285
- scope: 'content',
286
- code: 'retained_history_unavailable',
287
- fields: { path: request.path, revision: request.revision },
288
- };
289
- }
378
+ if (typeof named.media_type === 'string')
379
+ return { kind: 'no-history' };
290
380
  if (typeof named.content !== 'string')
291
381
  return { kind: 'transport-uncertainty' };
292
382
  return { kind: 'revision', content: named.content };
@@ -301,7 +391,15 @@ export function historyOutcome(status, body, locator, request) {
301
391
  typeof entry.created_at !== 'string') {
302
392
  return { kind: 'transport-uncertainty' };
303
393
  }
304
- 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
+ });
305
403
  }
306
404
  const next = held.next_before;
307
405
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c7d05e09c73b7",
3
+ "version": "0.1.0-c7edf402e20a3",
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-c64dbada0730d",
29
- "@agentshouse/mdruntime": "0.1.0-cf6d5f0a5c9c8"
27
+ "@agentshouse/mdruntime": "0.1.0-cd507e16e5fc0"
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,253 +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, the deployment facts and the signed-in member are observations only.
14
-
15
- The host attaches each port with its reach, and every member and observation
16
- answers within it: a Room outside it answers as one the replica does not hold,
17
- Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
- shows only those Documents and the Types of the models that govern them, and
19
- without conversations the conversation members, the chat draft and the
20
- conversation observation hold none.
21
- A change of the reach reaches every open observation as its new value, a query
22
- keeping every unchanged Document the same object.
23
-
24
- Every `observe` resolves, once its first value has arrived, to a handle:
25
- `current()` is the latest complete value, `subscribe(listener)` hears each later
26
- value whole and returns its unsubscribe, and `close()` ends the observation.
27
- Closing the port ends every handle and rejects every pending call and
28
- observation; a client that reconnects observes again.
29
-
30
- Each conversation the Provider's conversation list names is held complete in the
31
- browser. `conversation.list()` and `observe('conversations')` answer each with its
32
- Agent's identity and name, its name, created and finished times, last outcome and live
33
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
34
- and `started`, when the running turn began, or `null`.
35
- Observe one with `observe('conversation', id, { limit })`: the view
36
- holds its latest `limit` messages, or all of them, oldest first, its chat
37
- draft, and what the Provider streams for it whether or not anything views it:
38
- the running `turn` with its message parts and its context in use and window, the
39
- open questions, the process state, and the CLI's commands and options. These live
40
- only in memory: the message accepted under the turn's id replaces the running turn,
41
- and none of them is stored or searchable.
42
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
43
- sending it is a Provider Action that needs the Provider reachable and is never
44
- queued.
45
-
46
- Each Room in Rooms lists its `attachments`, the files the Provider holds for it
47
- that its Documents link by the Provider's reference, ordered by `reference`,
48
- each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
49
- `entry`. They are as the Provider last declared them and hold no bytes;
50
- open one through the Provider Action that serves it.
51
-
52
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
53
- touch the network.
54
- History and Call go to the Provider through the Adapter. A Call result whose
55
- effect the Provider places in a Room carries `at`, that Room and Room Version;
56
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
57
- reached it, and the MD Runtime keeps refreshing that Room until it has;
58
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
59
- that document was written at a later Room Version. Each History revision
60
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
61
- History of a Path no current document holds answers the removed document's
62
- revisions with `deleted: true`, newest first; that revision is what a link to
63
- the Path opens. Every
64
- member of the
65
- client is asynchronous. Results are detached snapshots. Nothing in this
66
- surface returns the authorization, performs a request the App's code
67
- composes, or exposes the browser store.
68
-
69
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
70
- opaque value using the host's contract.
71
-
72
- `observe('member')` answers who uses the App: the User the Provider signed in,
73
- `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
74
- whose `change.author.id` equals its `id` is that User's own. It is `null` until
75
- the Provider first names one, and where it names none, such as a Site. The
76
- MD Runtime keeps it with the Local Replicas, so it answers offline once known,
77
- and every port hears the next member the Provider names; signing out answers
78
- `null`, then ends the observation with the authorization. It is the only way App code learns who
79
- uses it.
80
-
81
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
82
- ships in no bundle.
83
-
84
- ## Local Query rules
85
-
86
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
87
- result and hears it again only when it changes, keeping every unchanged Document
88
- the same object, so a component can tell what changed by identity. A query is
89
- data:
90
-
91
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
92
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
93
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
94
- - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
95
- `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
96
- meets a list applies to every item and a number names one item. `where` names
97
- pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
98
- when any item satisfies it. A bare value is equality; the operators are `$eq`,
99
- `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
100
- `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
101
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
102
- text and `$size: 0` an empty list. A date compares in calendar order and never
103
- with a date-time. A reference compares by the Room Path it resolves to.
104
- Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
105
- values. There is no text containment or regular
106
- expression.
107
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
108
- reference at pointer `field`, at any depth, points to a matching Document of the
109
- same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
110
- matching Document of the same Room references. Each keeps a Document once.
111
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
112
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
113
- list of pointers and `sections` `'all'` or a list of names. Selected pointers
114
- return the frontmatter holding only them, nested as written. A backlink names
115
- the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
116
- Document also returns its MD Type. A non-Markdown Document or binary link
117
- target returns only Room and Path. An unselected part is absent. Select only
118
- what a screen shows: a list that selects the Markdown hears every edit of it.
119
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
120
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
121
- or `null` for a write the Provider made itself, and `time` is the Provider's
122
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
123
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
124
- saved write takes the Provider's own once it is Accepted. A
125
- Room's last change is its Document with the latest `time`.
126
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
127
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
128
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
129
- over every match and ordered by `count` or a key. A sort or group takes only a
130
- pointer that holds one value. `limit` bounds the Documents or the groups.
131
- - **Results and errors.** A result carries no Room Version: read freshness from
132
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
133
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
134
- answers an empty result in its place.
135
-
136
- ## Local Search rules
137
-
138
- `search({ text, documents, conversations, limit })` answers once, by words, from
139
- local state, with MiniSearch at its default configuration. There is no observed
140
- search.
141
-
142
- - **What is found.** A Document by its field values, its sections' headings and
143
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
144
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
145
- word forms, typo tolerance or prefix matching.
146
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
147
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
148
- apply before `limit`, which bounds each list; without it every hit returns.
149
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
150
- hits of one list of one search. A Document hit names its `room`, `path` and
151
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
152
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
153
- `path`, or `text`. A hit carries no position; mark the words in the text you
154
- show. An invalid filter fails with its Local Query error.
155
-
156
- ## Room Draft, Save, and outcome rules
157
-
158
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
159
- tab. It is durable: it survives reload and navigation. A Room that Discovery
160
- stops listing takes its Room Drafts and its queue with it.
161
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
162
- the revision you read, or `null` when there was none, and every part it should
163
- now change: fields, sections and the preamble, or the whole Markdown, a
164
- creation, a move, or a removal. A part new to the Room Draft names its base,
165
- the value you showed when it was opened; the MD Runtime keeps a part's first
166
- base. A binary link target has a Room Draft too, for a move or a removal, with
167
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
168
- the current Room Draft; read it and write again.
169
-
170
- Save takes one Room and the Room Drafts of it to save, each with its revision,
171
- validates locally, and on success appends one Change Batch to that Room's
172
- queue and removes those Room Drafts. It is refused as `stale`, as
173
- `changed-underneath` naming each part whose base no longer matches the visible
174
- state, or by a local validation rule, and then creates nothing and leaves every
175
- Room Draft in place. A directory move or removal is a move or removal part on
176
- each Document and binary link target beneath it, saved together.
177
-
178
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
179
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
180
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
181
- longer applies over the Room each leave the queue and return as Room Drafts on
182
- the Documents they changed, marked with why: the Provider's structured refusal
183
- code and fields as returned, not known to have applied, or withdrawn locally.
184
- The rest of the queue keeps synchronizing, and Sync Status requires attention
185
- until each returned Room Draft is saved again or discarded. A Change Batch
186
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
187
- Pending one, and a returned Room Draft says why it returned. Transport
188
- failure and Provider unavailability keep work Pending and do not infer a
189
- rejection. A refusal the Provider marks retryable stays Pending until the reset
190
- it names; the MD Runtime retries the same Change Batch identity and payload and
191
- never infers an outcome from transport uncertainty. The MD Runtime never
192
- combines, reorders, or rebases.
193
-
194
- `observe('service-mode')` answers the Provider's Service
195
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
196
- its Change Batch waits unsent, and the queue is submitted in order once the
197
- Provider reopens writes. An Action is never held: a write the Provider refuses
198
- for the halt returns that refusal to its caller. Show the Provider as read-only
199
- instead of retrying.
200
-
201
- ## The neutrality rule
202
-
203
- No module outside an Adapter package imports, names, or special-cases a
204
- Provider. MD UI and every App reach data only through the client entry.
205
-
206
- ## Content-safety rules
207
-
208
- The Provider authorization belongs to the Runtime host and is never readable
209
- by the App's code. The App's code reaches the network only at the external
210
- origins its manifest declares, empty by default, and the Provider enforces
211
- that set. Every request to the Provider itself goes through the MD Runtime.
212
- Rendered Markdown never executes scripts, renders raw HTML only for the
213
- details and summary elements, and loads images and other resources only from
214
- origins the Provider's policy allows.
215
-
216
- ## Launch promises MD UI keeps
217
-
218
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
219
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
220
- a desktop. Its strings are English only, dates and numbers follow the
221
- browser locale, and content is never translated. Light and dark themes come
222
- from CSS custom properties with the browser's preference as the default and
223
- an App's override respected. What an App Creator's agent adds carries none
224
- of these promises by itself. Reading, querying and searching never wait for
225
- the network. Data lives only in the App Creator's browser and with the Provider.
226
-
227
- ## App code takes the client its host hands it and never constructs a Runtime
228
-
229
- App code takes the client its host hands it: in House,
230
- `houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
231
- client House built into the page. It never constructs a Runtime or a client.
232
- It imports only types from `@agentshouse/mdruntime/client`, does not call
233
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
234
- the host entry, or the Adapter package. Hosts and tests use those entries; the
235
- served App does not.
236
-
237
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
238
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
239
- the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
240
- first value arrives, then `{ state: 'ready', value }`, re-rendering on each
241
- change; a `null` client observes nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
242
- `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
243
- already there, keeping the bases its parts have, or onto a new one, and saves
244
- them together. A refused Save leaves the Room Drafts for the App to save again
245
- or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
246
- roomDrafts)` is that save outside a component. A react-admin or Refine App
247
- reads and writes its Rooms through the data providers of
248
- `@agentshouse/mdruntime-families`.
249
-
250
- ## What an agent must never do
251
-
252
- An agent must never read the authorization, load code from a Room, call the
253
- Provider directly, or rebase a refused Change Batch.
package/dist/gather.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare function gatheredEach<A, R>(send: (asks: readonly A[], answer: (ask: number, result: R) => void) => Promise<void>): (ask: A) => Promise<R>;
2
- export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
3
- export declare function selections<T>(items: readonly T[], weight: (item: T) => number, limit: number): readonly (readonly T[])[];
4
- //# sourceMappingURL=gather.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GACpF,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAwBxB;AAED,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,CAMxB;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"}