instar 1.3.2004 → 1.3.2006

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 (120) hide show
  1. package/dashboard/console/work-model.js +2 -7
  2. package/dashboard/console/work.js +11 -4
  3. package/dist/core/AppConversationStore.d.ts +2 -0
  4. package/dist/core/AppConversationStore.d.ts.map +1 -1
  5. package/dist/core/AppConversationStore.js +6 -2
  6. package/dist/core/AppConversationStore.js.map +1 -1
  7. package/dist/core/ChiefOfStaffPrSearch.d.ts +92 -0
  8. package/dist/core/ChiefOfStaffPrSearch.d.ts.map +1 -0
  9. package/dist/core/ChiefOfStaffPrSearch.js +295 -0
  10. package/dist/core/ChiefOfStaffPrSearch.js.map +1 -0
  11. package/dist/core/ConversationUnreadService.d.ts +2 -0
  12. package/dist/core/ConversationUnreadService.d.ts.map +1 -1
  13. package/dist/core/ConversationUnreadService.js +3 -1
  14. package/dist/core/ConversationUnreadService.js.map +1 -1
  15. package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
  16. package/dist/core/PostUpdateMigrator.js +17 -18
  17. package/dist/core/PostUpdateMigrator.js.map +1 -1
  18. package/dist/core/WorkBoardPickupController.d.ts +1 -1
  19. package/dist/core/WorkBoardPickupController.d.ts.map +1 -1
  20. package/dist/core/WorkBoardPickupController.js +2 -2
  21. package/dist/core/WorkBoardPickupController.js.map +1 -1
  22. package/dist/core/WorkBoardRuntime.d.ts +3 -1
  23. package/dist/core/WorkBoardRuntime.d.ts.map +1 -1
  24. package/dist/core/WorkBoardRuntime.js +21 -4
  25. package/dist/core/WorkBoardRuntime.js.map +1 -1
  26. package/dist/core/WorkBoardService.d.ts +1 -1
  27. package/dist/core/WorkBoardService.d.ts.map +1 -1
  28. package/dist/core/WorkBoardService.js +3 -3
  29. package/dist/core/WorkBoardService.js.map +1 -1
  30. package/dist/core/WorkCardStore.d.ts +2 -0
  31. package/dist/core/WorkCardStore.d.ts.map +1 -1
  32. package/dist/core/WorkCardStore.js +18 -0
  33. package/dist/core/WorkCardStore.js.map +1 -1
  34. package/dist/core/githubRuntime.d.ts +6 -0
  35. package/dist/core/githubRuntime.d.ts.map +1 -1
  36. package/dist/core/githubRuntime.js +74 -6
  37. package/dist/core/githubRuntime.js.map +1 -1
  38. package/dist/core/workBoardViews.d.ts +6 -4
  39. package/dist/core/workBoardViews.d.ts.map +1 -1
  40. package/dist/core/workBoardViews.js +13 -8
  41. package/dist/core/workBoardViews.js.map +1 -1
  42. package/dist/core/workFrontDoorsGraph.d.ts +1 -1
  43. package/dist/core/workFrontDoorsGraph.d.ts.map +1 -1
  44. package/dist/core/workFrontDoorsGraph.js +2 -2
  45. package/dist/core/workFrontDoorsGraph.js.map +1 -1
  46. package/dist/core/workSourceCards.js +2 -2
  47. package/dist/core/workSourceCards.js.map +1 -1
  48. package/dist/data/standards-guard-index.json +1 -1
  49. package/dist/data/standards-guard-index.meta.json +2 -2
  50. package/dist/data/standards-registry.meta.json +1 -1
  51. package/dist/memory/MemoryIndex.d.ts.map +1 -1
  52. package/dist/memory/MemoryIndex.js +2 -12
  53. package/dist/memory/MemoryIndex.js.map +1 -1
  54. package/dist/memory/SemanticMemory.d.ts.map +1 -1
  55. package/dist/memory/SemanticMemory.js +3 -33
  56. package/dist/memory/SemanticMemory.js.map +1 -1
  57. package/dist/memory/TopicMemory.d.ts.map +1 -1
  58. package/dist/memory/TopicMemory.js +2 -11
  59. package/dist/memory/TopicMemory.js.map +1 -1
  60. package/dist/memory/ftsQueryTerms.d.ts +5 -0
  61. package/dist/memory/ftsQueryTerms.d.ts.map +1 -0
  62. package/dist/memory/ftsQueryTerms.js +12 -0
  63. package/dist/memory/ftsQueryTerms.js.map +1 -0
  64. package/dist/native/InstarWedgeCanary.app/Contents/MacOS/InstarWedgeCanary +0 -0
  65. package/dist/native/instar-desktop-host +0 -0
  66. package/dist/scaffold/conversationSearchGuidance.d.ts +10 -0
  67. package/dist/scaffold/conversationSearchGuidance.d.ts.map +1 -0
  68. package/dist/scaffold/conversationSearchGuidance.js +49 -0
  69. package/dist/scaffold/conversationSearchGuidance.js.map +1 -0
  70. package/dist/scaffold/templates.d.ts.map +1 -1
  71. package/dist/scaffold/templates.js +8 -13
  72. package/dist/scaffold/templates.js.map +1 -1
  73. package/dist/server/AgentServer.d.ts.map +1 -1
  74. package/dist/server/AgentServer.js +31 -3
  75. package/dist/server/AgentServer.js.map +1 -1
  76. package/dist/server/ConversationGraphSurface.d.ts +1 -0
  77. package/dist/server/ConversationGraphSurface.d.ts.map +1 -1
  78. package/dist/server/ConversationGraphSurface.js +7 -0
  79. package/dist/server/ConversationGraphSurface.js.map +1 -1
  80. package/dist/server/chiefOfStaffPrSearchRoutes.d.ts +9 -0
  81. package/dist/server/chiefOfStaffPrSearchRoutes.d.ts.map +1 -0
  82. package/dist/server/chiefOfStaffPrSearchRoutes.js +39 -0
  83. package/dist/server/chiefOfStaffPrSearchRoutes.js.map +1 -0
  84. package/dist/server/conversationGraphViewer.d.ts +2 -0
  85. package/dist/server/conversationGraphViewer.d.ts.map +1 -1
  86. package/dist/server/conversationGraphViewer.js +3 -2
  87. package/dist/server/conversationGraphViewer.js.map +1 -1
  88. package/dist/server/conversationMeaningSearch.d.ts.map +1 -1
  89. package/dist/server/conversationMeaningSearch.js +3 -1
  90. package/dist/server/conversationMeaningSearch.js.map +1 -1
  91. package/dist/server/mobileConversationRoutes.d.ts.map +1 -1
  92. package/dist/server/mobileConversationRoutes.js +202 -176
  93. package/dist/server/mobileConversationRoutes.js.map +1 -1
  94. package/dist/server/mobileConversationSearchRoutes.d.ts.map +1 -1
  95. package/dist/server/mobileConversationSearchRoutes.js +96 -87
  96. package/dist/server/mobileConversationSearchRoutes.js.map +1 -1
  97. package/dist/server/routes.d.ts.map +1 -1
  98. package/dist/server/routes.js +8 -0
  99. package/dist/server/routes.js.map +1 -1
  100. package/dist/server/workBoardRoutes.d.ts +2 -0
  101. package/dist/server/workBoardRoutes.d.ts.map +1 -1
  102. package/dist/server/workBoardRoutes.js +11 -4
  103. package/dist/server/workBoardRoutes.js.map +1 -1
  104. package/package.json +1 -1
  105. package/src/data/awareness/agent-work-cards.md +1 -1
  106. package/src/data/awareness/chief-of-staff-find-prior-work.md +11 -0
  107. package/src/data/builtin-manifest.json +66 -66
  108. package/src/data/standards-guard-index.json +1 -1
  109. package/src/data/standards-guard-index.meta.json +2 -2
  110. package/src/data/standards-registry.meta.json +1 -1
  111. package/src/scaffold/conversationSearchGuidance.ts +57 -0
  112. package/src/scaffold/templates.ts +8 -13
  113. package/upgrades/1.3.2005.md +20 -0
  114. package/upgrades/1.3.2006.md +38 -0
  115. package/upgrades/eli16/conversation-search-pointers.md +7 -0
  116. package/upgrades/side-effects/chief-of-staff-pr-discovery.md +87 -0
  117. package/upgrades/side-effects/chief-of-staff-pr-public-visibility.md +7 -0
  118. package/upgrades/side-effects/conversation-search-pointers.md +13 -0
  119. package/upgrades/side-effects/internal-work-owner-surfaces.eli16.md +9 -0
  120. package/upgrades/side-effects/internal-work-owner-surfaces.md +72 -0
