@jant/core 0.8.0 → 0.9.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.
Files changed (160) hide show
  1. package/dist/{app-CFsmRVJN.js → app-BzH8jmh3.js} +1619 -500
  2. package/dist/client/.vite/manifest.json +2 -2
  3. package/dist/client/_assets/{client-DTLBOHqD.js → client-S8oryJ0m.js} +1 -1
  4. package/dist/client/_assets/{client-auth-D6Ix6SmE.js → client-auth-Ds9G0IgR.js} +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/node.js +2 -2
  7. package/package.json +1 -1
  8. package/src/__tests__/fixtures/releases/0.8.0/site-export/README.md +130 -0
  9. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/2thjq/_index.md +25 -0
  10. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/2u5e5/_index.md +35 -0
  11. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/0x4nv/index.md +18 -0
  12. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/_index.md +44 -0
  13. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/faqyt/index.md +30 -0
  14. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
  15. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5kayp/_index.md +23 -0
  16. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5ynfs/_index.md +31 -0
  17. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5ynfs/hu597/index.md +21 -0
  18. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/_index.md +5 -0
  19. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
  20. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
  21. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/archive/_index.md +8 -0
  22. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +30 -0
  23. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
  24. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/city-walks/_index.md +12 -0
  25. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/cleanshot-for-screenshots-ocr-and-screen-recording-on-the-mac/_index.md +33 -0
  26. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/cleanshotmac-shang-de-jie-tu-ocr-lu-ping-gong-ju/_index.md +32 -0
  27. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/co344/_index.md +25 -0
  28. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/collections/_index.md +5 -0
  29. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/current-tea-rotation/_index.md +34 -0
  30. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +30 -0
  31. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/desk-but-better/_index.md +25 -0
  32. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/e0kcg/_index.md +22 -0
  33. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/egi3c/_index.md +24 -0
  34. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/evf9j/_index.md +152 -0
  35. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/featured/_index.md +8 -0
  36. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-basho/_index.md +25 -0
  37. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-epictetus/_index.md +25 -0
  38. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
  39. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-seneca/_index.md +26 -0
  40. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-thoreau/_index.md +25 -0
  41. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
  42. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
  43. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
  44. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/_index.md +39 -0
  45. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gwob9/_index.md +25 -0
  46. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/home-cooking/_index.md +12 -0
  47. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/hz729/_index.md +24 -0
  48. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
  49. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/j4v0q/_index.md +35 -0
  50. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k278t/_index.md +25 -0
  51. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k4eee/_index.md +22 -0
  52. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/_index.md +32 -0
  53. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
  54. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/a83qu/index.md +18 -0
  55. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
  56. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/kan-qi-lai-bi-jiao-ku-de-gong-si-men/_index.md +41 -0
  57. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/l2m7y/_index.md +29 -0
  58. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/lan-ya-yao-kong-qi-chuang-shang-yue-du-de-fan-ye-shen-qi/_index.md +57 -0
  59. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
  60. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/n09le/_index.md +23 -0
  61. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/ni-fu-jin-de-wei-ji-bai-ke-tiao-mu/_index.md +42 -0
  62. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
  63. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/_index.md +32 -0
  64. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/c91j0/index.md +18 -0
  65. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/qyucy/index.md +18 -0
  66. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/wsgck/index.md +18 -0
  67. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
  68. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/reading-notes/_index.md +12 -0
  69. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/s4r3e/_index.md +25 -0
  70. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
  71. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/_index.md +44 -0
  72. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/cxiu6/index.md +18 -0
  73. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/t77ms/index.md +18 -0
  74. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
  75. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/telk3/_index.md +30 -0
  76. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
  77. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +36 -0
  78. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
  79. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
  80. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tiny-projects/_index.md +12 -0
  81. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
  82. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tou-ma-yan-jiang-ju-le-bu-chu-ti-yan/_index.md +62 -0
  83. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/useful-links/_index.md +12 -0
  84. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/weekend-notes/_index.md +12 -0
  85. package/src/__tests__/fixtures/releases/0.8.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
  86. package/src/__tests__/fixtures/releases/0.8.0/site-export/data/jant.toml +124 -0
  87. package/src/__tests__/fixtures/releases/0.8.0/site-export/hugo.toml +45 -0
  88. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/_redirects +25 -0
  89. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/15d51730a4f7-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
  90. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
  91. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
  92. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
  93. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
  94. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
  95. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
  96. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
  97. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
  98. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
  99. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
  100. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
  101. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
  102. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
  103. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
  104. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
  105. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
  106. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
  107. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
  108. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
  109. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
  110. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
  111. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
  112. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
  113. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
  114. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
  115. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
  116. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
  117. package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
  118. package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
  119. package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/custom.css +0 -0
  120. package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/favicon.ico +0 -0
  121. package/src/__tests__/fixtures/releases/0.8.0/site-export/wrangler.jsonc +24 -0
  122. package/src/__tests__/fixtures/releases/0.8.0/snapshot/db.sql +322 -0
  123. package/src/__tests__/fixtures/releases/0.8.0/snapshot/meta.json +11 -0
  124. package/src/__tests__/helpers/cursor-walk.ts +82 -0
  125. package/src/__tests__/release-fixtures.test.ts +6 -2
  126. package/src/app.tsx +4 -0
  127. package/src/lib/__tests__/post-list-cursor.test.ts +105 -0
  128. package/src/lib/__tests__/thread-fold.test.ts +43 -0
  129. package/src/lib/__tests__/timeline.test.ts +14 -14
  130. package/src/lib/api-posts.ts +110 -2
  131. package/src/lib/api-public-posts.ts +263 -0
  132. package/src/lib/api-threads.ts +207 -0
  133. package/src/lib/post-list-cursor.ts +211 -0
  134. package/src/lib/thread-fold.ts +83 -41
  135. package/src/lib/thread-query.ts +143 -0
  136. package/src/middleware/cors.ts +8 -1
  137. package/src/middleware/deprecation.ts +48 -0
  138. package/src/routes/api/__tests__/mcp.test.ts +147 -0
  139. package/src/routes/api/__tests__/posts.test.ts +157 -0
  140. package/src/routes/api/__tests__/public-access.test.ts +5 -0
  141. package/src/routes/api/__tests__/threads.test.ts +115 -0
  142. package/src/routes/api/posts.ts +19 -112
  143. package/src/routes/api/public/__tests__/archive.test.ts +261 -0
  144. package/src/routes/api/public/__tests__/posts.test.ts +344 -19
  145. package/src/routes/api/public/__tests__/threads.test.ts +363 -0
  146. package/src/routes/api/public/archive.ts +82 -79
  147. package/src/routes/api/public/posts.ts +97 -299
  148. package/src/routes/api/public/threads.ts +141 -0
  149. package/src/routes/api/threads.ts +128 -0
  150. package/src/services/__tests__/post.test.ts +342 -36
  151. package/src/services/__tests__/thread.test.ts +495 -0
  152. package/src/services/index.ts +4 -0
  153. package/src/services/mcp.ts +213 -63
  154. package/src/services/post.ts +734 -361
  155. package/src/services/thread.ts +392 -0
  156. package/src/types/constants.ts +25 -0
  157. package/src/ui/feed/ThreadPreview.tsx +9 -14
  158. package/src/ui/feed/__tests__/thread-preview.test.ts +18 -22
  159. package/src/ui/feed/thread-preview-state.ts +0 -35
  160. package/src/ui/shared/Pagination.tsx +1 -1
