@estiva-app/interop 0.39.0 → 0.41.0

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.
@@ -12,11 +12,19 @@
12
12
  * anything: it becomes an integration written against one app, which is the
13
13
  * thing the whole exercise argues against.
14
14
  */
15
- import { decodeNaddr, decodeNevent, encodeNaddr, encodeNevent, findNaddrs, pointerToAddress, referenceToPointer } from '@estiva-app/protocol';
16
- import { imetaOf, parseProfile } from '@estiva-app/protocol';
15
+ import { decodeNevent, encodeNaddr, encodeNevent, pointerToAddress, referenceToPointer } from '@estiva-app/protocol';
16
+ import { parseProfile } from '@estiva-app/protocol';
17
17
  import { MAX_FILTERS_PER_QUERY, RELAY_PAGE_CEILING } from '@estiva-app/protocol';
18
18
  import { attachmentsInDocument, BLOCK_DOCUMENT_FORMAT, CONTENT_FORMAT_TAG, imetaTag, parseBlockDocument, } from '@estiva-app/protocol';
19
19
  import { planPlaceFile, planUnlistFile } from './folders.js';
20
+ /*
21
+ SPEC §6.4's comment strength and §6.3's ordering are the conversation
22
+ package's (CON-5): one copy of each rule, read here for a file's `comments`,
23
+ `conversationsOf` and every change fold. Its `isCommentOn` is stricter than
24
+ the copy that lived here — a `kind:9` is never a comment (CON-20 migrated
25
+ them), a reply is never a root, and `ts` is trusted only inside its own second.
26
+ */
27
+ import { byOrder, isCommentOn, orderingMs } from '@estiva-app/conversation';
20
28
  /** The default: one kind:0 query, straight to the relay. */
21
29
  /**
22
30
  * How long a *name* may be believed.
@@ -247,7 +255,8 @@ function rootOf(event) {
247
255
  * on another file, a `kind:9` whose body names this one — and those are
248
256
  * *Mentioned in*, which §6.4 says MUST NOT be presented as the file's own
249
257
  * discussion. A badge counting them said "3" beside an issue with one comment.
250
- * See `isCommentOn` for the per-kind rule.
258
+ * See `@estiva-app/conversation`'s `isCommentOn` for the per-kind rule, which
259
+ * this passes the owner's declared comment kinds (§7.3).
251
260
  */
252
261
  export async function conversationsOf(files, query,
253
262
  /** Warm from the read that produced these files; see {@link ProjectionCache}. */
@@ -296,6 +305,7 @@ cache) {
296
305
  if (asked.length === 0)
297
306
  return {};
298
307
  const refOf = new Map(asked.map((a) => [a.address, a.ref]));
308
+ const kindsOf = new Map(asked.map((a) => [a.address, a.filter.kinds]));
299
309
  const conversations = {};
300
310
  for (const a of asked)
301
311
  conversations[a.ref] = [];
@@ -323,7 +333,7 @@ cache) {
323
333
  neither when it merely mentions them. `isCommentOn` is §6.4's rule.
324
334
  */
325
335
  const ref = event.tags
326
- .filter((t) => t[0] === 'a' && t[1] && refOf.has(t[1]) && isCommentOn(event, t[1]))
336
+ .filter((t) => t[0] === 'a' && t[1] && refOf.has(t[1]) && isCommentOn(event, t[1], kindsOf.get(t[1])))
327
337
  .map((t) => refOf.get(t[1]))
328
338
  .find((found) => found !== undefined);
329
339
  if (ref !== undefined) {
@@ -417,186 +427,6 @@ limit = CONVERSATION_LIMIT) {
417
427
  }
418
428
  return { roots, replies };
419
429
  }
