@agentshouse/mdruntime-adapter 0.1.0-c5b15f4efd6f3 → 0.1.0-c5cb64c7ee7e2

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 (63) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +45 -2
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +121 -216
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +429 -115
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +9 -13
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +58 -39
  17. package/dist/gather.d.ts +2 -1
  18. package/dist/gather.d.ts.map +1 -1
  19. package/dist/gather.js +15 -20
  20. package/dist/house-model.d.ts +2 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +484 -0
  23. package/dist/index.d.ts +7 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +6 -1
  26. package/dist/model.d.ts +6 -2
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +32 -20
  29. package/dist/part.d.ts +15 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +82 -0
  32. package/dist/read.d.ts +79 -20
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +360 -163
  35. package/dist/refusal.d.ts +5 -9
  36. package/dist/refusal.d.ts.map +1 -1
  37. package/dist/refusal.js +31 -17
  38. package/dist/room-types.d.ts +7 -0
  39. package/dist/room-types.d.ts.map +1 -0
  40. package/dist/room-types.js +124 -0
  41. package/dist/site.d.ts +1 -1
  42. package/dist/site.d.ts.map +1 -1
  43. package/dist/site.js +177 -65
  44. package/dist/stream.d.ts +7 -4
  45. package/dist/stream.d.ts.map +1 -1
  46. package/dist/stream.js +390 -43
  47. package/dist/transport.d.ts +87 -15
  48. package/dist/transport.d.ts.map +1 -1
  49. package/dist/transport.js +4 -1
  50. package/dist/upload.d.ts +12 -0
  51. package/dist/upload.d.ts.map +1 -0
  52. package/dist/upload.js +63 -0
  53. package/dist/version.d.ts +1 -0
  54. package/dist/version.d.ts.map +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/write.d.ts +14 -9
  57. package/dist/write.d.ts.map +1 -1
  58. package/dist/write.js +161 -47
  59. package/package.json +9 -6
  60. package/AGENTS.md +0 -217
  61. package/dist/links.d.ts +0 -20
  62. package/dist/links.d.ts.map +0 -1
  63. package/dist/links.js +0 -104
package/dist/write.js CHANGED
@@ -1,4 +1,5 @@
1
- import { parseOriginals } from './read.js';
1
+ import { departure, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
2
3
  import { sha256Hex, textBytes } from './digest.js';
3
4
  import { nativePath, roomLocalPath } from './map.js';
4
5
  import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
@@ -73,6 +74,25 @@ function operationOf(batch, change, handle) {
73
74
  const operation = created(change, path);
74
75
  return operation === null ? { rule: 'type-missing' } : { operation };
75
76
  }
77
+ if (change.kind === 'binary') {
78
+ const written = {
79
+ op: 'upload',
80
+ path,
81
+ local_id: change.localId,
82
+ bytes: change.byteLength,
83
+ sha256: change.sha256,
84
+ media_type: change.mediaType,
85
+ };
86
+ const from = departure(batch.changes, batch.changes.indexOf(change));
87
+ if (from === change.path && priorAbsence(batch, change.path) !== undefined)
88
+ return { operation: written };
89
+ const replaced = priorExistence(batch, from);
90
+ if (replaced === undefined)
91
+ return { rule: 'precondition-missing' };
92
+ if (!('base' in replaced))
93
+ return { rule: 'presence-base-unrepresentable' };
94
+ return { operation: { ...written, base: replaced.base } };
95
+ }
76
96
  const existence = priorExistence(batch, change.path);
77
97
  if (existence === undefined)
78
98
  return { rule: 'precondition-missing' };
@@ -100,6 +120,24 @@ export function houseChanges(batch, handle) {
100
120
  }
101
121
  return { kind: 'changes', changes };
102
122
  }
