@yaks/inbox 0.0.0-stage → 0.2.36

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 (88) hide show
  1. package/LICENSE +202 -0
  2. package/Person.tsx +275 -0
  3. package/Project.tsx +83 -0
  4. package/README.md +311 -2
  5. package/_dist/actions-browser.d.ts +8 -0
  6. package/_dist/actions-browser.d.ts.map +1 -0
  7. package/_dist/actions.d.ts +22 -0
  8. package/_dist/actions.d.ts.map +1 -0
  9. package/_dist/asks.d.ts +15 -0
  10. package/_dist/asks.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +12 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/letters.d.ts +24 -0
  14. package/_dist/letters.d.ts.map +1 -0
  15. package/_dist/mail.d.ts +4 -0
  16. package/_dist/mail.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +7 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/options.d.ts +18 -0
  20. package/_dist/options.d.ts.map +1 -0
  21. package/_dist/queries.d.ts +23 -0
  22. package/_dist/queries.d.ts.map +1 -0
  23. package/_dist/read.d.ts +18 -0
  24. package/_dist/read.d.ts.map +1 -0
  25. package/_dist/reader.d.ts +25 -0
  26. package/_dist/reader.d.ts.map +1 -0
  27. package/_dist/service.d.ts +8 -0
  28. package/_dist/service.d.ts.map +1 -0
  29. package/_dist/threads.d.ts +33 -0
  30. package/_dist/threads.d.ts.map +1 -0
  31. package/_dist/tools.d.ts +12 -0
  32. package/_dist/tools.d.ts.map +1 -0
  33. package/_dist/vocab.d.ts +5 -0
  34. package/_dist/vocab.d.ts.map +1 -0
  35. package/actions-browser.js +165 -0
  36. package/actions-browser.js.map +1 -0
  37. package/actions-browser.ts +158 -0
  38. package/actions.js +34 -0
  39. package/actions.js.map +1 -0
  40. package/actions.ts +53 -0
  41. package/asks.js +76 -0
  42. package/asks.js.map +1 -0
  43. package/asks.ts +94 -0
  44. package/deno.json +1 -0
  45. package/front.js +41 -0
  46. package/front.js.map +1 -0
  47. package/front.json +68 -0
  48. package/front.ts +38 -0
  49. package/graph.js +176 -0
  50. package/graph.js.map +1 -0
  51. package/graph.ts +182 -0
  52. package/inspect.tsx +22 -0
  53. package/letters.js +233 -0
  54. package/letters.js.map +1 -0
  55. package/letters.ts +325 -0
  56. package/mail.js +122 -0
  57. package/mail.js.map +1 -0
  58. package/mail.ts +148 -0
  59. package/mod.js +11 -0
  60. package/mod.js.map +1 -0
  61. package/mod.ts +24 -0
  62. package/options.js +15 -0
  63. package/options.js.map +1 -0
  64. package/options.ts +42 -0
  65. package/package.json +76 -4
  66. package/queries.js +240 -0
  67. package/queries.js.map +1 -0
  68. package/queries.ts +302 -0
  69. package/read.js +453 -0
  70. package/read.js.map +1 -0
  71. package/read.ts +476 -0
  72. package/reader.js +105 -0
  73. package/reader.js.map +1 -0
  74. package/reader.ts +147 -0
  75. package/service.js +29 -0
  76. package/service.js.map +1 -0
  77. package/service.ts +45 -0
  78. package/threads.js +182 -0
  79. package/threads.js.map +1 -0
  80. package/threads.ts +276 -0
  81. package/tools.js +101 -0
  82. package/tools.js.map +1 -0
  83. package/tools.ts +103 -0
  84. package/views.tsx +30 -0
  85. package/vocab.js +12 -0
  86. package/vocab.js.map +1 -0
  87. package/vocab.json +242 -0
  88. package/vocab.ts +11 -0