@@ -3,15 +3,17 @@
3
3
  *
4
4
  * How much of a thread the timeline shows, and how much it folds away.
5
5
  *
6
- * A thread appears in two places that cannot select its posts the same way.
7
- * The site paints a page of timeline items and must not load whole threads to
8
- * do it, so `getThreadTimelineContext` ranks replies in SQL and hands the
9
- * buckets down. The feed already holds every reply — `<content>` carries the
10
- * whole chain — so it slices the array it has. Two access paths, one rule.
6
+ * A thread is folded in three places that cannot all select its posts the same
7
+ * way. The site paints a page of timeline items and must not load whole
8
+ * threads to do it, so `getThreadTimelineContext` ranks replies in SQL and
9
+ * hands the windows down; the Threads API's `include=fold` reads the same
10
+ * windows. The feed already holds every reply — `<content>` carries the whole
11
+ * chain — so it slices the array it has. Two access paths, one rule.
11
12
  *
12
- * This module owns what they share: the thresholds, and the arithmetic that
13
- * turns a selection into a hidden count. Whoever changes the shape of the fold
14
- * changes it here, and both surfaces move together.
13
+ * This module owns what they share: the thresholds, how overlapping windows
14
+ * become the replies shown ({@link foldReplyWindows}), and the arithmetic that
15
+ * turns them into a hidden count. Whoever changes the shape of the fold changes
16
+ * it here, and every surface moves together.
15
17
  *
16
18
  * ## The fold
17
19
  *
@@ -101,6 +103,73 @@ export interface ThreadFold<T> {
101
103
  hiddenCount: number;
102
104
  }
103
105
 