420
- /**
421
- * How many targets a reaction read asks about — SPEC §6.6, decided by CON-1.
422
- *
423
- * A `kind:7` carries no `h` and no `a`, so reactions are found only by asking
424
- * for the ids on screen, and the number asked for is a horizon every reader
425
- * shares: two apps with different N disagree about a count, legitimately and
426
- * unfixably. The value is the specification's, not this package's.
427
- */
428
- export const REACTION_HORIZON = 100;
429
- /** The three kinds a comment's decorations come in. Numbers, and here for the same reason `KIND_BARE_FILE` is. */
430
- const KIND_REACTION = 7;
431
- const KIND_ASSERTION = 9101;
432
- const KIND_MESSAGE_EDIT = 40003;
433
- /**
434
- * The message a `kind:40003` edits: **the first `e` whose value is 64 hex,
435
- * marker ignored**, lowercased (SPEC §6.8, PEE-38). That is exactly the event
436
- * whose ownership the relay checked (`validate_edit_ownership`), and a reader
437
- * MUST NOT apply an edit to any other `e` — nothing refuses an edit carrying a
438
- * second one, so `['e', <own>, '', 'mention'], ['e', <victim>]` is accepted on
439
- * the writer's own message and must not be drawn on the victim's.
440
- *
441
- * Undefined when there is none, which the relay refuses; a reader holding one
442
- * anyway applies it nowhere.
443
- */
444
- export function editTargetOf(event) {
445
- const tag = event.tags.find((t) => t[0] === 'e' && typeof t[1] === 'string' && /^[0-9a-fA-F]{64}$/.test(t[1]));
446
- return tag?.[1].toLowerCase();
447
- }
448
- /** Ids per `#e` filter. A comfortable fraction of the relay's page, so one filter's answer is never cut. */
449
- const DECORATION_TARGETS_PER_FILTER = 100;
450
- /**
451
- * What has been done to a set of comments — edits, reactions, resolutions — in
452
- * one request, read by `#e`.
453
- *
454
- * **A second round trip, and that is why this is a function rather than part of
455
- * {@link resolveForeignObject}.** Everything that read returns is addressed by
456
- * `#a`, so it arrives with the root. An edit (`kind:40003`), a reaction
457
- * (`kind:7`) and a resolution (`kind:9101`) name the *comment* by `e` and not
458
- * the file, so they cannot be asked for until the comment ids are known. A
459
- * widget that never draws comments should not pay for that, so a consumer
460
- * that draws a conversation asks here with the ids it has — the roots off the
461
- * object, the replies off its thread read — and pays once for both.
462
- *
463
- * Three rules, each from the ticket that established it:
464
- *
465
- * - **Edits fold newest-wins** (CON-8). The original stays on the relay and so
466
- * does every edit; the fold is the reader's, and this is it. Attachments
467
- * fold separately (CON-5): the newest edit carrying `imeta` sets them.
468
- * - **Reactions have a horizon of {@link REACTION_HORIZON} targets** (SPEC
469
- * §6.6, CON-1) — the *newest* targets by `at`, one budget across whatever
470
- * id spaces the caller mixes, and the number left out is reported. Edits
471
- * and resolutions have no horizon: they are one event per change, not one
472
- * per reader.
473
- * - **A resolution is a `kind:9101` carrying `t=resolution`** (PEEK-128); its
474
- * `action` tag is the state, its content the rationale, and a second `e`
475
- * marked `support` names the reply that carried it.
476
- *
477
- * Nothing here checks who wrote an edit against who wrote the comment. The
478
- * relay adjudicates writes; a `40003` it stored is one it accepted — **for
479
- * the `e` it checked**, which is why an edit lands only on
480
- * {@link editTargetOf} and never on another `e` it carries.
481
- */
482
- export async function commentDecorationsOf(targets, query) {
483
- const byId = {};
484
- const unique = new Map();
485
- for (const t of targets)
486
- if (!unique.has(t.id))
487
- unique.set(t.id, t.at);
488
- for (const id of unique.keys())
489
- byId[id] = { reactions: [], resolutions: [] };
490
- if (unique.size === 0)
491
- return { byId, reactionTargetsOmitted: 0 };
492
- const ids = [...unique.keys()];
493
- // Newest first, ties on the higher id so the cut is stable between reads.
494
- const forReactions = [...unique]
495
- .sort((a, b) => b[1] - a[1] || (a[0] > b[0] ? -1 : 1))
496
- .slice(0, REACTION_HORIZON)
497
- .map(([id]) => id);
498
- const filters = [];
499
- const chunked = (list) => {
500
- const out = [];
501
- for (let i = 0; i < list.length; i += DECORATION_TARGETS_PER_FILTER) {
502
- out.push(list.slice(i, i + DECORATION_TARGETS_PER_FILTER));
503
- }
504
- return out;
505
- };
506
- for (const chunk of chunked(ids)) {
507
- filters.push({ kinds: [KIND_MESSAGE_EDIT, KIND_ASSERTION], '#e': chunk, limit: RELAY_PAGE_CEILING });
508
- }
509
- for (const chunk of chunked(forReactions)) {
510
- filters.push({ kinds: [KIND_REACTION], '#e': chunk, limit: RELAY_PAGE_CEILING });
511
- }
512
- const seen = new Set();
513
- const edits = new Map();
514
- const bodies = new Map();
515
- for (const t of targets)
516
- if (t.body !== undefined && !bodies.has(t.id))
517
- bodies.set(t.id, t.body);
518
- for (let start = 0; start < filters.length; start += MAX_FILTERS_PER_QUERY) {
519
- const events = await query(filters.slice(start, start + MAX_FILTERS_PER_QUERY));
520
- for (const event of events) {
521
- if (seen.has(event.id))
522
- continue;
523
- seen.add(event.id);
524
- /*
525
- An edit's target is the one the relay checked ownership of, and no
526
- other (SPEC §6.8, PEE-38): see {@link editTargetOf}. For the rest, the
527
- `e` that names one of *our* targets — a resolution carries a second `e`
528
- for its supporting reply, so its first `e` is not necessarily the target.
529
- `hasOwn`, not `in`: an `e` of `constructor` is anybody's to write, and
530
- `in` finds it on the prototype.
531
- */
532
- const ours = (id) => id !== undefined && Object.hasOwn(byId, id);
533
- const target = event.kind === KIND_MESSAGE_EDIT
534
- ? editTargetOf(event)
535
- : event.tags.find((t) => t[0] === 'e' && ours(t[1]) && !t[3])?.[1];
536
- if (!ours(target))
537
- continue;
538
- const into = byId[target];
539
- if (event.kind === KIND_MESSAGE_EDIT) {
540
- edits.set(target, [...(edits.get(target) ?? []), event]);
541
- }
542
- else if (event.kind === KIND_REACTION) {
543
- if (!forReactions.includes(target))
544
- continue;
545
- into.reactions.push({ id: event.id, emoji: event.content, by: event.pubkey, at: event.created_at });
546
- }
547
- else if (event.kind === KIND_ASSERTION) {
548
- if (tagValue(event, 't') !== 'resolution')
549
- continue;
550
- const action = tagValue(event, 'action');
551
- if (action !== 'resolved' && action !== 'reopened')
552
- continue;
553
- const support = event.tags.find((t) => t[0] === 'e' && t[3] === 'support')?.[1];
554
- into.resolutions.push({
555
- id: event.id,
556
- action,
557
- by: event.pubkey,
558
- at: event.created_at,
559
- ...(event.content ? { message: event.content } : {}),
560
- ...(support ? { supportingEventId: support } : {}),
561
- });
562
- }
563
- }
564
- }
565
- for (const [target, list] of edits) {
566
- const ordered = [...list].sort(byOrder);
567
- const into = byId[target];
568
- const newest = ordered[ordered.length - 1];
569
- let body = bodies.get(target);
570
- if (body === undefined) {
571
- into.edit = { body: newest.content, at: newest.created_at, by: newest.pubkey };
572
- }
573
- else {
574
- // Replayed from the target's own body, so "byte-identical to the body it
575
- // replaces" is judged against the body as it then stood.
576
- let changed;
577
- for (const edit of ordered) {
578
- if (edit.content !== body)
579
- changed = edit;
580
- body = edit.content;
581
- }
582
- if (changed)
583
- into.edit = { body: newest.content, at: changed.created_at, by: changed.pubkey };
584
- }
585
- for (let i = ordered.length - 1; i >= 0; i--) {
586
- const set = imetaOf(ordered[i]);
587
- if (set.length > 0) {
588
- into.attachments = set;
589
- break;
590
- }
591
- }
592
- }
593
- const oldestFirst = (a, b) => a.at - b.at || (a.id < b.id ? -1 : 1);
594
- for (const decoration of Object.values(byId)) {
595
- decoration.reactions.sort(oldestFirst);
596
- decoration.resolutions.sort(oldestFirst);
597
- }
598
- return { byId, reactionTargetsOmitted: ids.length - forReactions.length };
599
- }
600
430
  export const ACTION_EFFECTS = ['safe', 'writes', 'destructive'];