package/read.ts ADDED
@@ -0,0 +1,476 @@
1
+ /** Server reads for the pure inbox policy. Membership and scalar projections
2
+ * keep list reads bodyless; words are authoritative only in search/detail. */
3
+ import type { Bundle, Comp, Graph } from 'jsr:@yaks/graph@0.2.36'
4
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
5
+ import { tablesOf } from '@yaks/archetype/sets'
6
+ import { type Built, joined, line, parse, type Query, sub } from '@yaks/query'
7
+ import {
8
+ candidates,
9
+ dependents,
10
+ discussion,
11
+ requirements,
12
+ type Words,
13
+ words,
14
+ } from './queries.js'
15
+ import { type Reader, readerAt, type Row } from './reader.js'
16
+ import { type Search, type Thread, threadOf, threads } from './threads.js'
17
+
18
+ // Graph.read honors .fields before hydration; raw storage Tx.read does not.
19
+ type ReadTx = Pick<Graph, 'read' | 'get'>
20
+ type Vocabulary = Pick<Vocab, 'comp' | 'props' | 'word'>
21
+ type Mode = 'metadata' | 'search' | 'detail'
22
+
23
+ // Presence is a policy fact, even when a component has no selected properties.
24
+ // In particular, an empty content marks a human input, and an empty decided,
25
+ // completed, conversation, requires or output still changes the policy.
26
+ let components = [
27
+ 'doc',
28
+ 'conversation',
29
+ 'content',
30
+ 'comment',
31
+ 'entry',
32
+ 'output',
33
+ 'notice',
34
+ 'reasoning',
35
+ 'result',
36
+ 'exception',
37
+ 'refusal',
38
+ 'ask',
39
+ 'call',
40
+ 'stop',
41
+ 'commit',
42
+ 'prompt',
43
+ 'session',
44
+ 'project',
45
+ 'design',
46
+ 'task',
47
+ 'decision',
48
+ 'filed',
49
+ 'mail',
50
+ 'mail_notice',
51
+ 'notified',
52
+ 'knock',
53
+ 'deliver',
54
+ 'notification',
55
+ 'bug',
56
+ 'created',
57
+ 'opened',
58
+ 'archived',
59
+ 'completed',
60
+ 'cancelled',
61
+ 'failed',
62
+ 'blocked',
63
+ 'broken',
64
+ 'resolved',
65
+ 'regressed',
66
+ 'decided',
67
+ 'exit',
68
+ 'requires',
69
+ 'edge',
70
+ ]
71
+ let scalars = [
72
+ 'doc.title',
73
+ 'comment.target',
74
+ 'comment.reply_to',
75
+ 'entry.session',
76
+ 'entry.seq',
77
+ 'commit.target',
78
+ 'commit.at',
79
+ 'session.actor',
80
+ 'filed.assignee',
81
+ 'filed.project',
82
+ 'mail.at',
83
+ 'mail.from',
84
+ 'mail.to',
85
+ 'mail.target',
86
+ 'mail.message_id',
87
+ 'mail.reply_to',
88
+ 'notified.message_id',
89
+ 'knock.target',
90
+ 'deliver.to',
91
+ 'notification.to',
92
+ 'notification.about',
93
+ 'bug.title',
94
+ 'bug.app',
95
+ 'bug.first',
96
+ 'bug.last',
97
+ 'decision.question',
98
+ 'created.by',
99
+ 'created.at',
100
+ 'opened.by',
101
+ 'opened.at',
102
+ 'archived.at',
103
+ 'completed.at',
104
+ 'cancelled.at',
105
+ 'failed.at',
106
+ 'blocked.since',
107
+ 'broken.at',
108
+ 'resolved.at',
109
+ 'regressed.at',
110
+ 'decided.at',
111
+ 'decided.by',
112
+ 'decided.choice',
113
+ 'exit.at',
114
+ 'edge.from',
115
+ 'edge.to',
116
+ ]
117
+ let rows = (bundles: Bundle[]): Row[] =>
118
+ bundles.map((b) => ({
119
+ eid: b.entity.eid,
120
+ comps: Object.fromEntries(
121
+ Object.entries(b).filter(([name, value]) =>
122
+ name != 'entity' && value && typeof value == 'object'
123
+ ),
124
+ ) as Row['comps'],
125
+ }))
126
+ let unique = (all: Row[]): Row[] => {
127
+ let out = new Map<string, Row>()
128
+ for (let row of all) {
129
+ let prior = out.get(row.eid)
130
+ out.set(row.eid, {
131
+ eid: row.eid,
132
+ comps: { ...prior?.comps, ...row.comps },
133
+ })
134
+ }
135
+ return [...out.values()]
136
+ }
137
+ let ids = (all: Row[]) => line`.entity.eid=${all.map((r) => r.eid)}`
138
+ // Batches for identity lookups do not need stable subscription buckets.
139
+ let batches = (all: Row[]): Row[][] => {
140
+ let out: Row[][] = []
141
+ for (let i = 0; i < all.length; i += 256) out.push(all.slice(i, i + 256))
142
+ return out
143
+ }
144
+ // A server read asks each round once. boundedReads splits a subscription's
145
+ // query to fit a socket message, and here every part would only scan the same
146
+ // tables again.
147
+ let whole = (rows: Row[], read: (rows: Row[]) => Built): Built[] => {
148
+ let query = rows.length ? read(rows) : undefined
149
+ return query ? [query] : []
150
+ }
151
+ // The rows a query selects, without the components it asks along: its
152
+ // top-level `?` projections give way to the eid alone.
153
+ let ONLY_EID = parse(line`.fields=entity.eid`).clauses
154
+ let membership = (query: Built): Query => {
155
+ let tree = parse(query)
156
+ return {
157
+ ...tree,
158
+ clauses: [
159
+ ...tree.clauses.filter((c) => !(c.kind == 'pred' && c.op == '?')),
160
+ ...ONLY_EID,
161
+ ],
162
+ }
163
+ }
164
+
165
+ let reads = (tx: ReadTx, has: Words, mode: Mode, vocab: Vocabulary) => {
166
+ let comps = components.filter(has)
167
+ let worded = comps.filter((c) => has(`${c}.body`))
168
+ let bodiless = comps.filter((c) => !worded.includes(c))
169
+ let fields = [
170
+ 'entity.eid',
171
+ ...(has('entity.archetype') ? ['entity.archetype'] : []),
172
+ ...scalars.filter(has),
173
+ ...(mode == 'search' ? ['doc.body', 'content.body'].filter(has) : []),
174
+ ]
175
+ let descriptors = new Map<string, Set<string>>()
176
+ // One computation owns one metadata working set. Overlapping discussion
177
+ // arms must not hydrate the same entity repeatedly; never retain it across
178
+ // reads, where another commit could change policy.
179
+ let hydrated = new Map<string, Row>()
180
+ let hydrate = async (members: Row[]): Promise<Row[]> => {
181
+ let uniqueMembers = unique(members)
182
+ let out: Row[] = []
183
+ let missing = uniqueMembers.filter((r) => !hydrated.has(r.eid))
184
+ for (let part of batches(missing)) {
185
+ if (mode == 'detail') {
186
+ out.push(...rows(await tx.get(part.map((r) => r.eid), comps)))
187
+ continue
188
+ }
189
+ let projectedRows = await tx.read(
190
+ line`${sub(ids(part))}&.fields=${fields}`,
191
+ )
192
+ let projected = new Map(rows(projectedRows).map((r) => [r.eid, r]))
193
+ let spines = has('entity.archetype')
194
+ ? projectedRows
195
+ : await tx.get(part.map((r) => r.eid), [])
196
+ let unknown = [
197
+ ...new Set(
198
+ spines.map((b) => b.entity.archetype)
199
+ .filter((id): id is string =>
200
+ typeof id == 'string' && !descriptors.has(id)
201
+ ),
202
+ ),
203
+ ]
204
+ for (
205
+ let b of unknown.length ? await tx.get(unknown, ['archetype']) : []
206
+ ) {
207
+ descriptors.set(
208
+ b.entity.eid,
209
+ new Set(tablesOf((b.archetype as Comp)?.tables, vocab)),
210
+ )
211
+ }
212
+ let classified = new Set<string>()
213
+ for (let b of spines) {
214
+ let tables = descriptors.get(String(b.entity.archetype ?? ''))
215
+ if (!tables) continue
216
+ classified.add(b.entity.eid)
217
+ let r = projected.get(b.entity.eid)
218
+ if (!r) {
219
+ r = { eid: b.entity.eid, comps: {} }
220
+ projected.set(r.eid, r)
221
+ }
222
+ for (let comp of comps) if (tables.has(comp)) r.comps[comp] ??= {}
223
+ }
224
+ // A projection cannot tell absent from present-with-no-selected-values,
225
+ // and a row no archetype classifies says nothing of what it holds. Its
226
+ // bodiless components come in one get, which reads only those its rows
227
+ // hold, rather than a query per component; a worded one (doc, content)
228
+ // is asked by membership, so no body is read merely to prove it exists.
229
+ let mark = (eid: string, comp: string) => {
230
+ let r = projected.get(eid)
231
+ if (!r) projected.set(eid, r = { eid, comps: {} })
232
+ r.comps[comp] ??= {}
233
+ }
234
+ let unclassified = part.filter((r) => !classified.has(r.eid))
235
+ if (unclassified.length && bodiless.length) {
236
+ let held = await tx.get(unclassified.map((r) => r.eid), bodiless)
237
+ for (let b of held.filter(Boolean)) {
238
+ for (let comp of bodiless) if (b[comp]) mark(b.entity.eid, comp)
239
+ }
240
+ }
241
+ for (let comp of worded) {
242
+ let missing = unclassified.filter((r) =>
243
+ !projected.get(r.eid)?.comps[comp]
244
+ )
245
+ if (!missing.length) continue
246
+ for (
247
+ let b of await tx.read(
248
+ line`.${comp}&${sub(ids(missing))}&.fields=entity.eid`,
249
+ )
250
+ ) mark(b.entity.eid, comp)
251
+ }
252
+ out.push(...projected.values())
253
+ }
254
+ for (let row of out) hydrated.set(row.eid, row)
255
+ return uniqueMembers.flatMap((r) =>
256
+ hydrated.has(r.eid) ? [hydrated.get(r.eid)!] : []
257
+ )
258
+ }
259
+ let read = async (queries: Built[]): Promise<Row[]> => {
260
+ let members: Row[] = []
261
+ for (let q of new Set(queries.filter(Boolean))) {
262
+ members.push(...rows(await tx.read(membership(q))))
263
+ }
264
+ return hydrate(members)
265
+ }
266
+ return { read, hydrate }
267
+ }
268
+
269
+ let reader = async (
270
+ tx: ReadTx,
271
+ has: Words,
272
+ actor: string,
273
+ scope?: string,
274
+ ): Promise<Reader> => {
275
+ let fields = [
276
+ 'entity.eid',
277
+ 'email.address',
278
+ 'subscription.actor',
279
+ 'subscription.target',
280
+ 'subscription.mode',
281
+ 'opened.at',
282
+ 'archived.at',
283
+ ].filter(has)
284
+ let person = rows(
285
+ await tx.read(
286
+ line`.entity.eid=${actor}&.fields=${fields}`,
287
+ ),
288
+ )
289
+ if (has('project')) {
290
+ for (
291
+ let r of rows(
292
+ await tx.read(
293
+ line`.project&.entity.eid=${actor}&.fields=entity.eid`,
294
+ ),
295
+ )
296
+ ) {
297
+ let p = person.find((p) => p.eid == r.eid)
298
+ if (p) p.comps.project = {}
299
+ else person.push({ eid: r.eid, comps: { project: {} } })
300
+ }
301
+ }
302
+ let subs = has('subscription.actor')
303
+ ? rows(
304
+ await tx.read(
305
+ line`.subscription.actor=${actor}&.fields=${fields}`,
306
+ ),
307
+ )
308
+ : []
309
+ // Timestamp projections omit present marks without a timestamp. Preserve
310
+ // their presence too: an empty archive still means this person put it away.
311
+ if (subs.length) {
312
+ let targets = new Map(subs.map((r) => [r.eid, r]))
313
+ for (let name of ['opened', 'archived'].filter(has)) {
314
+ for (
315
+ let r of rows(
316
+ await tx.read(
317
+ line`.${name}&${sub(ids(subs))}&.fields=entity.eid`,
318
+ ),
319
+ )
320
+ ) targets.get(r.eid)!.comps[name] ??= {}
321
+ }
322
+ }
323
+ let who = readerAt([...person, ...subs], actor)
324
+ return scope ? { ...who, scope } : who
325
+ }
326
+
327
+ let index = (all: Row[]): Map<string, Row> => {
328
+ let byId = new Map(
329
+ all.filter((r) => !r.comps.mail_notice).map((r) => [r.eid, r]),
330
+ )
331
+ for (let r of byId.values()) {
332
+ for (let id of [r.comps.mail?.message_id, r.comps.notified?.message_id]) {
333
+ if (id) byId.set(String(id), r)
334
+ }
335
+ }
336
+ return byId
337
+ }
338
+
339
+ /** Expand roots and reply ancestry to a fixed point. Mail replies may name a
340
+ * message-id rather than an eid, and more than one ancestor can be missing. */
341
+ let conversation = async (
342
+ seed: Row[],
343
+ who: Reader,
344
+ has: Words,
345
+ read: ReturnType<typeof reads>['read'],
346
+ search: Search,
347
+ ): Promise<Row[]> => {
348
+ let all = unique(seed)
349
+ let queriedRoots = new Set<string>(), queriedParents = new Set<string>()
350
+ let queriedReplies = new Set<string>()
351
+ for (;;) {
352
+ let byId = index(all)
353
+ let roots = [...new Set(all.map((r) => threadOf(r, who, byId)))]
354
+ .filter((eid) => !queriedRoots.has(eid))
355
+ .map((eid) => ({ eid, comps: {} }))
356
+ roots.forEach((r) => queriedRoots.add(r.eid))
357
+ let queries = whole(roots, (part) => discussion(part, has, search))
358
+ let parents = [
359
+ ...new Set(all.map((r) => String(r.comps.mail?.reply_to ?? ''))),
360
+ ]
361
+ .filter((eid) => eid && !queriedParents.has(eid))
362
+ .map((eid) => ({ eid, comps: {} }))
363
+ parents.forEach((r) => queriedParents.add(r.eid))
364
+ queries.push(...whole(parents, (part) => {
365
+ let refs = part.map((r) => r.eid)
366
+ return joined(
367
+ [
368
+ line`.entity.eid=${refs}`,
369
+ ...['mail.message_id', 'notified.message_id'].filter(has)
370
+ .map((p) => line`.${p}=${refs}`),
371
+ ],
372
+ '|',
373
+ )
374
+ }))
375
+ if (has('mail.reply_to')) {
376
+ let replies = [
377
+ ...new Set(
378
+ all.filter((r) => r.comps.mail || r.comps.notified).flatMap((r) => [
379
+ r.eid,
380
+ r.comps.mail?.message_id,
381
+ r.comps.notified?.message_id,
382
+ ]).filter((id): id is string => typeof id == 'string' && !!id),
383
+ ),
384
+ ]
385
+ .filter((id) => !queriedReplies.has(id))
386
+ .map((eid) => ({ eid, comps: {} }))
387
+ replies.forEach((r) => queriedReplies.add(r.eid))
388
+ queries.push(
389
+ ...whole(
390
+ replies,
391
+ (part) => line`.mail.reply_to=${part.map((r) => r.eid)}`,
392
+ ),
393
+ )
394
+ }
395
+ if (!queries.length) return all
396
+ let more = await read(queries)
397
+ all = unique([...all, ...more])
398
+ }
399
+ }
400
+
401
+ /** Exact server inbox summaries. Bodies are absent, not truncated previews.
402
+ * Text/direction searches read complete words on the server, then apply the
403
+ * same pure policy; callers receive threads rather than the source history.
404
+ * `scope` is the project the person stands in, when they read as one of its
405
+ * people: what is addressed to it reaches them too. `target` asks about one
406
+ * candidate through the same visibility and attention policy as the list. */
407
+ export let readInbox = async (
408
+ tx: ReadTx,
409
+ vocab: Vocabulary,
410
+ actor: string,
411
+ search: Search & { target?: string } = {},
412
+ scope?: string,
413
+ ): Promise<Thread[]> => {
414
+ let txGet = tx.get.bind(tx), txRead = tx.read.bind(tx)
415
+ tx = {
416
+ get: (ids, comps) => txGet(ids, comps, { native: true }),
417
+ read: (q) => txRead(q, { native: true }),
418
+ }
419
+ let has = words(vocab)
420
+ let who = await reader(tx, has, actor, scope)
421
+ let { read } = reads(
422
+ tx,
423
+ has,
424
+ search.text?.trim() || search.direction ? 'search' : 'metadata',
425
+ vocab,
426
+ )
427
+ let possible = candidates(who, has, search.within)
428
+ let first = await read([
429
+ search.target && possible
430
+ ? line`${sub(possible)}&.entity.eid=${search.target}`
431
+ : possible,
432
+ ])
433
+ let all = await conversation(first, who, has, read, search)
434
+ let byId = index(all)
435
+ let roots = [...new Set(all.map((r) => threadOf(r, who, byId)))]
436
+ .map((eid) => ({ eid, comps: {} }))
437
+ let edges = await read(
438
+ whole(roots, (part) => requirements(part, has)),
439
+ )
440
+ let tasks = await read(whole(edges, (part) => dependents(part, has)))
441
+ let found = threads(unique([...all, ...edges, ...tasks]), who, search)
442
+ return search.target ? found.filter((t) => t.eid == search.target) : found
443
+ }
444
+
445
+ /** Full authoritative words and messages for one thread, including archived
446
+ * threads. Digest/detail callers must opt into this read rather than treating
447
+ * metadata as a body. Missing or muted/non-inbox roots return undefined. */
448
+ export let readThread = async (
449
+ tx: ReadTx,
450
+ vocab: Vocabulary,
451
+ actor: string,
452
+ root: string,
453
+ scope?: string,
454
+ ): Promise<Thread | undefined> => {
455
+ let txGet = tx.get.bind(tx), txRead = tx.read.bind(tx)
456
+ tx = {
457
+ get: (ids, comps) => txGet(ids, comps, { native: true }),
458
+ read: (q) => txRead(q, { native: true }),
459
+ }
460
+ let has = words(vocab)
461
+ let who = await reader(tx, has, actor, scope)
462
+ let { read, hydrate } = reads(tx, has, 'detail', vocab)
463
+ let seed = await hydrate([{ eid: root, comps: {} }])
464
+ if (!seed.length) return undefined
465
+ // Direction forces discussion() to include internal transcript words too;
466
+ // it is not passed to the policy, which still computes ordinary attention.
467
+ let all = await conversation(seed, who, has, read, { direction: 'received' })
468
+ let eid = threadOf(seed[0], who, index(all))
469
+ let metadata = reads(tx, has, 'metadata', vocab).read
470
+ let edges = await metadata([requirements([{ eid, comps: {} }], has)])
471
+ let tasks = await metadata(
472
+ whole(edges, (part) => dependents(part, has)),
473
+ )
474
+ return threads(unique([...all, ...edges, ...tasks]), who, { all: true })
475
+ .find((t) => t.eid == eid)
476
+ }
package/reader.js ADDED
@@ -0,0 +1,105 @@
1
+ /** Pure attention policy shared by every inbox door. No I/O or sends. */ // What an inbox item is ABOUT — a subscription is aimed at the task or
2
+ // the venture, never at the individual letter, so this is the eid the
3
+ // watch/mute sets are asked about.
4
+ export let aboutOf = (r)=>String(r.comps.comment?.target ?? r.comps.notification?.about ?? r.comps.mail?.target ?? r.comps.knock?.target ?? '');
5
+ // Every entity this actor has said something about, split by mode.
6
+ export let subsOf = (all, actor)=>{
7
+ let watching = new Set(), muting = new Set();
8
+ let attention = new Map();
9
+ if (actor) {
10
+ for (let r of all){
11
+ let sub = r.comps.subscription;
12
+ if (!sub || String(sub.actor) != actor) continue;
13
+ let target = String(sub.target);
14
+ if (sub.mode == 'mute') muting.add(target);
15
+ if (sub.mode == 'watch') watching.add(target);
16
+ attention.set(target, r);
17
+ }
18
+ }
19
+ return {
20
+ watching,
21
+ muting,
22
+ attention
23
+ };
24
+ };
25
+ // Addressed to this reader — the four doors an item reaches attention
26
+ // through: a comment on work it claims or on the session itself, a knock aimed
27
+ // at the session or its actor, or mail that ARRIVED
28
+ // (message_id is the inbound mark; sent mail carries none). One predicate,
29
+ // so the digest, the TUI, and the web read the SAME inbox.
30
+ export let addressed = (who)=>(r)=>{
31
+ let c = r.comps.comment;
32
+ if (c) {
33
+ let t = String(c.target ?? '');
34
+ // Said TO the actor, not just to one of its sessions: an operator loop
35
+ // outlives the session that happened to be running when someone spoke
36
+ // to the venture, so a comment on P-19 must reach whoever runs P-19 —
37
+ // it was unheard by anyone otherwise. Gated on `operator` exactly like
38
+ // the actor knock below, so a specialist still hears only direct
39
+ // address and its own claimed work.
40
+ return t == who.session || !!who.claims?.has(t) || who.operator == true && !!who.actor && t == who.actor;
41
+ }
42
+ // A notification was emitted, not said: it reaches whoever its `to`
43
+ // names, the session or the actor, and for an operator loop the project it
44
+ // stands in, which is everyone there.
45
+ if (r.comps.notification) {
46
+ let t = String(r.comps.notification.to ?? '');
47
+ return !!t && (t == who.session || t == who.actor || who.operator == true && t == who.scope);
48
+ }
49
+ let k = r.comps.knock;
50
+ if (k) {
51
+ // WHO the knock is for rides the shared `deliver {to}` facet now.
52
+ let t = String(r.comps.deliver?.to ?? '');
53
+ return !!t && (t == who.session || who.operator == true && t == who.actor);
54
+ }
55
+ let m = r.comps.mail;
56
+ if (m) {
57
+ // An arrival, never a letter still going out — message_id is the
58
+ // inbound mark, and it screens both arms below.
59
+ if (!m.message_id) return false;
60
+ // A letter to your SESSION is direct address, so it lands whatever loop
61
+ // you run — the same rule the comment and knock arms above already
62
+ // follow. Sessions are addressable by id (`S-31@<fleet domain>`), and
63
+ // gating that on `operator` would resolve the
64
+ // address perfectly and then tell nobody.
65
+ if (who.session && String(m.target) == who.session) return true;
66
+ // Project mail reaches only the operator loop, never a specialist.
67
+ if (who.operator != true) return false;
68
+ // Two ways a letter is yours, and the FIRST is what a person has: it
69
+ // was sent to an address you answer to. A person stands in no project,
70
+ // so the scope arm says nothing about them — and a reader with neither
71
+ // arm matches NOTHING rather than the fleet's whole correspondence
72
+ // (1338 arrived letters in a week: the wrong default is a firehose,
73
+ // not an inconvenience).
74
+ return !!who.addrs?.size && who.addrs.has(String(m.to ?? '')) || !!who.scope && String(m.target) == who.scope;
75
+ }
76
+ return false;
77
+ };
78
+ // The reader an inbox reads for, resolved from the graph in one place:
79
+ // the session named, the actor it acts for, the project it stands in, and
80
+ // the eids it claims — everything addressed() needs.
81
+ // Every address an actor answers to: the address book entry it carries,
82
+ // and its own eid — a letter names its recipient by reference and only
83
+ // resolves to an address at delivery (M-4063), so both forms appear in the
84
+ // stored row depending on when you look.
85
+ export let addrsOf = (all, actor)=>{
86
+ let out = new Set();
87
+ if (!actor) return out;
88
+ out.add(actor);
89
+ let a = all.find((r)=>r.eid == actor)?.comps.email?.address;
90
+ if (a) out.add(String(a));
91
+ return out;
92
+ };
93
+ // A person or project reading through any door. A browser has no session — its
94
+ // identity is the actor its client entity names — and a person browsing
95
+ // their own graph IS the loop, which is all `operator` has ever meant.
96
+ // No claims: leases belong to sessions, and a person holds none.
97
+ export let readerAt = (all, actor)=>({
98
+ actor,
99
+ operator: true,
100
+ claims: new Set(),
101
+ addrs: addrsOf(all, actor),
102
+ scope: all.find((r)=>r.eid == actor)?.comps.project ? actor : undefined,
103
+ ...subsOf(all, actor)
104
+ });
105
+ //# sourceMappingURL=reader.js.map
package/reader.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sources":["./reader.ts"],"names":[],"mappings":"AAAA,uEAAuE,GA+BvE,uEAAuE;AACvE,sEAAsE;AACtE,mCAAmC;AACnC,OAAO,IAAI,UAAU,CAAC,IACpB,OACE,EAAE,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,YAAY,EAAE,SAC/C,EAAE,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,KAAK,EAAE,UAAU,IACpD;AAEH,mEAAmE;AACnE,OAAO,IAAI,SAAS,CAAC,KAAY;EAK/B,IAAI,WAAW,IAAI,OAAe,SAAS,IAAI;EAC/C,IAAI,YAAY,IAAI;EACpB,IAAI,OAAO;IACT,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