106
+ /**
107
+ * Fold a thread from its ranked windows: the replies each end of the fold
108
+ * keeps, before any overlap between them is removed.
109
+ *
110
+ * Both access paths arrive here. The feed slices the windows out of the whole
111
+ * chain; the site and the API rank them in SQL (`getThreadTimelineContext`),
112
+ * which hands them over overlapping on purpose. A short thread's windows
113
+ * overlap, and the hero is inside both of them on the shortest ones: with a
114
+ * single reply, that reply is the newest *and* the whole leading window. Each
115
+ * list therefore drops whatever an earlier one already shows, hero first.
116
+ *
117
+ * @param buckets.leadingReplies - The first `THREAD_LEADING_REPLIES` replies
118
+ * @param buckets.trailingReplies - The replies just before the newest, oldest
119
+ * first
120
+ * @param buckets.latestReply - The newest reply
121
+ * @param buckets.nextReply - The reply right after the leading window, the
122
+ * only candidate for the gap; `null` when the thread has no such reply
123
+ * @param buckets.totalReplyCount - Every published reply in the thread
124
+ * @returns The fold
125
+ * @example
126
+ * foldReplyWindows({ leadingReplies: [r1, r2], trailingReplies: [r6, r7],
127
+ * latestReply: r8, nextReply: r3, totalReplyCount: 8 });
128
+ * // leading [r1, r2], trailing [r6, r7], latest r8, firstHidden r3, hidden 3
129
+ */
130
+ export function foldReplyWindows<T extends Identified>({
131
+ leadingReplies: leadingWindow,
132
+ trailingReplies: trailingWindow,
133
+ latestReply,
134
+ nextReply,
135
+ totalReplyCount,
136
+ }: {
137
+ leadingReplies: T[];
138
+ trailingReplies: T[];
139
+ latestReply: T;
140
+ nextReply: T | null;
141
+ totalReplyCount: number;
142
+ }): ThreadFold<T> {
143
+ const shown = new Set([latestReply.id]);
144
+ const keepUnshown = (replies: T[]) =>
145
+ replies.filter((reply) => {
146
+ if (shown.has(reply.id)) return false;
147
+ shown.add(reply.id);
148
+ return true;
149
+ });
150
+ const leadingReplies = keepUnshown(leadingWindow);
151
+ const trailingReplies = keepUnshown(trailingWindow);
152
+ const hiddenCount = getThreadHiddenCount({
153
+ leadingReplies,
154
+ trailingReplies,
155
+ latestReply,
156
+ totalReplyCount,
157
+ });
158
+
159
+ return {
160
+ leadingReplies,
161
+ trailingReplies,
162
+ latestReply,
163
+ // The reply after the leading window is hidden exactly when anything is:
164
+ // the trailing window starts at or before it otherwise.
165
+ firstHiddenReply:
166
+ hiddenCount > 0 && nextReply && !shown.has(nextReply.id)
167
+ ? nextReply
168
+ : null,
169
+ hiddenCount,
170
+ };
171
+ }
172
+
104
173
  /**
105
174
  * Fold a thread whose replies are already in hand.
106
175
  *
@@ -122,40 +191,13 @@ export function foldThreadReplies<T extends Identified>(
122
191
  const latestReply = replies.at(-1);
123
192
  if (!latestReply) return null;
124
193
 
125
- // A short thread's windows overlap, and the hero is inside both of them on
126
- // the shortest ones: with a single reply, that reply is the newest *and* the
127
- // whole leading window. Each list therefore drops whatever an earlier one
128
- // already shows, hero first — the same order `ThreadPreview` dedupes in when
129
- // it walks the buckets the SQL path hands it.
130
- const leadingReplies = replies
131
- .slice(0, THREAD_LEADING_REPLIES)
132
- .filter((reply) => reply.id !== latestReply.id);
133
-
134
- const leadingIds = new Set(leadingReplies.map((reply) => reply.id));
135
- const trailingReplies = replies
136
- .slice(-THREAD_TRAILING_REPLIES, -1)
137
- .filter(
138
- (reply) => reply.id !== latestReply.id && !leadingIds.has(reply.id),
139
- );
140
-
141
- const shown = new Set([
142
- ...leadingIds,
143
- ...trailingReplies.map((reply) => reply.id),
144
- latestReply.id,
145
- ]);
146
-
147
- return {
148
- leadingReplies,
149
- trailingReplies,
194
+ return foldReplyWindows({
195
+ leadingReplies: replies.slice(0, THREAD_LEADING_REPLIES),
196
+ trailingReplies: replies.slice(-THREAD_TRAILING_REPLIES, -1),
150
197
  latestReply,
151
198
  // In thread order, so the gap link lands on the earliest post it stands
152
199
  // for rather than somewhere in the middle of the run it hides.
153
- firstHiddenReply: replies.find((reply) => !shown.has(reply.id)) ?? null,
154
- hiddenCount: getThreadHiddenCount({
155
- leadingReplies,
156
- trailingReplies,
157
- latestReply,
158
- totalReplyCount: replies.length,
159
- }),
160
- };
200
+ nextReply: replies[THREAD_LEADING_REPLIES] ?? null,
201
+ totalReplyCount: replies.length,
202
+ });
161
203
  }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Thread list queries
3
+ *
4
+ * Reads the filter dimensions a Thread list takes — the archive's, from the
5
+ * same registry — out of an HTTP query string or MCP arguments, so the public
6
+ * API, the author API, and MCP accept one vocabulary.
7
+ *
8
+ * One word differs from the archive page. A Thread list left unfiltered shows
9
+ * what the homepage shows, so it needs a word for "every visibility a reader
10
+ * may see": `visibility=any`. The registry's `visibility=all` is an old
11
+ * spelling of leaving the parameter out, which here would mean the homepage's
12
+ * set — the opposite of what the word says — so a Thread list refuses it.
13
+ */
14
+
15
+ import type { ThreadAudience } from "../services/thread.js";
16
+ import type { Collection } from "../types.js";
17
+ import { ValidationError } from "./errors.js";
18
+ import {
19
+ buildCollectionVocabulary,
20
+ EMPTY_COLLECTION_VOCABULARY,
21
+ parsePostFilterSelectionStrict,
22
+ readCollectionSlugs,
23
+ type ParamReader,
24
+ type PostFilterSelection,
25
+ } from "./filter-dimensions.js";
26
+
27
+ /** What a Thread list's filter parameters asked for. */
28
+ export type ThreadSelectionParse =
29
+ | {
30
+ kind: "selection";
31
+ selection: PostFilterSelection;
32
+ /** `visibility=any`: include what the homepage hides. */
33
+ includeHidden: boolean;
34
+ }
35
+ /** A named collection doesn't exist, so nothing can match. */
36
+ | { kind: "empty" };
37
+
38
+ const READER_VISIBILITIES = ["public", "featured", "hidden", "any"] as const;
39
+ const AUTHOR_VISIBILITIES = [...READER_VISIBILITIES, "private"] as const;
40
+ /** Spellings the registry reads that stay valid here. */
41
+ const LEGACY_VISIBILITIES = ["latest_hidden"] as const;
42
+
43
+ function allowedVisibilities(audience: ThreadAudience): readonly string[] {
44
+ return audience === "reader" ? READER_VISIBILITIES : AUTHOR_VISIBILITIES;
45
+ }
46
+
47
+ /**
48
+ * Read a Thread list's filter dimensions.
49
+ *
50
+ * @param read - Reads one parameter; `undefined` when absent
51
+ * @param present - Every parameter name the request carries
52
+ * @param options.allow - The endpoint's own parameters, which aren't
53
+ * dimensions; anything else unknown is refused
54
+ * @param options.audience - A reader may not name `private`
55
+ * @param options.loadCollections - Loads the collection vocabulary, called only
56
+ * when a collection is named
57
+ * @returns The selection, or `empty` when a named collection doesn't exist
58
+ * @throws {ValidationError} On an unknown parameter or an unreadable value
59
+ * @example
60
+ * const parsed = await parseThreadSelection(read, Object.keys(query), {
61
+ * allow: ["cursor", "limit"],
62
+ * audience: "reader",
63
+ * loadCollections: () => services.collections.list(),
64
+ * });
65
+ */
66
+ export async function parseThreadSelection(
67
+ read: ParamReader,
68
+ present: readonly string[],
69
+ options: {
70
+ allow: readonly string[];
71
+ audience: ThreadAudience;
72
+ loadCollections: () => Promise<Collection[]>;
73
+ },
74
+ ): Promise<ThreadSelectionParse> {
75
+ const visibility = read("visibility");
76
+ if (visibility !== undefined) {
77
+ const allowed = allowedVisibilities(options.audience);
78
+ if (visibility === "all") {
79
+ throw new ValidationError(
80
+ "visibility=all isn't accepted here. Leave visibility out for what the homepage lists, or pass visibility=any for everything.",
81
+ );
82
+ }
83
+ if (
84
+ !allowed.includes(visibility) &&
85
+ !(LEGACY_VISIBILITIES as readonly string[]).includes(visibility)
86
+ ) {
87
+ throw new ValidationError(
88
+ `Invalid visibility value. Allowed: ${allowed.join(", ")}`,
89
+ );
90
+ }
91
+ }
92
+
93
+ const includeHidden = visibility === "any";
94
+ // `any` isn't a registry value: it widens the audience's default rather
95
+ // than filtering, so the registry reads the query as if it were absent.
96
+ const readDimension: ParamReader = (key) =>
97
+ key === "visibility" && includeHidden ? undefined : read(key);
98
+
99
+ // Resolving a slug costs a round trip, paid only when one is named.
100
+ const collections =
101
+ readCollectionSlugs(readDimension).length > 0
102
+ ? buildCollectionVocabulary(await options.loadCollections())
103
+ : EMPTY_COLLECTION_VOCABULARY;
104
+ const parsed = parsePostFilterSelectionStrict(
105
+ readDimension,
106
+ present,
107
+ { collections },
108
+ { allow: options.allow },
109
+ );
110
+
111
+ if (parsed.ok) {
112
+ return { kind: "selection", selection: parsed.selection, includeHidden };
113
+ }
114
+ // A collection that doesn't exist is answered with nothing rather than a
115
+ // rejection: the caller's words were understood, and the site simply holds
116
+ // no such collection.
117
+ if (parsed.issues.every((issue) => issue.param === "collection")) {
118
+ return { kind: "empty" };
119
+ }
120
+ throw new ValidationError(parsed.issues[0]?.message ?? "Validation failed");
121
+ }
122
+
123
+ /**
124
+ * Read `include`: a comma-separated list of extras to attach to each Thread.
125
+ *
126
+ * @param raw - The parameter's value, or `undefined`
127
+ * @returns Whether the fold was asked for
128
+ * @throws {ValidationError} On a value this endpoint doesn't offer
129
+ * @example
130
+ * parseThreadInclude("fold"); // { fold: true }
131
+ */
132
+ export function parseThreadInclude(raw: string | undefined): { fold: boolean } {
133
+ if (raw === undefined || raw === "") return { fold: false };
134
+ const values = raw.split(",").map((value) => value.trim());
135
+ for (const value of values) {
136
+ if (value !== "fold") {
137
+ throw new ValidationError(
138
+ `Invalid include value "${value}". Allowed: fold`,
139
+ );
140
+ }
141
+ }
142
+ return { fold: values.includes("fold") };
143
+ }
@@ -39,7 +39,14 @@ export function apiCors(): MiddlewareHandler<Env> {
39
39
  origin: origins,
40
40
  allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
41
41
  allowHeaders: ["Content-Type", "Authorization", "MCP-Protocol-Version"],
42
- exposeHeaders: ["Content-Type", "MCP-Protocol-Version"],
42
+ // `Deprecation` and `Link` are how a deprecated endpoint names its
43
+ // replacement; a browser client can't read either unless exposed.
44
+ exposeHeaders: [
45
+ "Content-Type",
46
+ "MCP-Protocol-Version",
47
+ "Deprecation",
48
+ "Link",
49
+ ],
43
50
  credentials: origins !== "*",
44
51
  maxAge: 86400,
45
52
  });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Deprecated API endpoints.