123
+ export function houseMove(batch, source, destination) {
124
+ const changes = [];
125
+ for (const { path, to } of batch.between?.moves ?? []) {
126
+ const existence = priorExistence(batch, path);
127
+ if (existence === undefined)
128
+ return { kind: 'unmapped', path, rule: 'precondition-missing' };
129
+ if (!('base' in existence)) {
130
+ return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
131
+ }
132
+ changes.push({
133
+ op: 'rename',
134
+ path: nativePath(path, source),
135
+ to: nativePath(to, destination),
136
+ base: existence.base,
137
+ });
138
+ }
139
+ return { kind: 'changes', changes };
140
+ }
103
141
  export function operationHead(batch) {
104
142
  const writer = batch.writtenBy;
105
143
  return writer === undefined
@@ -109,7 +147,7 @@ export function operationHead(batch) {
109
147
  export function batchPaths(changes) {
110
148
  return [
111
149
  ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
112
- ].sort();
150
+ ];
113
151
  }
114
152
  export function deltaBody(changes) {
115
153
  return JSON.stringify({ changes });
@@ -124,20 +162,29 @@ export function uploadable(inline, bytes, bounds) {
124
162
  export function deltaDigest(delta) {
125
163
  return sha256Hex(delta);
126
164
  }
127
- function material(value, handle) {
165
+ function* material(value, handle, within = () => true) {
128
166
  if (!Array.isArray(value))
129
167
  return null;
130
168
  const held = [];
131
169
  for (const entry of value) {
170
+ yield ROW_WEIGHT;
132
171
  if (typeof entry !== 'object' || entry === null)
133
172
  return null;
134
173
  const file = entry;
135
174
  if (typeof file.path !== 'string')
136
175
  return null;
176
+ if (!within(file.path))
177
+ continue;
137
178
  if (file.content !== null && typeof file.content !== 'string')
138
179
  return null;
139
180
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
140
181
  return null;
182
+ const binary = binaryFileOf(file);
183
+ if (binary === null)
184
+ return null;
185
+ const head = headChange(file);
186
+ if (head === null)
187
+ return null;
141
188
  let path;
142
189
  try {
143
190
  path = roomLocalPath(file.path, handle);
@@ -149,29 +196,84 @@ function material(value, handle) {
149
196
  path,
150
197
  content: file.content,
151
198
  revision: typeof file.revision === 'string' ? file.revision : null,
199
+ ...(binary === undefined ? {} : { binary }),
200
+ ...(head === undefined ? {} : { head }),
152
201
  });
153
202
  }
154
203
  return held;
155
204
  }
156
- function affectedOf(held) {
205
+ function* affectedOf(held) {
157
206
  const affected = {};
158
207
  for (const entry of held) {
159
208
  if (entry.content !== null)
160
209
  affected[entry.path] = entry.content;
210
+ yield ROW_WEIGHT;
161
211
  }
162
212
  return affected;
163
213
  }
164
- export function mutationOutcome(status, body, locator, handle) {
214
+ function* acceptedOf(at, contents) {
215
+ const answer = answering();
216
+ for (const entry of contents) {
217
+ yield ROW_WEIGHT + (entry.content?.length ?? 0);
218
+ if (entry.revision === null) {
219
+ answer.removals.add(entry.path);
220
+ continue;
221
+ }
222
+ if (entry.content !== null)
223
+ answer.documents.set(entry.path, entry.content);
224
+ if (entry.binary !== undefined)
225
+ answer.binaryFiles.set(entry.path, entry.binary);
226
+ revised(answer, entry.path, entry.revision);
227
+ if (entry.head !== undefined)
228
+ answer.changes.set(entry.path, entry.head);
229
+ }
230
+ const unbinaried = answer.binaryFiles.size === 0;
231
+ const { binaryFiles, ...room } = yield* answered(answer);
232
+ return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
233
+ }
234
+ function* movedOutcome(held, move) {
235
+ const authorities = Array.isArray(held.authorities) ? held.authorities : [];
236
+ const at = (authority) => {
237
+ const entry = authorities.find((one) => typeof one === 'object' &&
238
+ one !== null &&
239
+ one.authority === authority);
240
+ return entry === undefined ? null : readPosition(entry);
241
+ };
242
+ const left = at(move.source.authority);
243
+ const arrived = at(move.destination.authority);
244
+ if (left === null || arrived === null)
245
+ return { kind: 'transport-uncertainty' };
246
+ const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
247
+ const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
248
+ const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
249
+ if (leaving === null || arriving === null)
250
+ return { kind: 'transport-uncertainty' };
251
+ return {
252
+ kind: 'accepted',
253
+ ...(yield* acceptedOf(left, leaving)),
254
+ destination: yield* acceptedOf(arrived, arriving),
255
+ };
256
+ }
257
+ export function* mutationOutcome(status, body, locator, handle, move) {
165
258
  const refusal = doorRefusal(body);
166
259
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
167
260
  return { kind: 'write-halted' };
168
261
  }
169
- if (refusal !== null && refusal.code === 'operation_expired')
170
- return { kind: 'expired' };
262
+ if (refusal !== null && refusal.code === 'expired') {
263
+ return refusal.fields.restored === true
264
+ ? { kind: 'expired', restored: true }
265
+ : { kind: 'expired' };
266
+ }
171
267
  if (refusal !== null && refusal.code === 'edit_conflict') {
172
268
  const { current, ...fields } = refusal.fields;
173
- const held = material(current, handle) ?? [];
174
- return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
269
+ const held = (yield* material(current, handle)) ?? [];
270
+ return {
271
+ kind: 'conflicted',
272
+ affected: yield* affectedOf(held),
273
+ code: refusal.code,
274
+ fields,
275
+ retryable: refusal.retryable,
276
+ };
175
277
  }
176
278
  if (refusal !== null && status === 404) {
177
279
  return scopedRefusal(locator, 'undisclosed', refusal);
@@ -181,48 +283,41 @@ export function mutationOutcome(status, body, locator, handle) {
181
283
  if (refusal?.retryable === true &&
182
284
  typeof reset === 'string' &&
183
285
  classified?.kind === 'transport-uncertainty') {
184
- return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
185
- }
186
- if (classified !== null && classified.kind !== 'scoped-refusal') {
187
- return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
286
+ return {
287
+ kind: 'retryable-refusal',
288
+ code: refusal.code,
289
+ fields: refusal.fields,
290
+ retryable: true,
291
+ reset,
292
+ };
188
293
  }
189
- if (classified !== null && status === 403)
294
+ if (classified !== null && classified.kind !== 'scoped-refusal')
295
+ return classified;
296
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
190
297
  return classified;
298
+ }
191
299
  if (refusal !== null && status >= 400) {
192
- return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
300
+ return {
301
+ kind: 'rejected',
302
+ affected: {},
303
+ code: refusal.code,
304
+ fields: refusal.fields,
305
+ retryable: refusal.retryable,
306
+ };
193
307
  }
194
308
  if (status !== 200 || typeof body !== 'object' || body === null) {
195
309
  return { kind: 'transport-uncertainty' };
196
310
  }
197
311
  const held = body;
312
+ if (move !== undefined)
313
+ return yield* movedOutcome(held, move);
198
314
  const at = readPosition(held);
199
315
  if (at === null)
200
316
  return { kind: 'transport-uncertainty' };
201
- const contents = material(held.contents, handle);
317
+ const contents = yield* material(held.contents, handle);
202
318
  if (contents === null)
203
319
  return { kind: 'transport-uncertainty' };
204
- const originals = parseOriginals(held.originals);
205
- if (originals === null)
206
- return { kind: 'transport-uncertainty' };
207
- const documents = {};
208
- const revisions = {};
209
- const removals = [];
210
- for (const entry of contents) {
211
- if (entry.content === null || entry.revision === null) {
212
- removals.push(entry.path);
213
- continue;
214
- }
215
- documents[entry.path] = entry.content;
216
- revisions[entry.path] = entry.revision;
217
- }
218
- return {
219
- kind: 'accepted',
220
- roomVersion: roomVersion(at),
221
- documents,
222
- revisions,
223
- removals: removals.sort(),
224
- originals,
225
- };
320
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
226
321
  }
227
322
  export function rejectedMapping(mapping) {
228
323
  return {
@@ -230,6 +325,7 @@ export function rejectedMapping(mapping) {
230
325
  affected: {},
231
326
  code: mapping.rule,
232
327
  fields: { path: mapping.path },
328
+ retryable: false,
233
329
  };
234
330
  }
235
331
  export function revisionBody(input) {
@@ -242,20 +338,26 @@ export function revisionBody(input) {
242
338
  function revisionAuthor(entry) {
243
339
  const user = entry.author_user;
244
340
  const site = entry.author_site;
245
- const name = entry.author_site_name;
246
- if (typeof user === 'string' && site === undefined && name === undefined) {
341
+ const siteName = entry.author_site_name;
342
+ const inbox = entry.author_inbox;
343
+ const inboxName = entry.author_inbox_name;
344
+ const named = [site, siteName, inbox, inboxName].filter((held) => held !== undefined);
345
+ if (typeof user === 'string' && named.length === 0)
247
346
  return { kind: 'user', id: user };
347
+ if (user !== null || named.length !== 2)
348
+ return null;
349
+ if (typeof site === 'string' && typeof siteName === 'string') {
350
+ return { kind: 'site', id: site, name: siteName };
248
351
  }
249
- if (user === null && typeof site === 'string' && typeof name === 'string') {
250
- return { kind: 'site', id: site, name };
352
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
353
+ return { kind: 'inbox', id: inbox, name: inboxName };
251
354
  }
252
355
  return null;
253
356
  }
254
357
  export function historyOutcome(status, body, locator, request) {
255
358
  const classified = classifyDoor(status, body, locator);
256
- if (classified !== null) {
257
- return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
258
- }
359
+ if (classified !== null)
360
+ return classified;
259
361
  if (status !== 200 || typeof body !== 'object' || body === null) {
260
362
  return { kind: 'transport-uncertainty' };
261
363
  }
@@ -276,11 +378,14 @@ export function historyOutcome(status, body, locator, request) {
276
378
  return {
277
379
  kind: 'scoped-refusal',
278
380
  locator,
279
- scope: 'content',
381
+ scope: 'operation',
280
382
  code: 'retained_history_unavailable',
281
383
  fields: { path: request.path, revision: request.revision },
384
+ retryable: false,
282
385
  };
283
386
  }
387
+ if (typeof named.media_type === 'string')
388
+ return { kind: 'no-history' };
284
389
  if (typeof named.content !== 'string')
285
390
  return { kind: 'transport-uncertainty' };
286
391
  return { kind: 'revision', content: named.content };
@@ -295,12 +400,21 @@ export function historyOutcome(status, body, locator, request) {
295
400
  typeof entry.created_at !== 'string') {
296
401
  return { kind: 'transport-uncertainty' };
297
402
  }
298
- revisions.push({ revision: entry.revision, author, time: entry.created_at });
403
+ const binaryFile = binaryFileOf(entry);
404
+ if (binaryFile === null)
405
+ return { kind: 'transport-uncertainty' };
406
+ revisions.push({
407
+ revision: entry.revision,
408
+ author,
409
+ time: entry.created_at,
410
+ ...(binaryFile === undefined ? {} : { binaryFile }),
411
+ });
299
412
  }
300
413
  const next = held.next_before;
301
414
  return {
302
415
  kind: 'history',
303
416
  revisions,
304
417
  ...(typeof next === 'number' ? { pageToken: String(next) } : {}),
418
+ ...(held.deleted === true ? { deleted: true } : {}),
305
419
  };
306
420
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c5b15f4efd6f3",
3
+ "version": "0.1.0-c5cb64c7ee7e2",
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-c30ed2b8e04d5"
27
+ "@agentshouse/mdruntime": "0.1.0-c3c7796382e28"
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,217 +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 takes the client its host hands it and never constructs a Runtime
205
-
206
- App code takes the client its host hands it: in House,
207
- `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
208
- client House built into the page. It never constructs a Runtime or a client.
209
- It imports only types from `@agentshouse/mdruntime/client`, does not call
210
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
211
- the host entry, or the Adapter package. Hosts and tests use those entries; the
212
- served App does not.
213
-
214
- ## What an agent must never do
215
-
216
- An agent must never read the authorization, load code from a Room, call the
217
- Provider directly, or rebase a refused Change Batch.
package/dist/links.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { HeldRoom, MutationResult, RoomAttachment } from '@agentshouse/mdruntime';
2
- import type { HouseScope, HouseView } from './read.js';
3
- import type { StreamedAdvancement } from './stream.js';
4
- export type RoomLinks = {
5
- roomVersion: string;
6
- handed: ReadonlyMap<string, RoomAttachment>;
7
- paths: ReadonlyMap<string, ReadonlySet<string>>;
8
- revisions: ReadonlyMap<string, string>;
9
- };
10
- export declare function scopeLinks(scope: HouseScope): RoomLinks;
11
- export declare function heldLinks(held: HeldRoom): RoomLinks;
12
- export declare function acceptedLinks(held: RoomLinks, accepted: Extract<MutationResult, {
13
- kind: 'accepted';
14
- }>, roomVersion: string, originals: readonly RoomAttachment[]): {
15
- links: RoomLinks;
16
- attachments?: readonly RoomAttachment[];
17
- };
18
- export declare function enumeratedLinks(view: HouseView, earlier: RoomLinks | undefined): RoomLinks;
19
- export declare function streamedLinks(held: RoomLinks, advanced: StreamedAdvancement): RoomLinks | null;
20
- //# sourceMappingURL=links.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAOvD,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAcF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAWvD;AAOD,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAOnD;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACvD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,SAAS,cAAc,EAAE,GACnC;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,CA2B/D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAgB1F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAoB9F"}