601
431
  /** The declared format, when it is one this version writes. */
602
432
  function proseFormatOf(declared) {
@@ -794,52 +624,6 @@ export function folderOf(root) {
794
624
  * answered the way the relay answered it.
795
625
  */
796
626
  const hasTagValue = (e, name, value) => e.tags.some((t) => t[0] === name && t[1] === value);
797
- /** The addresses a body names by `nostr:naddr…`; a pointer that will not decode is prose. */
798
- function namedInBody(body) {
799
- const addresses = new Set();
800
- for (const naddr of findNaddrs(body)) {
801
- try {
802
- addresses.add(pointerToAddress(decodeNaddr(naddr)));
803
- }
804
- catch {
805
- // A malformed pointer is prose.
806
- }
807
- }
808
- return addresses;
809
- }
810
- /**
811
- * Is this event a *comment* on the address, rather than a message elsewhere
812
- * that merely names it?
813
- *
814
- * Both arrive by the object's `#a` read — the `a` tag is the index of every
815
- * reference, whichever strength — and SPEC §6.4 says an app MUST NOT present
816
- * the two as one list: a comment is the object's own discussion, a mention is
817
- * *Mentioned in*. Until CON-15 this package handed the raw `#a` union to
818
- * {@link resolveForeignObject}'s `comments` and {@link conversationsOf}, and
819
- * a widget said "3" beside an issue with one comment and two mentions. The
820
- * rule is §6.4's per-tag one, applied per kind (CON-13, CON-14):
821
- *
822
- * - A `kind:1111`'s uppercase `A` is the comment — NIP-22's thread root. One
823
- * whose `A` is another file is that file's conversation; its `a` for this
824
- * one is the index of a reference. One with no `A` at all is read by its
825
- * `a`, the way §6.4 says to read it rather than drop the thread.
826
- * - Any other comment kind has no `A`, so its `a` is read against its body.
827
- * A `kind:9` whose body names the address is the index of that reference —
828
- * what Peek writes for every `[`-menu reference in a topic message — and a
829
- * mention. One whose body does not is the anchor of a comment written
830
- * before REW-10 moved comments to `1111`, which is not replaceable and so
831
- * reads as a comment for good.
832
- *
833
- * `commentDecorationsOf` is deliberately not behind this: a reaction or a
834
- * status on a comment is about the *comment*, whatever that comment is about.
835
- */
836
- function isCommentOn(event, address) {
837
- if (event.kind === KIND_COMMENT) {
838
- const roots = event.tags.filter((t) => t[0] === 'A' && t[1]);
839
- return roots.length > 0 ? roots.some((t) => t[1] === address) : hasTagValue(event, 'a', address);
840
- }
841
- return hasTagValue(event, 'a', address) && !namedInBody(event.content).has(address);
842
- }
843
627
  /**
844
628
  * A manifest event's `content`, or null when it is not parseable JSON.
845
629
  *
@@ -1172,6 +956,7 @@ entity = 'naddr') {
1172
956
  async function throughCache(cache, key, read) {
1173
957
  const now = Date.now();
1174
958
  const memo = cache?.lookup(key, now);
959
+ // Each key is written by one reader, so what it holds is that reader's `T`.
1175
960
  if (memo)
1176
961
  return memo.value;
1177
962
  if (!cache)
@@ -1340,31 +1125,116 @@ async function resolveManifestUncached(pointer, query) {
1340
1125
  return null;
1341
1126
  }
1342
1127
  /**
1343
- * Ordering key for an append-only event, per the manifest's `records.order`.
1344
- *
1345
- * The manifest declares `["ts", "created_at", "id"]` and, crucially, the
1346
- * condition under which `ts` may be believed: only when it agrees with
1347
- * `created_at` to the second. `created_at` has one-second resolution and the
1348
- * relay validates it, so a `ts` pinned inside that second inherits that
1349
- * validation and can only refine ordering *within* it.
1350
- *
1351
- * Peek enforces that bound itself rather than trusting the writer. Under the
1352
- * honour-system model nothing validates these events (RFC_UPDATES.md §3), so a
1353
- * buggy or pushy client claiming a far-future `ts` would otherwise win every
1354
- * fold forever — in Peek's rendering as much as in the owning app's.
1128
+ * Every app that declares a way to **create one of its own kinds on this one**
1129
+ * — MAN-8.
1130
+ *
1131
+ * {@link resolveManifest} answers with one manifest per kind, its owner's, and
1132
+ * the object's actions came from it alone. So an action one app declares on a
1133
+ * kind another app owns was on the relay and unreachable: Ship's `add-project`
1134
+ * says `appliesTo: "39000"`, a Folder is Peek's, and a Folder resolved with
1135
+ * Peek's `start-a-conversation` and nothing else. Measured on production
1136
+ * 2026-09-30 with Peek's own code.
1137
+ *
1138
+ * **Only a creation, and only of a kind the declaring app projects.** That is
1139
+ * the whole of what one app may say about another's kind: "one of mine can be
1140
+ * made here". A field it sets, a comment, a deletion are the owner's to
1141
+ * declare — the owner's `records` rule folds them, and a stranger declaring
1142
+ * `archived` on a Folder would be offering a change nobody folds as it says.
1143
+ * A creation needs nothing from the owner but an object to be made on, and
1144
+ * what it makes is drawn by the app that declared it.
1145
+ *
1146
+ * One read for every kind, the sweep {@link resolveAspectApp} already makes,
1147
+ * because nothing can ask for it by kind: a manifest's `k` tags name what it
1148
+ * draws, and Ship does not draw a Folder. Newest first, and **one manifest per
1149
+ * created kind**: an older manifest declaring the same kind on the same target
1150
+ * is a stale copy of the same claim, and offering both is two "New project"
1151
+ * rows. The owner is filtered out later ({@link borrowedFrom}), because who the
1152
+ * owner is depends on the object's author and this list does not.
1355
1153
  */
1356
- function orderingMs(event) {
1357
- const raw = Number.parseInt(tagValue(event, 'ts') ?? '', 10);
1358
- if (Number.isFinite(raw) && Math.abs(Math.floor(raw / 1000) - event.created_at) <= 1)
1359
- return raw;
1360
- return event.created_at * 1000;
1154
+ async function creatorsOn(kind, query, cache) {
1155
+ return throughCache(cache, `creators:${kind}`, async () => {
1156
+ const handlers = await query([{ kinds: [KIND_HANDLER_INFORMATION], limit: HANDLER_SWEEP_LIMIT }]);
1157
+ const creators = [];
1158
+ const claimed = new Set();
1159
+ for (const candidate of [...handlers].sort((a, b) => b.created_at - a.created_at)) {
1160
+ const manifest = parseManifest(candidate);
1161
+ if (!manifest)
1162
+ continue;
1163
+ const makes = (manifest.actions ?? []).filter((action) => isCreationAction(action) &&
1164
+ asArray(action.appliesTo).includes(String(kind)) &&
1165
+ !!manifest.projections?.[String(action.emits.kind)] &&
1166
+ !claimed.has(action.emits.kind));
1167
+ if (makes.length === 0)
1168
+ continue;
1169
+ for (const action of makes)
1170
+ claimed.add(action.emits.kind);
1171
+ creators.push({
1172
+ // Only the creations: this manifest is what a consumer acts with, and
1173
+ // nothing it was not offered for must be buildable with it.
1174
+ manifest: { ...manifest, actions: makes },
1175
+ address: `${candidate.kind}:${candidate.pubkey}:${tagValue(candidate, 'd') ?? ''}`,
1176
+ viaRecommendation: false,
1177
+ webTemplate: webTemplate(candidate, 'naddr'),
1178
+ });
1179
+ }
1180
+ return creators;
1181
+ });
1182
+ }
1183
+ /**
1184
+ * {@link creatorsOn} for a read, where a failed sweep is no borrowed actions.
1185
+ *
1186
+ * The sweep is an addition to an object, not part of it: a relay that refuses
1187
+ * it (the meter is 300 reads a minute) must not take down a card whose own
1188
+ * read succeeded. Not remembered — `throughCache` never keeps a failure — so
1189
+ * the next resolve asks again. {@link resolveActingManifest} does not use
1190
+ * this: a write that cannot find its manifest should say so, not act with none.
1191
+ */
1192
+ function creatorsOrNone(kind, query, cache) {
1193
+ return creatorsOn(kind, query, cache).catch(() => []);
1361
1194
  }
1362
- /** Total order, oldest first. Ties break on the lower event id (NIP-01's rule). */
1363
- function byOrder(a, b) {
1364
- const [at, bt] = [orderingMs(a), orderingMs(b)];
1365
- if (at !== bt)
1366
- return at - bt;
1367
- return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
1195
+ /**
1196
+ * {@link creatorsOn}, less the owner and less anything the owner makes itself.
1197
+ *
1198
+ * The owner's own actions are already on the object. And a kind the owner
1199
+ * creates here is the owner's to offer, so another manifest's claim to create
1200
+ * it — a staging copy of the same app, most likely — is dropped rather than
1201
+ * drawn as a second row.
1202
+ */
1203
+ function borrowedFrom(kind, owner, creators) {
1204
+ const ownerMakes = new Set((owner.manifest.actions ?? [])
1205
+ .filter((action) => isCreationAction(action) && asArray(action.appliesTo).includes(String(kind)))
1206
+ .map((action) => action.emits.kind));
1207
+ return creators.flatMap((creator) => {
1208
+ if (creator.address === owner.address)
1209
+ return [];
1210
+ const actions = (creator.manifest.actions ?? []).filter((action) => !ownerMakes.has(action.emits.kind));
1211
+ return actions.length ? [{ ...creator, manifest: { ...creator.manifest, actions } }] : [];
1212
+ });
1213
+ }
1214
+ /** Every borrowed creation, resolved as the owner's actions are, with its declaring app named. */
1215
+ function borrowedActions(kind, owner, creators) {
1216
+ return borrowedFrom(kind, owner, creators).flatMap((creator) => resolveActions(creator.manifest, kind, {}).map((action) => ({
1217
+ ...action,
1218
+ declaredBy: { address: creator.address, ...(creator.manifest.name ? { appName: creator.manifest.name } : {}) },
1219
+ })));
1220
+ }
1221
+ /**
1222
+ * The manifest to build an action with — the object's own, or the one named by
1223
+ * the action's {@link ResolvedAction.declaredBy} (MAN-8).
1224
+ *
1225
+ * `declaredBy` omitted, or naming the owner, is exactly {@link resolveManifest}.
1226
+ * Otherwise the answer is that manifest **only if resolving the object would
1227
+ * have offered the action from it** — the same sweep, the same filtering — and
1228
+ * null if not. So a caller cannot act on a Folder with an arbitrary manifest by
1229
+ * naming its address; it can only act with one this module found declaring a
1230
+ * creation there. The manifest returned holds only those creations.
1231
+ */
1232
+ export async function resolveActingManifest(pointer, declaredBy, query, cache) {
1233
+ const owner = await resolveManifest(pointer, query, cache);
1234
+ if (!owner || !declaredBy || declaredBy === owner.address)
1235
+ return owner;
1236
+ const creators = await creatorsOn(pointer.kind, query, cache);
1237
+ return borrowedFrom(pointer.kind, owner, creators).find((creator) => creator.address === declaredBy) ?? null;
1368
1238
  }
1369
1239
  /** Replay change events into current field values. Last write wins per field. */
1370
1240
  /**
@@ -2079,14 +1949,27 @@ cache, options = {}) {
2079
1949
  const plan = planObject(naddr, pointer, resolved, depth);
2080
1950
  if (!plan)
2081
1951
  return null;
2082
- const answered = await query(plan.filters);
1952
+ // Beside the object's own read, not after it: the sweep is cached, and cold
1953
+ // it would otherwise add a round trip to every resolve that pays for it.
1954
+ const [answered, creators] = await Promise.all([query(plan.filters), creatorsOrNone(pointer.kind, query, cache)]);
2083
1955
  const followUp = childChangeFilters(plan, answered);
2084
1956
  const assembled = assembleObject(plan, answered, followUp.length ? await queryChunked(followUp, query) : []);
2085
1957
  if (assembled.object.unreachable)
2086
1958
  return assembled.object;
2087
1959
  if (options.archivedWith)
2088
1960
  await markArchivedParents([{ object: assembled.object, manifest: resolved.manifest }], query);
2089
- return withPeople(assembled, await (lookupPeople ?? peopleViaRelay(query))(peopleOf(assembled)));
1961
+ return withBorrowed(withPeople(assembled, await (lookupPeople ?? peopleViaRelay(query))(peopleOf(assembled))), borrowedActions(pointer.kind, resolved, creators));
1962
+ }
1963
+ /**
1964
+ * The object's own actions, then the ones other apps declare on it (MAN-8).
1965
+ *
1966
+ * The object's only, not its children's: a child is drawn inside its parent's
1967
+ * card, and a creation offered on every issue in a project's list is a form
1968
+ * nobody opens from there. An unreachable object gets none either — it has no
1969
+ * Folder to create anything in.
1970
+ */
1971
+ function withBorrowed(object, borrowed) {
1972
+ return borrowed.length ? { ...object, actions: [...object.actions, ...borrowed] } : object;
2090
1973
  }
2091
1974
  /**
2092
1975
  * Many addressed objects in one round trip — PER-10.
@@ -2168,7 +2051,14 @@ cache, options = {}) {
2168
2051
  planned.add(plan.address);
2169
2052
  filters.push(...plan.filters);
2170
2053
  }
2171
- const events = await queryChunked(filters, query);
2054
+ // Who else creates on each kind in the set (MAN-8): one sweep per kind, not
2055
+ // per object, read beside the objects themselves.
2056
+ const kinds = [...new Set(plans.map(({ plan }) => plan.pointer.kind))];
2057
+ const [events, creatorLists] = await Promise.all([
2058
+ queryChunked(filters, query),
2059
+ Promise.all(kinds.map((kind) => creatorsOrNone(kind, query, cache))),
2060
+ ]);
2061
+ const creatorsByKind = new Map(kinds.map((kind, i) => [kind, creatorLists[i]]));
2172
2062
  // Every card's children's changes in one more read for the whole set, not
2173
2063
  // one per card (MAN-7) — and none at all when no card has a fold to read.
2174
2064
  const followUp = [];
@@ -2191,7 +2081,7 @@ cache, options = {}) {
2191
2081
  const wanted = [...new Set(assembled.flatMap(({ built }) => peopleOf(built)))];
2192
2082
  const reachable = assembled.some(({ built }) => !built.object.unreachable);
2193
2083
  const people = reachable ? await (lookupPeople ?? peopleViaRelay(query))(wanted) : {};
2194
- for (const { reference, built } of assembled) {
2084
+ for (const { reference, plan, built } of assembled) {
2195
2085
  if (built.object.unreachable) {
2196
2086
  results[reference] = built.object;
2197
2087
  continue;
@@ -2203,7 +2093,7 @@ cache, options = {}) {
2203
2093
  for (const key of peopleOf(built))
2204
2094
  if (key in people)
2205
2095
  own[key] = people[key];
2206
- results[reference] = withPeople(built, own);
2096
+ results[reference] = withBorrowed(withPeople(built, own), borrowedActions(plan.pointer.kind, plan.resolved, creatorsByKind.get(plan.pointer.kind) ?? []));
2207
2097
  }
2208
2098
  return results;
2209
2099
  }
@@ -2396,10 +2286,10 @@ function assembleObject(plan, answered, childChanges = []) {
2396
2286
 
2397
2287
  Then narrowed to §6.4's *comment* strength (CON-15): the `a` tag is also the
2398
2288
  index of a mention, and a mention is not this object's discussion. See
2399
- `isCommentOn` for the per-kind rule.
2289
+ `isCommentOn` (`@estiva-app/conversation`) for the per-kind rule.
2400
2290
  */
2401
2291
  const comments = events
2402
- .filter((e) => commentKinds.includes(e.kind) && isCommentOn(e, address))
2292
+ .filter((e) => commentKinds.includes(e.kind) && isCommentOn(e, address, commentKinds))
2403
2293
  .sort(byOrder)
2404
2294
  .map((e) => ({ id: e.id, author: e.pubkey, body: e.content, createdAt: e.created_at }));
2405
2295
  const object = buildObject({