3
+ *
4
+ * A deprecated endpoint keeps answering exactly as before until the major
5
+ * release that removes it, and says so on every response, errors included:
6
+ * `Deprecation` (RFC 9745) carries when it was deprecated, and `Link` with
7
+ * `rel="successor-version"` names what replaces it. The docs and the release
8
+ * notes say the same thing in words.
9
+ */
10
+
11
+ import type { MiddlewareHandler } from "hono";
12
+ import type { Bindings } from "../types.js";
13
+ import type { AppVariables } from "../types/app-context.js";
14
+ import { toPublicPath } from "../lib/url.js";
15
+
16
+ type Env = { Bindings: Bindings; Variables: AppVariables };
17
+
18
+ /**
19
+ * When 0.9 deprecated the Thread lists that `/api/public/threads` replaces:
20
+ * the `GET /api/public/posts` list and `GET /api/public/archive`.
21
+ */
22
+ export const THREAD_LIST_DEPRECATED_AT = Date.UTC(2026, 8, 27) / 1000;
23
+
24
+ /**
25
+ * Mark every response of a route as deprecated.
26
+ *
27
+ * @param deprecatedAt - Unix seconds the endpoint was deprecated
28
+ * @param successor - The replacement, as a site path (the site path prefix is
29
+ * added)
30
+ * @returns Hono middleware that sets `Deprecation` and `Link`
31
+ * @example
32
+ * ```ts
33
+ * routes.get("/", deprecated(THREAD_LIST_DEPRECATED_AT, "/api/public/threads"), handler);
34
+ * ```
35
+ */
36
+ export function deprecated(
37
+ deprecatedAt: number,
38
+ successor: string,
39
+ ): MiddlewareHandler<Env> {
40
+ return async (c, next) => {
41
+ await next();
42
+ c.header("Deprecation", `@${deprecatedAt}`);
43
+ c.header(
44
+ "Link",
45
+ `<${toPublicPath(successor, c.var.appConfig.sitePathPrefix)}>; rel="successor-version"`,
46
+ );
47
+ };
48
+ }
@@ -144,6 +144,9 @@ describe("MCP API Routes", () => {
144
144
  );
145
145
 
146
146
  expect(toolNames).toContain("jant_posts_list");
147
+ expect(toolNames).toContain("jant_threads_list");
148
+ expect(toolNames).toContain("jant_threads_get");
149
+ expect(toolNames).toContain("jant_threads_list_posts");
147
150
  expect(toolNames).toContain("jant_collections_add_thread");
148
151
  expect(toolNames).toContain("jant_collections_remove_thread");
149
152
  expect(toolNames).toContain("jant_settings_update");
@@ -213,6 +216,150 @@ describe("MCP API Routes", () => {
213
216
  expect(await services.collections.getThreadIds(collection.id)).toEqual([]);
214
217
  });
215
218
 
219
+ it("reads Threads through tools/call", async () => {
220
+ const { app, services } = createTestApp({ authenticated: true });
221
+ app.route("/api/mcp", mcpApiRoutes);
222
+
223
+ const collection = await services.collections.create({
224
+ slug: "notes",
225
+ title: "Notes",
226
+ });
227
+ const root = await services.posts.create({
228
+ format: "note",
229
+ bodyMarkdown: "Root",
230
+ publishedAt: 1000,
231
+ collectionIds: [collection.id],
232
+ });
233
+ const replies = [];
234
+ let parent = root;
235
+ for (let i = 1; i <= 7; i++) {
236
+ parent = await services.posts.create({
237
+ format: "note",
238
+ bodyMarkdown: `Reply ${i}`,
239
+ replyToId: parent.id,
240
+ publishedAt: 1000 + i,
241
+ createdAt: 1000 + i,
242
+ });
243
+ replies.push(parent);
244
+ }
245
+ const other = await services.posts.create({
246
+ format: "note",
247
+ bodyMarkdown: "Elsewhere",
248
+ publishedAt: 500,
249
+ });
250
+
251
+ const call = async (name: string, args: Record<string, unknown>) => {
252
+ const res = await postMcp(
253
+ app,
254
+ {
255
+ jsonrpc: "2.0",
256
+ id: 40,
257
+ method: "tools/call",
258
+ params: { name, arguments: args },
259
+ },
260
+ { "MCP-Protocol-Version": "2025-06-18" },
261
+ );
262
+ expect(res.status).toBe(200);
263
+ const { result } = await res.json();
264
+ expect(result.isError).toBe(false);
265
+ return result.structuredContent;
266
+ };
267
+
268
+ const all = await call("jant_threads_list", { sort: "published" });
269
+ expect(all.threads.map((thread: { id: string }) => thread.id)).toEqual([
270
+ root.id,
271
+ other.id,
272
+ ]);
273
+ expect(all.threads[0].postCount).toBe(8);
274
+ expect(all.threads[0].fold).toBeUndefined();
275
+
276
+ const inCollection = await call("jant_threads_list", {
277
+ collection: "notes",
278
+ fold: true,
279
+ });
280
+ expect(inCollection.threads).toHaveLength(1);
281
+ expect(inCollection.threads[0].fold.hidden).toBe(2);
282
+ expect(inCollection.threads[0].fold.gap).toEqual({
283
+ id: replies[2]?.id,
284
+ slug: replies[2]?.slug,
285
+ });
286
+
287
+ const thread = await call("jant_threads_get", { id: replies[4]?.id });
288
+ expect(thread).toMatchObject({ id: root.id, postCount: 8 });
289
+
290
+ const walked: string[] = [];
291
+ let cursor: string | undefined;
292
+ for (let page = 0; page < 10; page++) {
293
+ const result = await call("jant_threads_list_posts", {
294
+ id: root.id,
295
+ limit: 3,
296
+ ...(cursor ? { cursor } : {}),
297
+ });
298
+ walked.push(...result.posts.map((post: { id: string }) => post.id));
299
+ cursor = result.nextCursor ?? undefined;
300
+ if (!cursor) break;
301
+ }
302
+ expect(walked).toEqual([root.id, ...replies.map((reply) => reply.id)]);
303
+ });
304
+
305
+ it("pages posts through tools/call with nextCursor", async () => {
306
+ const { app, services } = createTestApp({ authenticated: true });
307
+ app.route("/api/mcp", mcpApiRoutes);
308
+
309
+ const created = [];
310
+ for (let i = 0; i < 3; i++) {
311
+ created.push(
312
+ await services.posts.create({
313
+ format: "note",
314
+ bodyMarkdown: `post ${i}`,
315
+ publishedAt: 1000 + i,
316
+ }),
317
+ );
318
+ }
319
+
320
+ const listPosts = async (args: Record<string, unknown>) => {
321
+ const res = await postMcp(
322
+ app,
323
+ {
324
+ jsonrpc: "2.0",
325
+ id: 30,
326
+ method: "tools/call",
327
+ params: { name: "jant_posts_list", arguments: args },
328
+ },
329
+ { "MCP-Protocol-Version": "2025-06-18" },
330
+ );
331
+ expect(res.status).toBe(200);
332
+ return (await res.json()).result;
333
+ };
334
+
335
+ const ids: string[] = [];
336
+ let cursor: string | undefined;
337
+ for (let page = 0; page < 5; page++) {
338
+ const result = await listPosts({
339
+ limit: 1,
340
+ ...(cursor ? { cursor } : {}),
341
+ });
342
+ expect(result.isError).toBe(false);
343
+ ids.push(
344
+ ...result.structuredContent.posts.map(
345
+ (post: { id: string }) => post.id,
346
+ ),
347
+ );
348
+ cursor = result.structuredContent.nextCursor ?? undefined;
349
+ if (!cursor) break;
350
+ }
351
+ expect(ids).toEqual(created.map((post) => post.id).reverse());
352
+
353
+ const legacy = await listPosts({ cursor: created[2]?.id });
354
+ expect(
355
+ legacy.structuredContent.posts.map((post: { id: string }) => post.id),
356
+ ).toEqual([created[1]?.id, created[0]?.id]);
357
+
358
+ const unreadable = await listPosts({ cursor: "nope" });
359
+ expect(unreadable.isError).toBe(true);
360
+ expect(unreadable.structuredContent.error).toMatch(/cursor/);
361
+ });
362
+
216
363
  it("creates posts through tools/call", async () => {
217
364
  const { app, services } = createTestApp({ authenticated: true });
218
365
  app.route("/api/mcp", mcpApiRoutes);
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect } from "vitest";
2
2
  import { createTestApp } from "../../../__tests__/helpers/app.js";
3
+ import { walkPostPages } from "../../../__tests__/helpers/cursor-walk.js";
3
4
  import { createEntityId } from "../../../lib/ids.js";
4
5
  import { postsApiRoutes } from "../posts.js";
5
6
 
@@ -143,6 +144,162 @@ describe("Posts API Routes", () => {
143
144
  expect(body.nextCursor).toBeTruthy();
144
145
  });
145
146
 
147
+ it("pages published posts and drafts with an opaque cursor", async () => {
148
+ const { app, services } = createTestApp({ authenticated: true });
149
+ app.route("/api/posts", postsApiRoutes);
150
+
151
+ const published = [];
152
+ for (let i = 0; i < 5; i++) {
153
+ published.push(
154
+ await services.posts.create({
155
+ format: "note",
156
+ bodyMarkdown: `post ${i}`,
157
+ publishedAt: 1000 + (i % 2), // Ties, broken by ID.
158
+ }),
159
+ );
160
+ }
161
+ const root = published[0];
162
+ await services.posts.create({
163
+ format: "note",
164
+ bodyMarkdown: "reply",
165
+ replyToId: root?.id,
166
+ publishedAt: 900,
167
+ });
168
+ for (let i = 0; i < 3; i++) {
169
+ await services.posts.create({
170
+ format: "note",
171
+ bodyMarkdown: `draft ${i}`,
172
+ status: "draft",
173
+ });
174
+ }
175
+
176
+ for (const path of ["/api/posts", "/api/posts?status=draft"]) {
177
+ const res = await app.request(path);
178
+ const expected = (await res.json()).posts.map(
179
+ (post: { id: string }) => post.id,
180
+ );
181
+ expect(expected.length).toBeGreaterThan(2);
182
+ for (const limit of [1, 2]) {
183
+ expect(await walkPostPages(app, path, limit)).toEqual(expected);
184
+ }
185
+ }
186
+
187
+ const first = await (await app.request("/api/posts?limit=2")).json();
188
+ expect(first.nextCursor).not.toMatch(/^pst_/);
189
+ });
190
+
191
+ it("reads a bare post ID as a cursor, and rejects one it can't use", async () => {
192
+ const { app, services } = createTestApp({ authenticated: true });
193
+ app.route("/api/posts", postsApiRoutes);
194
+
195
+ const older = await services.posts.create({
196
+ format: "note",
197
+ bodyMarkdown: "older",
198
+ publishedAt: 1000,
199
+ });
200
+ const newer = await services.posts.create({
201
+ format: "note",
202
+ bodyMarkdown: "newer",
203
+ publishedAt: 2000,
204
+ });
205
+ const draft = await services.posts.create({
206
+ format: "note",
207
+ bodyMarkdown: "draft",
208
+ status: "draft",
209
+ });
210
+
211
+ const legacy = await app.request(`/api/posts?cursor=${newer.id}`);
212
+ expect(legacy.status).toBe(200);
213
+ expect(
214
+ (await legacy.json()).posts.map((post: { id: string }) => post.id),
215
+ ).toEqual([older.id]);
216
+
217
+ // A draft is not in the published list the cursor claims to continue.
218
+ const wrongList = await app.request(`/api/posts?cursor=${draft.id}`);
219
+ expect(wrongList.status).toBe(400);
220
+ const unreadable = await app.request("/api/posts?cursor=nope");
221
+ expect(unreadable.status).toBe(400);
222
+ expect((await unreadable.json()).code).toBe("VALIDATION_ERROR");
223
+ });
224
+
225
+ // The failure this guards: ordered by thread activity with pins first, a
226
+ // reply lifted a long-published root to the top — past a walk's cursor,
227
+ // so the walk never returned it.
228
+ it("orders published posts by publication alone", async () => {
229
+ const { app, services } = createTestApp({ authenticated: true });
230
+ app.route("/api/posts", postsApiRoutes);
231
+
232
+ const root = await services.posts.create({
233
+ format: "note",
234
+ bodyMarkdown: "old root",
235
+ publishedAt: 1000,
236
+ });
237
+ const pinned = await services.posts.create({
238
+ format: "note",
239
+ bodyMarkdown: "pinned",
240
+ publishedAt: 2000,
241
+ pinned: true,
242
+ });
243
+ const recent = await services.posts.create({
244
+ format: "note",
245
+ bodyMarkdown: "recent",
246
+ publishedAt: 3000,
247
+ });
248
+
249
+ const first = await (await app.request("/api/posts?limit=1")).json();
250
+ expect(first.posts[0].id).toBe(recent.id);
251
+ const reply = await services.posts.create({
252
+ format: "note",
253
+ bodyMarkdown: "late reply",
254
+ replyToId: root.id,
255
+ publishedAt: 4000,
256
+ });
257
+
258
+ const rest = await walkPostPages(app, "/api/posts", 1, first.nextCursor);
259
+ expect(rest).toEqual([pinned.id, root.id]);
260
+ const all = await (await app.request("/api/posts")).json();
261
+ expect(all.posts.map((post: { id: string }) => post.id)).toEqual([
262
+ reply.id,
263
+ recent.id,
264
+ pinned.id,
265
+ root.id,
266
+ ]);
267
+ expect(
268
+ all.posts.map(
269
+ (post: { threadPostCount: number }) => post.threadPostCount,
270
+ ),
271
+ ).toEqual([2, 1, 1, 2]);
272
+ });
273
+
274
+ it("keeps drafts in last-edited order", async () => {
275
+ const { app, services } = createTestApp({ authenticated: true });
276
+ app.route("/api/posts", postsApiRoutes);
277
+
278
+ const first = await services.posts.create({
279
+ format: "note",
280
+ bodyMarkdown: "first",
281
+ status: "draft",
282
+ createdAt: 1000,
283
+ updatedAt: 1000,
284
+ });
285
+ const second = await services.posts.create({
286
+ format: "note",
287
+ bodyMarkdown: "second",
288
+ status: "draft",
289
+ createdAt: 2000,
290
+ updatedAt: 2000,
291
+ });
292
+ await services.posts.update(first.id, { bodyMarkdown: "edited" });
293
+
294
+ const res = await app.request("/api/posts?status=draft");
295
+ const body = await res.json();
296
+ expect(body.posts.map((post: { id: string }) => post.id)).toEqual([
297
+ first.id,
298
+ second.id,
299
+ ]);
300
+ expect(body.posts[0].threadPostCount).toBe(0);
301
+ });
302
+
146
303
  it("serializes quote attribution as sourceName/sourceUrl", async () => {
147
304
  const { app, services } = createTestApp({ authenticated: true });
148
305
  app.route("/api/posts", postsApiRoutes);