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

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 (69) hide show
  1. package/README.md +4 -4
  2. package/dist/actions.d.ts +3 -4
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +10 -327
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +283 -246
  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 +18 -23
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +80 -73
  17. package/dist/history.d.ts +12 -0
  18. package/dist/history.d.ts.map +1 -0
  19. package/dist/history.js +91 -0
  20. package/dist/house-model.d.ts +2915 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +1603 -0
  23. package/dist/index.d.ts +10 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +9 -1
  26. package/dist/model.d.ts +10 -18
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +39 -37
  29. package/dist/part.d.ts +14 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +90 -0
  32. package/dist/read.d.ts +52 -41
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +248 -237
  35. package/dist/refusal.d.ts +4 -11
  36. package/dist/refusal.d.ts.map +1 -1
  37. package/dist/refusal.js +26 -17
  38. package/dist/room-stream.d.ts +19 -0
  39. package/dist/room-stream.d.ts.map +1 -0
  40. package/dist/room-stream.js +57 -0
  41. package/dist/room-types.d.ts +7 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +126 -0
  44. package/dist/site.d.ts +1 -1
  45. package/dist/site.d.ts.map +1 -1
  46. package/dist/site.js +132 -142
  47. package/dist/stream.d.ts +16 -11
  48. package/dist/stream.d.ts.map +1 -1
  49. package/dist/stream.js +229 -143
  50. package/dist/transport.d.ts +109 -22
  51. package/dist/transport.d.ts.map +1 -1
  52. package/dist/transport.js +53 -10
  53. package/dist/upload.d.ts +12 -0
  54. package/dist/upload.d.ts.map +1 -0
  55. package/dist/upload.js +63 -0
  56. package/dist/version.d.ts +2 -0
  57. package/dist/version.d.ts.map +1 -1
  58. package/dist/version.js +10 -1
  59. package/dist/write.d.ts +18 -2
  60. package/dist/write.d.ts.map +1 -1
  61. package/dist/write.js +169 -42
  62. package/package.json +9 -6
  63. package/AGENTS.md +0 -215
  64. package/dist/gather.d.ts +0 -3
  65. package/dist/gather.d.ts.map +0 -1
  66. package/dist/gather.js +0 -40
  67. package/dist/links.d.ts +0 -12
  68. package/dist/links.d.ts.map +0 -1
  69. package/dist/links.js +0 -66
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AACA,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,CAAC,CAAC;IAC5B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAYF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAWvD;AAOD,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"}
package/dist/links.js DELETED
@@ -1,66 +0,0 @@
1
- import { roomVersion } from './version.js';
2
- const ATTACHMENT_REFERENCE = /at_[1-9a-hjkmnp-tv-z][0-9a-hjkmnp-tv-z]*\.[0-9a-hjkmnp-tv-z]/g;
3
- const NONE = new Set();
4
- function linkedBy(text) {
5
- if (text === null)
6
- return NONE;
7
- const references = new Set(Array.from(text.matchAll(ATTACHMENT_REFERENCE), ([found]) => found));
8
- return references.size === 0 ? NONE : references;
9
- }
10
- function handedOf(attachments) {
11
- return new Set((attachments ?? []).map((attachment) => attachment.reference));
12
- }
13
- export function scopeLinks(scope) {
14
- return {
15
- roomVersion: roomVersion(scope),
16
- handed: handedOf(scope.attachments),
17
- paths: new Map(scope.contents.map(({ path, content }) => [path, linkedBy(content)])),
18
- revisions: new Map(scope.files.flatMap(({ path, revision }) => revision === undefined ? [] : [[path, revision]])),
19
- };
20
- }
21
- function revised(revisions, path, revision) {
22
- if (revision === undefined)
23
- revisions.delete(path);
24
- else
25
- revisions.set(path, revision);
26
- }
27
- export function enumeratedLinks(view, earlier) {
28
- const paths = new Map(earlier?.paths);
29
- const revisions = new Map(earlier?.revisions);
30
- for (const change of view.changes) {
31
- paths.set(change.path, linkedBy('content' in change ? change.content : null));
32
- revised(revisions, change.path, 'removed' in change
33
- ? undefined
34
- : 'reference' in change
35
- ? change.reference.revision
36
- : change.revision);
37
- }
38
- return { roomVersion: roomVersion(view), handed: handedOf(view.attachments), paths, revisions };
39
- }
40
- export function streamedLinks(held, advanced) {
41
- const paths = new Map(held.paths);
42
- const revisions = new Map(held.revisions);
43
- const dropped = new Set();
44
- for (const entry of advanced.entries) {
45
- revised(revisions, entry.path, entry.kind === 'removed' ? undefined : entry.revision);
46
- const text = entry.kind === 'removed' ? null : entry.text;
47
- if (text === undefined)
48
- return null;
49
- const linked = linkedBy(text);
50
- for (const reference of linked)
51
- if (!held.handed.has(reference))
52
- return null;
53
- for (const reference of paths.get(entry.path) ?? held.handed) {
54
- if (held.handed.has(reference) && !linked.has(reference))
55
- dropped.add(reference);
56
- }
57
- paths.set(entry.path, linked);
58
- }
59
- for (const references of paths.values()) {
60
- for (const reference of references)
61
- dropped.delete(reference);
62
- }
63
- if (dropped.size > 0)
64
- return null;
65
- return { roomVersion: advanced.page.roomVersion, handed: held.handed, paths, revisions };
66
- }