@@ -580,7 +580,11 @@ export function createMobileConversationRouter(deps) {
580
580
  out.push({ id: x.conversationKey, platform: 'app', title: x.title, lastActivity: x.lastActivity ?? x.createdAt, lastPreview: null, ...(x.ownerPerson ? { ownerPerson: x.ownerPerson } : {}) });
581
581
  }
582
582
  }
583
- catch { /* @silent-fallback-ok — the flag is a hint; a failed read leaves it false */ }
583
+ catch (error) {
584
+ if (error instanceof Error && error.message === 'work-card-visibility-unavailable')
585
+ throw error;
586
+ // @silent-fallback-ok: an ordinary history read failure leaves this optional hint false.
587
+ }
584
588
  try {
585
589
  for (const t of deps.telegramTopics?.() ?? []) {
586
590
  const r = { id: t.topicId, platform: 'telegram', title: t.topicName, lastActivity: t.lastActivity, lastPreview: null };
@@ -675,190 +679,212 @@ export function createMobileConversationRouter(deps) {
675
679
  res.json({ dryRun: true, canApply: false, rows, nextCursor: page.nextCursor });
676
680
  });
677
681
  router.get('/mobile/conversations', async (req, res) => {
678
- if (!readGate(req, res))
679
- return;
680
- if (req.query.scope !== undefined && req.query.scope !== 'pool') {
681
- res.status(400).json({ error: 'invalid-scope' });
682
- return;
683
- }
684
- const limit = Math.max(1, Math.min(200, Number(req.query.limit) || 50));
685
- const cursor = typeof req.query.cursor === 'string' ? req.query.cursor : null;
686
- const local = localListPage(limit, cursor);
687
- const ownerNote = local.slackOwnerUnset && deviceMayUse(deps.pairing, req, 'slack:') ? { slackOwnerUnset: true } : {};
688
- // People and roles §3.4: an MSP phone sees Telegram topics and its own app conversations only
689
- // (filtered after the merge, so the cursor still advances over rows it does not see).
690
- const person = devicePersonOf(req);
691
- /** A team phone's list line is the newest message it may read, so a held one is not shown there. */
692
- const shownPreview = (r) => {
693
- if (person?.role !== 'team' || r.platform !== 'app')
694
- return r;
695
- const newest = svc.store.browseMessages(String(r.id), null, 100).messages.filter((m) => deps.pairing.mayReadStored(person, String(r.id), m)).pop();
696
- return { ...r, lastPreview: newest ? messagePreview(newest) : null };
697
- };
698
- const visible = (rows) => rows.filter((r) => {
699
- if (r.platform === 'telegram')
700
- return deviceMayUse(deps.pairing, req, `telegram:${String(r.id)}`);
701
- if (r.platform === 'slack')
702
- return deviceMayUse(deps.pairing, req, 'slack:');
703
- return deviceMayUse(deps.pairing, req, String(r.id));
704
- }).map(shownPreview);
705
- // Unread (§3.5): read fields for a reader on every visible row, the page total, and whether
706
- // anything after the page is unread. A Bearer read without a forwarded reader gets none.
707
- const unread = unreadOn();
708
- const reader = readerOf(req);
709
- if (unread && reader)
710
- unread.touchBaseline(reader);
711
- const self = deps.machineId();
712
- const strip = (r) => { const { hasUnread: _h, unreadCount: _c, unreadMore: _m, readUpTo: _r, ...rest } = r; return rest; };
713
- const withFields = (rows, keepPeerTelegram) => rows.map((r) => {
714
- if (!unread || !reader)
715
- return strip(r);
716
- // App rows are counted here (every machine holds every app conversation); a Telegram row keeps
717
- // the count of the machine that listed it; a Slack row is always this machine's.
718
- if (keepPeerTelegram && r.platform === 'telegram' && r.machine && r.machine !== self)
719
- return r;
720
- const f = unread.rowFields(reader, r);
721
- return f ? { ...strip(r), ...unreadOut(f) } : strip(r);
722
- });
723
- const totals = (rows, beyond) => {
724
- if (!unread || !reader)
725
- return {};
726
- let unreadTotal = 0;
727
- let unreadTotalMore = false;
728
- for (const r of rows) {
729
- if (r.unreadCount !== undefined)
730
- unreadTotal += r.unreadCount;
731
- else if (r.hasUnread)
732
- unreadTotalMore = true;
733
- if (r.unreadMore)
734
- unreadTotalMore = true;
682
+ try {
683
+ if (!readGate(req, res))
684
+ return;
685
+ if (req.query.scope !== undefined && req.query.scope !== 'pool') {
686
+ res.status(400).json({ error: 'invalid-scope' });
687
+ return;
735
688
  }
736
- return { unreadTotal, unreadTotalMore, unreadBeyondPage: beyond };
737
- };
738
- const beyondLocal = (page, more) => {
739
- if (!unread || !reader || !more)
740
- return false;
741
- const last = page[page.length - 1];
742
- return visible(localRowsAfter(last ? listCursorFor(last) : cursor)).some((r) => {
743
- const f = unread.rowFields(reader, { ...r, lastActivity: r.lastActivity });
744
- return !!f && f.hasUnread;
689
+ const limit = Math.max(1, Math.min(200, Number(req.query.limit) || 50));
690
+ const cursor = typeof req.query.cursor === 'string' ? req.query.cursor : null;
691
+ const local = localListPage(limit, cursor);
692
+ const ownerNote = local.slackOwnerUnset && deviceMayUse(deps.pairing, req, 'slack:') ? { slackOwnerUnset: true } : {};
693
+ // People and roles §3.4: an MSP phone sees Telegram topics and its own app conversations only
694
+ // (filtered after the merge, so the cursor still advances over rows it does not see).
695
+ const person = devicePersonOf(req);
696
+ /** A team phone's list line is the newest message it may read, so a held one is not shown there. */
697
+ const shownPreview = (r) => {
698
+ if (person?.role !== 'team' || r.platform !== 'app')
699
+ return r;
700
+ const newest = svc.store.browseMessages(String(r.id), null, 100).messages.filter((m) => deps.pairing.mayReadStored(person, String(r.id), m)).pop();
701
+ return { ...r, lastPreview: newest ? messagePreview(newest) : null };
702
+ };
703
+ const visible = (rows) => rows.filter((r) => {
704
+ if (r.platform === 'telegram')
705
+ return deviceMayUse(deps.pairing, req, `telegram:${String(r.id)}`);
706
+ if (r.platform === 'slack')
707
+ return deviceMayUse(deps.pairing, req, 'slack:');
708
+ return !svc.store.isHiddenConversation?.(String(r.id)) && deviceMayUse(deps.pairing, req, String(r.id));
709
+ }).map(shownPreview);
710
+ // Unread (§3.5): read fields for a reader on every visible row, the page total, and whether
711
+ // anything after the page is unread. A Bearer read without a forwarded reader gets none.
712
+ const unread = unreadOn();
713
+ const reader = readerOf(req);
714
+ if (unread && reader)
715
+ unread.touchBaseline(reader);
716
+ const self = deps.machineId();
717
+ const strip = (r) => { const { hasUnread: _h, unreadCount: _c, unreadMore: _m, readUpTo: _r, ...rest } = r; return rest; };
718
+ const withFields = (rows, keepPeerTelegram) => rows.map((r) => {
719
+ if (!unread || !reader)
720
+ return strip(r);
721
+ // App rows are counted here (every machine holds every app conversation); a Telegram row keeps
722
+ // the count of the machine that listed it; a Slack row is always this machine's.
723
+ if (keepPeerTelegram && r.platform === 'telegram' && r.machine && r.machine !== self)
724
+ return r;
725
+ const f = unread.rowFields(reader, r);
726
+ return f ? { ...strip(r), ...unreadOut(f) } : strip(r);
745
727
  });
746
- };
747
- // A peer's preview cannot be judged here, so a team phone lists what this machine holds.
748
- // Chief of Staff §1.4: owner-role callers get `parentConversationKey` on every row and, on the first page
749
- // (no cursor), a separate `pinned` row; everyone else gets neither. A Bearer read is the operator's own.
750
- const cosView = (person === null || person.role === 'owner') ? (deps.chiefOfStaff?.() ?? null) : null;
751
- const rowKey = (r) => (r.platform === 'app' ? `app:${String(r.id)}` : `${r.platform}:${String(r.id)}`);
752
- const scope = ownerMetadata(req) ? creationScope(req) : null;
753
- const withTree = (rows) => rows.map((r) => {
754
- if (r.platform === 'app') {
755
- const { parentConversationKey: _parent, creationSource: _source, hierarchyState: _state, ...ordinary } = r;
756
- return scope && creationProjection ? { ...ordinary, ...creationProjection.fields(String(r.id), scope) } : ordinary;
757
- }
758
- return cosView?.parents.has(rowKey(r)) ? { ...r, parentConversationKey: cosView.parents.get(rowKey(r)) ?? null } : r;
759
- });
760
- const pinnedOut = (rows) => {
761
- if (!cosView || !cosView.pinnedKey || cursor !== null)
762
- return {};
763
- const inPage = rows.find((r) => rowKey(r) === cosView.pinnedKey);
764
- const fromLocal = inPage ?? visible(localRowsAfter(null)).map((r) => ({ ...r, machine: self })).find((r) => rowKey(r) === cosView.pinnedKey);
765
- return fromLocal ? { pinned: withTree(withFields([fromLocal], false))[0] } : {};
766
- };
767
- /**
768
- * Conversation-list pins: on the first page only, for a resolvable reader, the reader's pinned refs
769
- * (newest pin first) and a full list row for each one found here or on an answering peer, so a pinned
770
- * conversation older than the page still leads the list. A ref with no row stays in `pinnedRefs` only.
771
- */
772
- const listPinsOut = (rows, peerRows) => {
773
- const store = listPinsOn();
774
- if (!store || cursor !== null)
775
- return {};
776
- const pinReader = pinReaderOf(req);
777
- if (!pinReader)
778
- return {};
779
- let refs = [];
780
- try {
781
- refs = store.pinnedFor(pinReader.key);
782
- }
783
- catch {
784
- return {};
785
- } // @silent-fallback-ok — no pin fields rather than a failed list
786
- const shown = refs.filter((p) => pinReaderMay(req, pinReader, pinAccessRef(p.ref)));
787
- const byRef = new Map();
788
- const offer = (r) => { const k = canonicalRefOfRow(r); if (k && !byRef.has(k))
789
- byRef.set(k, r); };
790
- for (const r of rows)
791
- offer(r);
792
- const missing = () => shown.some((p) => !byRef.has(p.ref));
793
- if (missing())
794
- for (const r of withTree(withFields(visible(peerRows), true)))
795
- offer(r);
796
- if (missing()) {
728
+ const totals = (rows, beyond) => {
729
+ if (!unread || !reader)
730
+ return {};
731
+ let unreadTotal = 0;
732
+ let unreadTotalMore = false;
733
+ for (const r of rows) {
734
+ if (r.unreadCount !== undefined)
735
+ unreadTotal += r.unreadCount;
736
+ else if (r.hasUnread)
737
+ unreadTotalMore = true;
738
+ if (r.unreadMore)
739
+ unreadTotalMore = true;
740
+ }
741
+ return { unreadTotal, unreadTotalMore, unreadBeyondPage: beyond };
742
+ };
743
+ const beyondLocal = (page, more) => {
744
+ if (!unread || !reader || !more)
745
+ return false;
746
+ const last = page[page.length - 1];
747
+ return visible(localRowsAfter(last ? listCursorFor(last) : cursor)).some((r) => {
748
+ const f = unread.rowFields(reader, { ...r, lastActivity: r.lastActivity });
749
+ return !!f && f.hasUnread;
750
+ });
751
+ };
752
+ // A peer's preview cannot be judged here, so a team phone lists what this machine holds.
753
+ // Chief of Staff §1.4: owner-role callers get `parentConversationKey` on every row and, on the first page
754
+ // (no cursor), a separate `pinned` row; everyone else gets neither. A Bearer read is the operator's own.
755
+ const cosView = (person === null || person.role === 'owner') ? (deps.chiefOfStaff?.() ?? null) : null;
756
+ const rowKey = (r) => (r.platform === 'app' ? `app:${String(r.id)}` : `${r.platform}:${String(r.id)}`);
757
+ const scope = ownerMetadata(req) ? creationScope(req) : null;
758
+ const withTree = (rows) => rows.map((r) => {
759
+ if (r.platform === 'app') {
760
+ const { parentConversationKey: _parent, creationSource: _source, hierarchyState: _state, ...ordinary } = r;
761
+ return scope && creationProjection ? { ...ordinary, ...creationProjection.fields(String(r.id), scope) } : ordinary;
762
+ }
763
+ return cosView?.parents.has(rowKey(r)) ? { ...r, parentConversationKey: cosView.parents.get(rowKey(r)) ?? null } : r;
764
+ });
765
+ const pinnedOut = (rows) => {
766
+ if (!cosView || !cosView.pinnedKey || cursor !== null)
767
+ return {};
768
+ const inPage = rows.find((r) => rowKey(r) === cosView.pinnedKey);
769
+ const fromLocal = inPage ?? visible(localRowsAfter(null)).map((r) => ({ ...r, machine: self })).find((r) => rowKey(r) === cosView.pinnedKey);
770
+ return fromLocal ? { pinned: withTree(withFields([fromLocal], false))[0] } : {};
771
+ };
772
+ /**
773
+ * Conversation-list pins: on the first page only, for a resolvable reader, the reader's pinned refs
774
+ * (newest pin first) and a full list row for each one found here or on an answering peer, so a pinned
775
+ * conversation older than the page still leads the list. A ref with no row stays in `pinnedRefs` only.
776
+ */
777
+ const listPinsOut = (rows, peerRows) => {
778
+ const store = listPinsOn();
779
+ if (!store || cursor !== null)
780
+ return {};
781
+ const pinReader = pinReaderOf(req);
782
+ if (!pinReader)
783
+ return {};
784
+ let refs = [];
797
785
  try {
798
- for (const r of withTree(withFields(visible(localConversationListPage(deps, 200, null).rows.map((x) => ({ ...x, machine: self }))), false)))
786
+ refs = store.pinnedFor(pinReader.key);
787
+ }
788
+ catch {
789
+ return {};
790
+ } // @silent-fallback-ok — no pin fields rather than a failed list
791
+ const shown = refs.filter((p) => !(p.ref.startsWith('app:') && svc.store.isHiddenConversation?.(p.ref)) && pinReaderMay(req, pinReader, pinAccessRef(p.ref)));
792
+ const byRef = new Map();
793
+ const offer = (r) => { const k = canonicalRefOfRow(r); if (k && !byRef.has(k))
794
+ byRef.set(k, r); };
795
+ for (const r of rows)
796
+ offer(r);
797
+ const missing = () => shown.some((p) => !byRef.has(p.ref));
798
+ if (missing())
799
+ for (const r of withTree(withFields(visible(peerRows), true)))
799
800
  offer(r);
801
+ if (missing()) {
802
+ try {
803
+ for (const r of withTree(withFields(visible(localConversationListPage(deps, 200, null).rows.map((x) => ({ ...x, machine: self }))), false)))
804
+ offer(r);
805
+ }
806
+ catch (error) {
807
+ if (error instanceof Error && error.message === 'work-card-visibility-unavailable')
808
+ throw error;
809
+ // @silent-fallback-ok: a pinned row not found stays in pinnedRefs only.
810
+ }
800
811
  }
801
- catch { /* @silent-fallback-ok — a pinned row not found stays in pinnedRefs only */ }
802
- }
803
- // An app conversation older than every page is read straight from the store (every machine holds it).
804
- for (const p of shown) {
805
- if (byRef.has(p.ref) || !p.ref.startsWith('app:'))
806
- continue;
807
- try {
808
- const c = svc.store.getConversation(p.ref.slice(4));
809
- if (!c || c.tombstoned)
812
+ // An app conversation older than every page is read straight from the store (every machine holds it).
813
+ for (const p of shown) {
814
+ if (byRef.has(p.ref) || !p.ref.startsWith('app:'))
810
815
  continue;
811
- const raw = { id: c.conversationKey, platform: 'app', title: c.title, lastActivity: c.lastActivity ?? c.createdAt, lastPreview: c.lastPreview, machine: self, ...(c.ownerPerson ? { ownerPerson: c.ownerPerson } : {}) };
812
- for (const r of withTree(withFields(visible([raw]), false)))
813
- offer(r);
816
+ try {
817
+ const c = svc.store.getConversation(p.ref.slice(4));
818
+ if (!c || c.tombstoned)
819
+ continue;
820
+ const raw = { id: c.conversationKey, platform: 'app', title: c.title, lastActivity: c.lastActivity ?? c.createdAt, lastPreview: c.lastPreview, machine: self, ...(c.ownerPerson ? { ownerPerson: c.ownerPerson } : {}) };
821
+ for (const r of withTree(withFields(visible([raw]), false)))
822
+ offer(r);
823
+ }
824
+ catch (error) {
825
+ if (error instanceof Error && error.message === 'work-card-visibility-unavailable')
826
+ throw error;
827
+ // @silent-fallback-ok: a pinned row not found stays in pinnedRefs only.
828
+ }
814
829
  }
815
- catch { /* @silent-fallback-ok — a pinned row not found stays in pinnedRefs only */ }
830
+ const pinnedRows = shown.map((p) => byRef.get(p.ref)).filter((r) => !!r);
831
+ return { pinnedRefs: shown, pinnedRows };
832
+ };
833
+ if (req.query.scope !== 'pool' || person?.role === 'team') {
834
+ const m = mergeConversationPages([local], limit);
835
+ const rows = withTree(withFields(visible(m.rows), false));
836
+ res.json({ ownerProjectionVersion: 1, conversations: rows, nextCursor: m.nextCursor, ...pinnedOut(rows), ...listPinsOut(rows, []), ...ownerNote, ...totals(rows, beyondLocal(m.rows, m.nextCursor !== null)) });
837
+ return;
816
838
  }
817
- const pinnedRows = shown.map((p) => byRef.get(p.ref)).filter((r) => !!r);
818
- return { pinnedRefs: shown, pinnedRows };
819
- };
820
- if (req.query.scope !== 'pool' || person?.role === 'team') {
821
- const m = mergeConversationPages([local], limit);
822
- const rows = withTree(withFields(visible(m.rows), false));
823
- res.json({ conversations: rows, nextCursor: m.nextCursor, ...pinnedOut(rows), ...listPinsOut(rows, []), ...ownerNote, ...totals(rows, beyondLocal(m.rows, m.nextCursor !== null)) });
824
- return;
839
+ // Pool read (§4.8): every answering machine's own page after the same cursor, merged on the
840
+ // same order (lossless), duplicates collapsed; a dark machine is a `pool.failed` row.
841
+ const readerQ = reader ? `&reader=${encodeURIComponent(reader.key)}` : '';
842
+ const q = `/mobile/conversations?limit=${limit}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}${readerQ}`;
843
+ let peerBeyond = false;
844
+ let unreadProjectionIncomplete = false;
845
+ const peers = deps.pool
846
+ ? await fetchPeers(deps.pool, q, MAX_POOL_LIST_BYTES, (body, machineId) => {
847
+ if (body.ownerProjectionVersion === 1) {
848
+ if (body.unreadBeyondPage === true)
849
+ peerBeyond = true;
850
+ }
851
+ else if (body.unreadBeyondPage === true)
852
+ unreadProjectionIncomplete = true;
853
+ return {
854
+ rows: (Array.isArray(body.conversations) ? body.conversations.slice(0, limit) : [])
855
+ .map((r) => sanitizePeerConversation(r, machineId))
856
+ .filter((r) => r !== null && isAfterListCursor(r, parseListCursor(cursor))),
857
+ more: typeof body.nextCursor === 'string' && body.nextCursor.length > 0,
858
+ };
859
+ })
860
+ : { results: [], failed: [] };
861
+ // A peer's Slack rows are never listed: a Slack conversation id is local to the machine that
862
+ // minted it, and the Slack routes on this machine look ids up here, so a peer row could name a
863
+ // different conversation that shares the number (and would otherwise collapse onto this
864
+ // machine's row of the same id). Only this machine's own Slack rows are listed.
865
+ const peerPages = peers.results.map((p) => ({ ...p, rows: p.rows.filter((r) => r.platform !== 'slack') }));
866
+ const localRows = withFields(local.rows.map((r) => ({ ...r, machine: self })), false);
867
+ const m = mergeConversationPages([{ rows: localRows, more: local.more }, ...peerPages], limit);
868
+ // A peer's app row is checked against THIS machine's copy of the conversation: one not
869
+ // replicated here yet is not shown to an MSP phone (fail closed).
870
+ const rows = withFields(visible(m.rows), true);
871
+ // Unread beyond this page: a peer said so, something local after the page is unread, or a visible
872
+ // row the merge dropped past the page limit is unread (§3.5).
873
+ let beyond = peerBeyond || beyondLocal(m.rows, local.more);
874
+ if (unread && reader && !beyond) {
875
+ const all = mergeConversationPages([{ rows: localRows, more: false }, ...peerPages.map((p) => ({ ...p, more: false }))], 10_000).rows;
876
+ beyond = visible(all.slice(limit)).some((r) => r.hasUnread === true || (r.machine === self || r.platform === 'app' ? !!unread.rowFields(reader, r)?.hasUnread : false));
877
+ }
878
+ const treeRows = withTree(rows);
879
+ res.json({ ownerProjectionVersion: 1, conversations: treeRows, ...pinnedOut(rows), ...listPinsOut(treeRows, peerPages.flatMap((p) => p.rows)), nextCursor: m.nextCursor, ...ownerNote, pool: { failed: peers.failed }, ...(unreadProjectionIncomplete ? { unreadProjectionIncomplete: true } : {}), ...totals(rows, beyond) });
880
+ }
881
+ catch (error) {
882
+ if (error instanceof Error && error.message === 'work-card-visibility-unavailable') {
883
+ res.status(503).json({ error: 'work-card-visibility-unavailable', detail: 'Work card visibility is not ready. Try this read again.' });
884
+ return;
885
+ }
886
+ throw error;
825
887
  }
826
- // Pool read (§4.8): every answering machine's own page after the same cursor, merged on the
827
- // same order (lossless), duplicates collapsed; a dark machine is a `pool.failed` row.
828
- const readerQ = reader ? `&reader=${encodeURIComponent(reader.key)}` : '';
829
- const q = `/mobile/conversations?limit=${limit}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}${readerQ}`;
830
- let peerBeyond = false;
831
- const peers = deps.pool
832
- ? await fetchPeers(deps.pool, q, MAX_POOL_LIST_BYTES, (body, machineId) => {
833
- if (body.unreadBeyondPage === true)
834
- peerBeyond = true;
835
- return {
836
- rows: (Array.isArray(body.conversations) ? body.conversations.slice(0, limit) : [])
837
- .map((r) => sanitizePeerConversation(r, machineId))
838
- .filter((r) => r !== null && isAfterListCursor(r, parseListCursor(cursor))),
839
- more: typeof body.nextCursor === 'string' && body.nextCursor.length > 0,
840
- };
841
- })
842
- : { results: [], failed: [] };
843
- // A peer's Slack rows are never listed: a Slack conversation id is local to the machine that
844
- // minted it, and the Slack routes on this machine look ids up here, so a peer row could name a
845
- // different conversation that shares the number (and would otherwise collapse onto this
846
- // machine's row of the same id). Only this machine's own Slack rows are listed.
847
- const peerPages = peers.results.map((p) => ({ ...p, rows: p.rows.filter((r) => r.platform !== 'slack') }));
848
- const localRows = withFields(local.rows.map((r) => ({ ...r, machine: self })), false);
849
- const m = mergeConversationPages([{ rows: localRows, more: local.more }, ...peerPages], limit);
850
- // A peer's app row is checked against THIS machine's copy of the conversation: one not
851
- // replicated here yet is not shown to an MSP phone (fail closed).
852
- const rows = withFields(visible(m.rows), true);
853
- // Unread beyond this page: a peer said so, something local after the page is unread, or a visible
854
- // row the merge dropped past the page limit is unread (§3.5).
855
- let beyond = peerBeyond || beyondLocal(m.rows, local.more);
856
- if (unread && reader && !beyond) {
857
- const all = mergeConversationPages([{ rows: localRows, more: false }, ...peerPages.map((p) => ({ ...p, more: false }))], 10_000).rows;
858
- beyond = visible(all.slice(limit)).some((r) => r.hasUnread === true || (r.machine === self || r.platform === 'app' ? !!unread.rowFields(reader, r)?.hasUnread : false));
859
- }
860
- const treeRows = withTree(rows);
861
- res.json({ conversations: treeRows, ...pinnedOut(rows), ...listPinsOut(treeRows, peerPages.flatMap((p) => p.rows)), nextCursor: m.nextCursor, ...ownerNote, pool: { failed: peers.failed }, ...totals(rows, beyond) });
862
888
  });
863
889
  // ── Read reports (mobile-unread-messages §3.5) ──
864
890
  const unreadOff = (res) => res.status(503).json({ error: 'unread-off', detail: 'Unread counts are turned off on this agent.' });