rvlib-shipkit 2.12.0 → 2.14.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 (378) hide show
  1. package/CHANGELOG.md +75 -21
  2. package/README.md +1 -1
  3. package/package.json +4 -2
  4. package/src/agent-time/store.ts +2 -2
  5. package/src/assets/run-assets.ts +2 -2
  6. package/src/assets/server/studio-server.ts +27 -23
  7. package/src/check.ts +4 -4
  8. package/src/checks/SK001-package-json-shape.check.ts +8 -4
  9. package/src/checks/SK002-contracts-fulfillness.check.ts +2 -2
  10. package/src/checks/SK003-claude-md-shape.check.ts +20 -13
  11. package/src/checks/SK004-gitignore-policy.check.ts +45 -6
  12. package/src/checks/SK005-rvlib-versions.check.ts +2 -2
  13. package/src/checks/SK006-npm-publish-safety.check.ts +3 -3
  14. package/src/checks/SK007-github-visibility.check.ts +2 -2
  15. package/src/checks/SK008-reviewer-agent.check.ts +3 -3
  16. package/src/checks/SK010-undeclared-unit.check.ts +2 -2
  17. package/src/checks/SK011-sibling-unit-ranges.check.ts +2 -2
  18. package/src/checks/SK012-config-barrel-import.check.ts +2 -2
  19. package/src/checks/SK013-one-way-in-policy.check.ts +2 -2
  20. package/src/checks/SK015-nested-repo.check.ts +3 -3
  21. package/src/checks/SK016-legacy-check-shapes.check.ts +2 -2
  22. package/src/checks/SK017-vscode-hub-task.check.ts +2 -2
  23. package/src/checks/SK018-test-files-run.check.ts +2 -2
  24. package/src/checks/SK019-tests-run-in-units.check.ts +2 -2
  25. package/src/checks/SK020-self-spawning-check.check.ts +2 -2
  26. package/src/checks/SK022-machine-runs-the-pin.check.ts +2 -2
  27. package/src/checks/SK024-identity-colors.check.ts +1 -1
  28. package/src/checks/SK025-release-drift.check.ts +2 -2
  29. package/src/checks/SK026-asks-autoclose.check.ts +2 -2
  30. package/src/checks/SK027-agent-wiki-links.check.ts +8 -2
  31. package/src/checks/SK028-readme.check.ts +2 -2
  32. package/src/checks/SK029-explicit-check-files.check.ts +3 -3
  33. package/src/checks/SK030-cache-audit.check.ts +7 -5
  34. package/src/checks/SK031-trace-audit.check.ts +7 -7
  35. package/src/checks/SK032-ignored-inputs.check.ts +3 -3
  36. package/src/checks/SK033-global-contribution.check.ts +11 -4
  37. package/src/checks/SK034-commit-gates-armed.check.ts +2 -2
  38. package/src/checks/SK035-public-clean.check.ts +46 -0
  39. package/src/checks/SK036-draft-media-size.check.ts +28 -0
  40. package/src/checks/SK037-keyword-additions.check.ts +43 -0
  41. package/src/cli/cmd_Backup.ts +152 -0
  42. package/src/cli/cmd_Ci.ts +8 -11
  43. package/src/cli/cmd_Commands.ts +4 -4
  44. package/src/cli/cmd_ConfigKeys.ts +2 -2
  45. package/src/cli/cmd_Drill.ts +145 -0
  46. package/src/cli/cmd_Home.ts +50 -3
  47. package/src/cli/cmd_Init.ts +1 -1
  48. package/src/cli/cmd_Media.ts +10 -8
  49. package/src/cli/cmd_Mv.ts +14 -7
  50. package/src/cli/cmd_Review.ts +6 -4
  51. package/src/cli/cmd_Shot.ts +5 -2
  52. package/src/cli/cmd_Smoke.ts +5 -2
  53. package/src/cli/cmd_Social.ts +226 -0
  54. package/src/cli/cmd_Sound.ts +1 -1
  55. package/src/cli/cmd_Start.ts +1 -1
  56. package/src/cli/cmd_Time.ts +1 -1
  57. package/src/cli/cmd_TraceAudit.ts +6 -6
  58. package/src/cli/cmd_Trailer.ts +7 -4
  59. package/src/cli/cmd_Veille.ts +173 -0
  60. package/src/cli/cmd_When.ts +2 -2
  61. package/src/cli/family-pages.ts +19 -16
  62. package/src/cli/registry.ts +13 -2
  63. package/src/cli.ts +5 -2
  64. package/src/collections/actions.ts +1 -49
  65. package/src/collections/checks.ts +2 -1
  66. package/src/collections/collection-types.ts +12 -3
  67. package/src/collections/providers.ts +4 -4
  68. package/src/collections/review.ts +3 -2
  69. package/src/collections/tests.ts +19 -8
  70. package/src/comfy/comfy-panel.ts +2 -2
  71. package/src/contracts/apply-contracts.ts +1 -3
  72. package/src/contracts/contract-manifests.ts +2 -3
  73. package/src/contracts/contract-types.ts +0 -1
  74. package/src/contracts/contracts-engine.ts +0 -3
  75. package/src/contracts/manifests/discord.contract.ts +1 -1
  76. package/src/contracts/manifests/identity.contract.ts +1 -1
  77. package/src/contracts/manifests/itch.contract.ts +1 -1
  78. package/src/contracts/manifests/steam.contract.ts +1 -1
  79. package/src/core/agent-dir-at.ts +12 -0
  80. package/src/core/agent-dir.ts +16 -0
  81. package/src/core/app-icon.ts +9 -3
  82. package/src/core/budget.ts +1 -1
  83. package/src/core/bun-builtins.ts +2 -2
  84. package/src/core/canonical-scripts.ts +2 -2
  85. package/src/core/discover-checks.ts +38 -6
  86. package/src/core/fix-scope.ts +4 -2
  87. package/src/core/floor-resolve.ts +68 -48
  88. package/src/core/floor.ts +9 -0
  89. package/src/core/git-root.ts +24 -0
  90. package/src/core/global-contribution.ts +4 -1
  91. package/src/core/ignored-block.ts +1 -1
  92. package/src/core/ignored-inputs.ts +3 -2
  93. package/src/core/last-good.ts +3 -1
  94. package/src/core/layout.ts +8 -0
  95. package/src/core/log-stamp.ts +36 -0
  96. package/src/core/loop-watch.ts +93 -0
  97. package/src/core/machine-link.ts +134 -0
  98. package/src/core/memory-watch.ts +41 -0
  99. package/src/core/motherhome.ts +2 -2
  100. package/src/core/one-way-in-policy.ts +34 -26
  101. package/src/core/run-ci.ts +9 -11
  102. package/src/core/run-fixers.ts +9 -9
  103. package/src/core/runs-matrix.ts +1 -1
  104. package/src/core/slots.ts +30 -0
  105. package/src/core/trace-audit.ts +50 -9
  106. package/src/core/tree-rev.ts +60 -0
  107. package/src/core/unit-files.ts +42 -0
  108. package/src/drill/render.ts +140 -0
  109. package/src/drill/run.ts +269 -0
  110. package/src/fleet/scan-fleet.ts +6 -5
  111. package/src/home/daemon-jobs.ts +201 -0
  112. package/src/home/global-context.ts +44 -8
  113. package/src/home/gui-app/ShipkitGui.swift +91 -2
  114. package/src/home/home-routes.ts +22 -15
  115. package/src/home/hubs.ts +10 -3
  116. package/src/home/inbox-shape.ts +54 -5
  117. package/src/home/inbox.ts +17 -2
  118. package/src/home/lib-watch.ts +10 -3
  119. package/src/home/machine-stores.ts +15 -29
  120. package/src/home/pm-config.ts +4 -1
  121. package/src/home/pm-inputs.ts +2 -0
  122. package/src/home/resources.ts +7 -2
  123. package/src/home/run-daemon.ts +15 -18
  124. package/src/home/run-pm.ts +3 -1
  125. package/src/home/serve-daemon.ts +4 -3
  126. package/src/home/serve-web.ts +104 -1
  127. package/src/hooks/commit-message.ts +29 -20
  128. package/src/hooks/hook-gates.ts +1 -1
  129. package/src/hooks/leak-guard.ts +69 -9
  130. package/src/hooks/run-hooks.ts +18 -22
  131. package/src/identities/identities.ts +334 -0
  132. package/src/identities/machine-route.ts +126 -0
  133. package/src/identities/machine.ts +62 -0
  134. package/src/init-repo.ts +3 -3
  135. package/src/ledger/check-stats.ts +10 -9
  136. package/src/ledger/gate-checks.ts +32 -1
  137. package/src/ledger/record-kept.ts +112 -0
  138. package/src/ledger/repo-view.ts +10 -0
  139. package/src/ledger/run-log.ts +17 -12
  140. package/src/ledger/run-timeline.ts +8 -4
  141. package/src/ledger/store.ts +7 -0
  142. package/src/ledger/suite-log.ts +17 -13
  143. package/src/media-kinds.ts +3 -2
  144. package/src/media-store/backup/daemon.ts +73 -0
  145. package/src/media-store/backup/keys.ts +25 -0
  146. package/src/media-store/backup/manifest.ts +193 -0
  147. package/src/media-store/backup/restore.ts +192 -0
  148. package/src/media-store/backup/run.ts +278 -0
  149. package/src/media-store/backup/secret.ts +86 -0
  150. package/src/media-store/backup/snapshot.ts +64 -0
  151. package/src/media-store/backup/sources.ts +199 -0
  152. package/src/media-store/content.ts +1 -1
  153. package/src/media-store/daemon.ts +56 -70
  154. package/src/media-store/db.ts +1 -1
  155. package/src/media-store/fact.ts +1 -1
  156. package/src/media-store/hand.ts +1 -1
  157. package/src/media-store/kind.ts +1 -1
  158. package/src/media-store/purge.ts +1 -1
  159. package/src/media-store/put.ts +5 -3
  160. package/src/media-store/remote.ts +1 -1
  161. package/src/media-store/space.ts +24 -5
  162. package/src/mv/mv-md.ts +63 -22
  163. package/src/pages/forward.ts +35 -0
  164. package/src/pages/frame-client.ts +118 -0
  165. package/src/pages/routes.ts +29 -0
  166. package/src/pages/unit.ts +92 -0
  167. package/src/plan/planner.ts +12 -0
  168. package/src/plan/repo-source.ts +19 -5
  169. package/src/reflect/transcript.ts +35 -10
  170. package/src/release/public-clean.ts +319 -0
  171. package/src/release/published-here.ts +22 -0
  172. package/src/release/run-bump.ts +3 -2
  173. package/src/release/run-release.ts +7 -4
  174. package/src/repo-config.ts +71 -13
  175. package/src/review/anim.ts +1 -1
  176. package/src/review/auto.ts +1 -1
  177. package/src/review/cells.ts +15 -1
  178. package/src/review/format.ts +2 -2
  179. package/src/review/http.ts +16 -2
  180. package/src/review/marks.ts +1 -1
  181. package/src/review/media-kind.ts +1 -1
  182. package/src/review/media-read.ts +1 -1
  183. package/src/review/model.ts +27 -6
  184. package/src/review/notes.ts +125 -0
  185. package/src/review/previews.ts +1 -1
  186. package/src/review/project.ts +7 -39
  187. package/src/review/role.ts +1 -1
  188. package/src/review/routes.ts +18 -14
  189. package/src/review/store.ts +42 -2
  190. package/src/review/threads.ts +1 -1
  191. package/src/review/trailer-desk.ts +3 -3
  192. package/src/review/trailer-media.ts +8 -5
  193. package/src/review/trailer-model.ts +1 -1
  194. package/src/review/trailer-routes.ts +1 -1
  195. package/src/review/trailer-shots.ts +22 -5
  196. package/src/review/unit.ts +2 -2
  197. package/src/scaffold/files/agent-handoff.md +3 -0
  198. package/src/scaffold/files/agent-index.md +4 -12
  199. package/src/scaffold/files/tsconfig.json +1 -1
  200. package/src/scaffold/project-scaffold.ts +6 -5
  201. package/src/serve/embed.ts +2 -2
  202. package/src/serve/hub-app/check-words.ts +1 -1
  203. package/src/serve/hub-app/col-card.tsx +3 -17
  204. package/src/serve/hub-app/col-tables-view.tsx +2 -1
  205. package/src/serve/hub-app/cols-svc.ts +0 -13
  206. package/src/serve/hub-app/dock-st.ts +4 -2
  207. package/src/serve/hub-app/dock-view.tsx +2 -0
  208. package/src/serve/hub-app/frames-st.ts +35 -0
  209. package/src/serve/hub-app/hash-route.ts +64 -1
  210. package/src/serve/hub-app/home-st.ts +32 -8
  211. package/src/serve/hub-app/home-strip.css +9 -1
  212. package/src/serve/hub-app/home-strip.tsx +7 -6
  213. package/src/serve/hub-app/home.html +5 -0
  214. package/src/serve/hub-app/hub-app.tsx +51 -7
  215. package/src/serve/hub-app/hub.css +29 -11
  216. package/src/serve/hub-app/icons.tsx +16 -1
  217. package/src/serve/hub-app/identities-st.ts +210 -0
  218. package/src/serve/hub-app/identities-view.tsx +353 -0
  219. package/src/serve/hub-app/identities.css +48 -0
  220. package/src/serve/hub-app/identity-address.ts +52 -0
  221. package/src/serve/hub-app/inbox-st.ts +60 -7
  222. package/src/serve/hub-app/inbox-view.tsx +49 -7
  223. package/src/serve/hub-app/inbox.css +12 -1
  224. package/src/serve/hub-app/index.html +3 -0
  225. package/src/serve/hub-app/kept-cols.tsx +30 -0
  226. package/src/serve/hub-app/keys.ts +10 -2
  227. package/src/serve/hub-app/list-walk.ts +89 -0
  228. package/src/serve/hub-app/machine-st.ts +12 -0
  229. package/src/serve/hub-app/media-svc.ts +1 -1
  230. package/src/serve/hub-app/media-view.tsx +2 -1
  231. package/src/serve/hub-app/pages-frames.tsx +134 -0
  232. package/src/serve/hub-app/pages-svc.ts +111 -0
  233. package/src/serve/hub-app/palette-st.ts +18 -3
  234. package/src/serve/hub-app/palette-view.tsx +9 -2
  235. package/src/serve/hub-app/planned-view.tsx +2 -1
  236. package/src/serve/hub-app/project-list.css +18 -14
  237. package/src/serve/hub-app/project-list.tsx +88 -49
  238. package/src/serve/hub-app/projects-svc.ts +33 -3
  239. package/src/serve/hub-app/repo-sections.ts +19 -2
  240. package/src/serve/hub-app/repo-st.ts +76 -20
  241. package/src/serve/hub-app/review/review-board.tsx +1 -1
  242. package/src/serve/hub-app/review/review-cells.tsx +6 -5
  243. package/src/serve/hub-app/review/review-kit.ts +30 -7
  244. package/src/serve/hub-app/review/review-page.tsx +6 -5
  245. package/src/serve/hub-app/review/review-st.ts +34 -15
  246. package/src/serve/hub-app/review/review-thread.tsx +63 -14
  247. package/src/serve/hub-app/review/review-views.tsx +133 -51
  248. package/src/serve/hub-app/review/thread-st.ts +80 -37
  249. package/src/serve/hub-app/review/trailer-page.tsx +7 -5
  250. package/src/serve/hub-app/review/trailer-st.ts +1 -1
  251. package/src/serve/hub-app/review.css +26 -9
  252. package/src/serve/hub-app/site/site-part.tsx +173 -0
  253. package/src/serve/hub-app/site/site-st.ts +157 -0
  254. package/src/serve/hub-app/site.css +35 -0
  255. package/src/serve/hub-app/social/calendar.tsx +182 -0
  256. package/src/serve/hub-app/social/comms-page.tsx +330 -0
  257. package/src/serve/hub-app/social/kit.tsx +244 -0
  258. package/src/serve/hub-app/social/post-card.tsx +456 -0
  259. package/src/serve/hub-app/social/problems.tsx +60 -0
  260. package/src/serve/hub-app/social/social-model.ts +154 -0
  261. package/src/serve/hub-app/social/social-page.tsx +681 -0
  262. package/src/serve/hub-app/social/social-st.ts +1014 -0
  263. package/src/serve/hub-app/social.css +289 -0
  264. package/src/serve/hub-app/stores/stores-page.tsx +312 -0
  265. package/src/serve/hub-app/stores/stores-st.ts +286 -0
  266. package/src/serve/hub-app/stores.css +54 -0
  267. package/src/serve/hub-app/timeline-geometry.ts +1 -1
  268. package/src/serve/hub-app/timeline-view.tsx +3 -2
  269. package/src/serve/hub-app/tree-build.ts +6 -0
  270. package/src/serve/hub-app/tree-row.tsx +27 -4
  271. package/src/serve/hub-app/tree-svc.ts +18 -49
  272. package/src/serve/hub-app/veille/veille-page.tsx +515 -0
  273. package/src/serve/hub-app/veille/veille-st.ts +443 -0
  274. package/src/serve/hub-app/veille.css +84 -0
  275. package/src/serve/hub-runtime.ts +20 -11
  276. package/src/serve/project-gutter-route.ts +44 -12
  277. package/src/serve/run-lanes.ts +7 -4
  278. package/src/serve/same-origin.ts +1 -1
  279. package/src/serve/serve-hub.ts +20 -12
  280. package/src/serve/tracked-watch.ts +24 -3
  281. package/src/serve/warm-cell.ts +5 -1
  282. package/src/shipkit-files.ts +15 -4
  283. package/src/shipkit.ts +0 -1
  284. package/src/shot/box.ts +160 -0
  285. package/src/shot/browser-slot.ts +74 -0
  286. package/src/shot/client.ts +42 -7
  287. package/src/shot/clip-encoder.ts +108 -24
  288. package/src/shot/film-box.ts +292 -0
  289. package/src/shot/shooter.ts +71 -17
  290. package/src/shot/shot-ask.ts +10 -2
  291. package/src/shot/stepped-clip.ts +5 -4
  292. package/src/site/desk.ts +242 -0
  293. package/src/site/routes.ts +66 -0
  294. package/src/site/unit.ts +62 -0
  295. package/src/social/brands.ts +22 -0
  296. package/src/social/card-drafts.ts +24 -0
  297. package/src/social/compose.ts +97 -0
  298. package/src/social/desk-index.ts +123 -0
  299. package/src/social/desk-wire.ts +64 -0
  300. package/src/social/drafts.ts +183 -0
  301. package/src/social/house.ts +24 -0
  302. package/src/social/load.ts +332 -0
  303. package/src/social/md.ts +70 -0
  304. package/src/social/media-facts.ts +53 -0
  305. package/src/social/media-kind.ts +189 -0
  306. package/src/social/media-limit.ts +42 -0
  307. package/src/social/media-of.ts +30 -0
  308. package/src/social/migrate.ts +123 -0
  309. package/src/social/open.ts +17 -0
  310. package/src/social/post-url.ts +158 -0
  311. package/src/social/presence.ts +332 -0
  312. package/src/social/public-read.ts +53 -0
  313. package/src/social/publish/bluesky.ts +168 -0
  314. package/src/social/publish/discord.ts +76 -0
  315. package/src/social/publish/index.ts +24 -0
  316. package/src/social/publish/secret.ts +13 -0
  317. package/src/social/push.ts +37 -0
  318. package/src/social/richtext.ts +37 -0
  319. package/src/social/routes.ts +186 -0
  320. package/src/social/stats.ts +134 -0
  321. package/src/social/text.ts +267 -0
  322. package/src/social/tracker-route.ts +39 -0
  323. package/src/social/tracker.ts +255 -0
  324. package/src/social/unit.ts +53 -0
  325. package/src/social/writes.ts +130 -0
  326. package/src/start-repo.ts +14 -9
  327. package/src/stores/collection.ts +27 -0
  328. package/src/stores/desk.ts +336 -0
  329. package/src/stores/model.ts +187 -0
  330. package/src/stores/routes.ts +126 -0
  331. package/src/stores/unit.ts +57 -0
  332. package/src/suite/calibrate.ts +127 -0
  333. package/src/suite/core-counters.ts +91 -0
  334. package/src/suite/judge-suites.ts +95 -35
  335. package/src/suite/suite-cli.ts +44 -10
  336. package/src/suite/suite-cpu-preload.ts +34 -9
  337. package/src/trace/tracer.ts +12 -5
  338. package/src/trailer/adapter.ts +5 -1
  339. package/src/trailer/build.ts +45 -12
  340. package/src/trailer/ffmpeg.ts +11 -0
  341. package/src/trailer/footage.ts +30 -13
  342. package/src/trailer/grammar.ts +18 -2
  343. package/src/trailer/graph.ts +28 -6
  344. package/src/trailer/holes.ts +1 -1
  345. package/src/trailer/passage.ts +18 -6
  346. package/src/trailer/plan.ts +74 -3
  347. package/src/trailer/prune.ts +1 -1
  348. package/src/trailer/states.ts +1 -1
  349. package/src/trailer/stitch.ts +67 -26
  350. package/src/trailer/url.ts +1 -1
  351. package/src/trailer/versions.ts +24 -0
  352. package/src/trailer/words.ts +1 -1
  353. package/src/ts/gate-typecheck.ts +32 -0
  354. package/src/ts/typecheck-cli.ts +9 -11
  355. package/src/tui/run-tui.ts +1 -1
  356. package/src/tui/tui-app.tsx +0 -1
  357. package/src/tui/tui-store.ts +1 -1
  358. package/src/veille/asks.ts +155 -0
  359. package/src/veille/auto.ts +31 -0
  360. package/src/veille/batch.ts +27 -0
  361. package/src/veille/chrome.ts +127 -0
  362. package/src/veille/collection.ts +28 -0
  363. package/src/veille/desk.ts +242 -0
  364. package/src/veille/identity.ts +80 -0
  365. package/src/veille/import.ts +68 -0
  366. package/src/veille/log.ts +183 -0
  367. package/src/veille/platforms.ts +118 -0
  368. package/src/veille/reads.ts +66 -0
  369. package/src/veille/replied.ts +110 -0
  370. package/src/veille/routes.ts +185 -0
  371. package/src/veille/service.ts +81 -0
  372. package/src/veille/watch.ts +116 -0
  373. package/src/veille/worth.ts +46 -0
  374. package/src/wiki/scan-md.ts +18 -0
  375. package/src/collections/posts.ts +0 -142
  376. package/src/contracts/manifests/social.contract.ts +0 -20
  377. package/src/scaffold/files/agent-coding.md +0 -35
  378. package/src/ts/typecheck-cache.ts +0 -11
@@ -0,0 +1,118 @@
1
+ // the Veille's words the page and the server share (wiki tools/shipkit/veille.md), pure: no node import, the page
2
+ // bundles it. A reply opens prefilled where the platform has an intent, else he pastes it
3
+
4
+ export const PLATFORMS = ['x', 'threads', 'bluesky', 'mastodon', 'instagram', 'tiktok', 'reddit'] as const
5
+ export type Platform = (typeof PLATFORMS)[number]
6
+ export const isPlatform = (s: unknown): s is Platform => PLATFORMS.some((p) => p === s)
7
+
8
+ /** each platform's column, in the order they stand, with its reply limit */
9
+ export const COLUMNS: readonly { platform: Platform; label: string; max: number }[] = [
10
+ { platform: 'x', label: 'X', max: 280 },
11
+ { platform: 'bluesky', label: 'Bluesky', max: 300 },
12
+ { platform: 'reddit', label: 'Reddit', max: 10000 },
13
+ { platform: 'threads', label: 'Threads', max: 500 },
14
+ { platform: 'mastodon', label: 'Mastodon', max: 500 },
15
+ { platform: 'instagram', label: 'Instagram', max: 2200 },
16
+ { platform: 'tiktok', label: 'TikTok', max: 150 },
17
+ ]
18
+
19
+ /** what a reader sends for one post */
20
+ export type Read = {
21
+ platform: Platform
22
+ id: string
23
+ url: string
24
+ author: string
25
+ name: string
26
+ text: string
27
+ /** where it was posted, when the platform says (a subreddit: `r/IndieDev`); empty else */
28
+ place: string
29
+ at: number | null
30
+ likes: number | null
31
+ reposts: number | null
32
+ replies: number | null
33
+ views: number | null
34
+ followers: number | null
35
+ media: 'image' | 'video' | null
36
+ /** the search query that read it, when his search kept it (His search is his intent); empty else */
37
+ via?: string
38
+ /** X's « Replying to @author » over it, the author's handle */
39
+ replyTo?: string
40
+ }
41
+ /** a post as the log keeps it: its last read, when he first and last saw it, how many reads */
42
+ export type Kept = Read & { first: number; last: number; seen: number }
43
+
44
+ export type Parts = { fresh: number; traction: number; niche: number; seen: number; promo: number }
45
+ export type Group = 'now' | 'maybe' | 'done'
46
+ export type Reply = { text: string; media: string | null; at: number; by: 'agent' | 'owner' }
47
+ export type Replied = { url: string; at: number; how: 'text' | 'page' | 'context' | 'api' }
48
+ /** where an item of the Veille stands in the review store: its id, its state, the lane that claimed it */
49
+ export type Interaction = { id: string; state: string; worker: string | null }
50
+
51
+ export type FeedRow = Kept & {
52
+ key: string
53
+ worth: number
54
+ parts: Parts
55
+ group: Group
56
+ handled: boolean
57
+ passed: string | null
58
+ reply: Reply | null
59
+ /** our reply, detected (His replies, detected) */
60
+ replied: Replied | null
61
+ asked: Interaction | null
62
+ tags: string[]
63
+ }
64
+
65
+ export type Dropped = { url: string; author: string; text: string; at: number }
66
+ export type PlatformReads = {
67
+ read: number
68
+ kept: number
69
+ dropped: number
70
+ /** the last batch: when, and the search that read it (null: a timeline) */
71
+ last: number
72
+ search: string | null
73
+ /** the last dropped posts, newest first */
74
+ droppedPosts: Dropped[]
75
+ }
76
+ /** a page worth scrolling, a button on its column; `day` (0 Sunday to 6) lights it that weekday */
77
+ export type Explore = { platform: string; label: string; url: string; day: number | null }
78
+ /** a file of the project's drafts a reply could lend: repo relative, the draft it comes from, the words it shares */
79
+ export type MediaPick = { path: string; draft: string; words: number }
80
+
81
+ /** what the feed route answers: the rows of each platform on by group, best first, its counts, when its reader last
82
+ * sent; the platforms off and the one review */
83
+ export type VeilleFeed = {
84
+ now: number
85
+ identity: { id: string; name: string }
86
+ /** the platforms he switched off: no column of theirs comes */
87
+ off: Platform[]
88
+ /** the review of every column in the review store while open */
89
+ review: Interaction | null
90
+ /** the one he starts the lane's agent with, and the repo it runs in */
91
+ command: string
92
+ asksRepo: string
93
+ /** `reads`: what its reader did today; `expired`: its posts of the window under `maybe`, never handled nor passed;
94
+ * `explore`: its buttons */
95
+ columns: {
96
+ platform: Platform
97
+ rows: FeedRow[]
98
+ counts: Record<Group, number>
99
+ lastRead: number | null
100
+ reads: PlatformReads | null
101
+ expired: number
102
+ explore: Explore[]
103
+ }[]
104
+ }
105
+ export type VeillePost = { row: FeedRow; media: MediaPick[] }
106
+
107
+ /** the platform's reply page with the text in it; null where none exists (he pastes it on the post) */
108
+ export function replyUrl(row: Pick<FeedRow, 'platform' | 'id'>, text: string): string | null {
109
+ if (row.platform === 'x') return `https://x.com/intent/tweet?in_reply_to=${row.id}&text=${encodeURIComponent(text)}`
110
+ return null
111
+ }
112
+
113
+ /** a reader silent this long shows in orange: its platform's page may have moved */
114
+ export const READER_QUIET_MS = 24 * 3600_000
115
+
116
+ export const keyOf = (p: { platform: string; id: string }): string => `${p.platform}:${p.id}`
117
+ /** a post key as the routes take it */
118
+ export const KEY = /^[a-z]+:[A-Za-z0-9_-]+$/
@@ -0,0 +1,66 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+ import { dayOf } from './log.ts'
4
+ import type { Platform, PlatformReads } from './platforms.ts'
5
+
6
+ // what each platform's reader did today (wiki tools/shipkit/veille.md, Every missing post is explained): the posts read, kept
7
+ // and dropped by the watch list, each counted once a day, the last batch's page, the last dropped posts. On this machine
8
+ // only, the identity's `reads.json`; a new day starts from zero
9
+
10
+ const DROPPED_KEPT = 30
11
+ const IDS_KEPT = 5000
12
+
13
+ type Store = { day: string; platforms: Partial<Record<Platform, PlatformReads & { ids: { read: string[]; kept: string[] } }>> }
14
+
15
+ export class Reads {
16
+ private store: Store | null = null
17
+
18
+ constructor(readonly file: string) {}
19
+
20
+ private load(now: number): Store {
21
+ const day = dayOf(now)
22
+ if (this.store == null)
23
+ try {
24
+ this.store = JSON.parse(readFileSync(this.file, 'utf8')) as Store
25
+ } catch {
26
+ this.store = { day, platforms: {} }
27
+ }
28
+ if (this.store.day !== day) this.store = { day, platforms: {} }
29
+ return this.store
30
+ }
31
+
32
+ /** one batch: what it read, what the watch list kept, from which search */
33
+ add(platform: Platform, read: readonly { id: string; url: string; author: string; text: string }[], keptIds: ReadonlySet<string>, search: string | null, now = Date.now()): void {
34
+ const s = this.load(now)
35
+ const p = (s.platforms[platform] ??= { read: 0, kept: 0, dropped: 0, last: 0, search: null, droppedPosts: [], ids: { read: [], kept: [] } })
36
+ const seen = new Set(p.ids.read)
37
+ const kept = new Set(p.ids.kept)
38
+ for (const x of read) {
39
+ const wasKept = kept.has(x.id)
40
+ if (!seen.has(x.id)) {
41
+ seen.add(x.id)
42
+ p.read++
43
+ }
44
+ if (keptIds.has(x.id) && !wasKept) {
45
+ kept.add(x.id)
46
+ p.kept++
47
+ }
48
+ }
49
+ for (const x of read)
50
+ if (!keptIds.has(x.id) && !p.droppedPosts.some((d) => d.url === x.url))
51
+ p.droppedPosts = [{ url: x.url, author: x.author, text: x.text.slice(0, 160), at: now }, ...p.droppedPosts].slice(0, DROPPED_KEPT)
52
+ p.dropped = [...seen].filter((id) => !kept.has(id)).length
53
+ p.ids = { read: [...seen].slice(-IDS_KEPT), kept: [...kept].slice(-IDS_KEPT) }
54
+ p.last = now
55
+ p.search = search
56
+ mkdirSync(join(this.file, '..'), { recursive: true })
57
+ writeFileSync(this.file, JSON.stringify(s))
58
+ }
59
+
60
+ /** today's reads of one platform, none when its reader sent nothing today */
61
+ of(platform: Platform, now = Date.now()): PlatformReads | null {
62
+ const p = this.load(now).platforms[platform]
63
+ if (p == null) return null
64
+ return { read: p.read, kept: p.kept, dropped: p.dropped, last: p.last, search: p.search, droppedPosts: p.droppedPosts }
65
+ }
66
+ }
@@ -0,0 +1,110 @@
1
+ import type { Kept, Platform, Read, Replied } from './platforms.ts'
2
+
3
+ // his replies, detected (wiki tools/shipkit/veille.md, His replies, detected): our own posts the readers saw, matched to the
4
+ // post they answer by a draft's text, the page they sit under, or « Replying to @author »; and the public reads of our
5
+ // Bluesky and Mastodon accounts. Read only: nothing here acts on a platform
6
+
7
+ /** the post a page is about: X `/<user>/status/<id>`, Threads `/@user/post/<code>`, Bluesky `/profile/<h>/post/<rkey>`,
8
+ * Mastodon `/@user/<id>`; null on any other page */
9
+ export function targetOf(platform: Platform, page: string): string | null {
10
+ const path = page.split(/[?#]/)[0] ?? ''
11
+ const re: Partial<Record<Platform, RegExp>> = {
12
+ x: /^\/[^/]+\/status\/(\d+)/,
13
+ threads: /^\/@[^/]+\/post\/([A-Za-z0-9_-]+)/,
14
+ bluesky: /^\/profile\/[^/]+\/post\/([a-z0-9]+)/,
15
+ mastodon: /^\/@[^/]+\/(\d+)\/?$/,
16
+ }
17
+ return re[platform]?.exec(path)?.[1] ?? null
18
+ }
19
+
20
+ /** a text as a reply compares: no link, no case, one space, no trailing ellipsis */
21
+ const norm = (s: string): string =>
22
+ s
23
+ .replace(/https?:\/\/\S+/g, ' ')
24
+ .replace(/[’‘]/g, "'")
25
+ .toLowerCase()
26
+ .replace(/\s+/g, ' ')
27
+ .replace(/[\s.…]+$/, '')
28
+ .trim()
29
+
30
+ /** the same reply: equal, or one the start of the other (a reader clips, a platform shortens) past 20 characters */
31
+ export function sameText(a: string, b: string): boolean {
32
+ const x = norm(a)
33
+ const y = norm(b)
34
+ if (x === '' || y === '') return false
35
+ if (x === y) return true
36
+ const [short, long] = x.length < y.length ? [x, y] : [y, x]
37
+ return short.length >= 20 && long.startsWith(short)
38
+ }
39
+
40
+ const keyOf = (platform: string, id: string): string => `${platform}:${id}`
41
+
42
+ /** the posts our own posts of one batch answer, each once, the first way that finds it */
43
+ export function detect(
44
+ mine: readonly Read[],
45
+ page: string,
46
+ log: ReadonlyMap<string, Kept>,
47
+ drafts: Readonly<Record<string, { text: string }>>,
48
+ now: number,
49
+ ): { key: string; replied: Replied }[] {
50
+ const out = new Map<string, Replied>()
51
+ for (const p of mine) {
52
+ const add = (key: string | undefined, how: Replied['how']): void => {
53
+ if (key && key !== keyOf(p.platform, p.id) && !out.has(key)) out.set(key, { url: p.url, at: p.at ?? now, how })
54
+ }
55
+ const byText = Object.entries(drafts).find(([k, d]) => k.startsWith(`${p.platform}:`) && sameText(d.text, p.text))?.[0]
56
+ if (byText) {
57
+ add(byText, 'text')
58
+ continue
59
+ }
60
+ const target = targetOf(p.platform, page)
61
+ if (target && target !== p.id && log.has(keyOf(p.platform, target))) {
62
+ add(keyOf(p.platform, target), 'page')
63
+ continue
64
+ }
65
+ if (p.replyTo) {
66
+ const of = [...log.values()].filter((x) => x.platform === p.platform && x.author.toLowerCase() === p.replyTo!.toLowerCase())
67
+ const drafted = of.filter((x) => drafts[keyOf(x.platform, x.id)] != null)
68
+ const pick = drafted.length > 0 ? drafted : of
69
+ if (pick.length === 1) add(keyOf(pick[0]!.platform, pick[0]!.id), 'context')
70
+ }
71
+ }
72
+ return [...out].map(([key, replied]) => ({ key, replied }))
73
+ }
74
+
75
+ const TIMEOUT_MS = 5000
76
+
77
+ async function getJson<T>(url: string): Promise<T> {
78
+ const r = await fetch(url, { signal: AbortSignal.timeout(TIMEOUT_MS), headers: { accept: 'application/json' } })
79
+ if (!r.ok) throw new Error(`${new URL(url).host}: HTTP ${r.status}`)
80
+ return (await r.json()) as T
81
+ }
82
+
83
+ type BskyItem = { post: { uri: string; author: { handle: string }; record: { createdAt?: string; reply?: { parent?: { uri?: string } } } } }
84
+
85
+ /** our Bluesky account's last posts with their replies: each parent's key and our reply */
86
+ export async function blueskyReplies(handle: string): Promise<{ key: string; replied: Replied }[]> {
87
+ const h = handle.replace(/^@/, '')
88
+ const r = await getJson<{ feed: BskyItem[] }>(`https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=${encodeURIComponent(h)}&limit=50&filter=posts_with_replies`)
89
+ return r.feed.flatMap((i) => {
90
+ const parent = i.post.record.reply?.parent?.uri?.split('/').pop()
91
+ if (parent == null || i.post.author.handle !== h) return []
92
+ const rkey = i.post.uri.split('/').pop() ?? ''
93
+ return [{ key: keyOf('bluesky', parent), replied: { url: `https://bsky.app/profile/${h}/post/${rkey}`, at: Date.parse(i.post.record.createdAt ?? '') || Date.now(), how: 'api' as const } }]
94
+ })
95
+ }
96
+
97
+ const mastodonIds = new Map<string, string>()
98
+
99
+ /** our Mastodon account's last statuses: each `in_reply_to_id` (an id of our instance, the one the reader reads) */
100
+ export async function mastodonReplies(handle: string): Promise<{ key: string; replied: Replied }[]> {
101
+ const [user = '', host = ''] = handle.replace(/^@/, '').split('@')
102
+ if (user === '' || host === '') throw new Error(`handle Mastodon ${handle}?`)
103
+ let id = mastodonIds.get(handle)
104
+ if (id == null) {
105
+ id = (await getJson<{ id: string }>(`https://${host}/api/v1/accounts/lookup?acct=${encodeURIComponent(user)}`)).id
106
+ mastodonIds.set(handle, id)
107
+ }
108
+ const list = await getJson<{ url: string; created_at: string; in_reply_to_id: string | null }[]>(`https://${host}/api/v1/accounts/${id}/statuses?limit=40&exclude_reblogs=true`)
109
+ return list.flatMap((s) => (s.in_reply_to_id ? [{ key: keyOf('mastodon', s.in_reply_to_id), replied: { url: s.url, at: Date.parse(s.created_at), how: 'api' as const } }] : []))
110
+ }
@@ -0,0 +1,185 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { basename, join } from 'node:path'
4
+ import { bad, NO_STORE, ranged } from '../review/http.ts'
5
+ import { storeDir, storeStamp } from '../review/store.ts'
6
+ import { houseRepos } from '../serve/project-gutter.ts'
7
+ import { interactions, raisePost, raiseReview, readColumns, reviewRaise, START_COMMAND } from './asks.ts'
8
+ import { openAll, openTab, copyFile, reveal } from './chrome.ts'
9
+ import { brief, mediaFor } from './desk.ts'
10
+ import { draftMedia, DRAFTS_DIR } from '../social/media-of.ts'
11
+ import { veilleOfRepo, type VeilleIdentity } from './identity.ts'
12
+ import { COLUMNS, type FeedRow, isPlatform, KEY, type MediaPick, type Platform, replyUrl, type VeilleFeed, type VeillePost } from './platforms.ts'
13
+ import { deskStamp, oursOf, readPublicReplies, veilleOf } from './service.ts'
14
+
15
+ // the hub's Veille routes (wiki tools/shipkit/veille.md, The page), relative to a repo hub's base: the feed by
16
+ // platform, a post with the media the project's drafts could lend, handled, the reply text, « Proposer », « Revoir »,
17
+ // « Répondre », an explore page opened in the identity's Chrome profile. null: not a path of these
18
+
19
+ const ROWS_A_COLUMN = 60
20
+ const DONE_A_COLUMN = 30
21
+
22
+ /** the identity a repo speaks as, read off its config's `speaksAs` line */
23
+ export function speaksAsOf(root: string): string | null {
24
+ try {
25
+ return /\bspeaksAs\s*:\s*['"]([a-z0-9-]+)['"]/.exec(readFileSync(join(root, 'repo.config.ts'), 'utf8'))?.[1] ?? null
26
+ } catch {
27
+ return null
28
+ }
29
+ }
30
+
31
+ /** the repo's Veille: its identity, and the repo whose review store takes its asks */
32
+ export function veilleAt(root: string): { identity: VeilleIdentity; asks: { name: string; root: string } } | null {
33
+ const name = basename(root)
34
+ const identity = veilleOfRepo(name, speaksAsOf(root))
35
+ if (identity == null) return null
36
+ const want = veilleOf(identity).desk.watch().asks ?? name
37
+ if (want === name) return { identity, asks: { name, root } }
38
+ const repo = houseRepos(root, homedir()).repos.find((r) => r.name === want)
39
+ if (repo == null) throw new Error(`${identity.watchFile}: asks: ${want} is no house repo`)
40
+ return { identity, asks: { name: repo.name, root: repo.path } }
41
+ }
42
+
43
+ async function body(req: Request): Promise<Record<string, unknown>> {
44
+ try {
45
+ return (await req.json()) as Record<string, unknown>
46
+ } catch {
47
+ return {}
48
+ }
49
+ }
50
+
51
+ const ok = (b: object): Response => Response.json({ ok: true, ...b }, { headers: NO_STORE })
52
+
53
+ /** a media file the picker may name: one the project's drafts give, never another file of the disk */
54
+ function draftFile(root: string, path: unknown): string {
55
+ const abs = typeof path === 'string' ? join(root, path) : ''
56
+ if (!draftMedia(root).some((d) => d.posts.some((p) => p.media?.path === abs))) throw new Error(`${String(path)}: no draft of ${DRAFTS_DIR} gives that file`)
57
+ return abs
58
+ }
59
+
60
+ export async function veilleRoutes(root: string, req: Request, path: string): Promise<Response | null> {
61
+ if (!path.startsWith('/api/veille/')) return null
62
+ const at = path.slice('/api/veille/'.length)
63
+ let v: ReturnType<typeof veilleAt>
64
+ try {
65
+ v = veilleAt(root)
66
+ } catch (e) {
67
+ return bad(e, 500)
68
+ }
69
+ if (v == null) return bad(`${basename(root)} shows no Veille: it speaks as no identity with a watch list (wiki tools/shipkit/veille.md)`, 404)
70
+ const { identity } = v
71
+ const { desk, reads } = veilleOf(identity)
72
+ const asksDir = storeDir(v.asks.root)
73
+ const ours = oursOf(identity)
74
+ const url = new URL(req.url)
75
+ const voice = (): { as: string; pages: string[] } => ({ as: identity.id, pages: desk.watch().voice })
76
+ const rowOf = (key: string): FeedRow | null => desk.feed({ all: true, ours, asks: interactions(asksDir).posts }).find((r) => r.key === key) ?? null
77
+ const media = (row: FeedRow): MediaPick[] => mediaFor(row.text, draftMedia(root), root)
78
+ try {
79
+ if (req.method === 'GET') {
80
+ if (at === 'stamp') return Response.json({ stamp: `${deskStamp(identity)}:${storeStamp(asksDir)}` }, { headers: NO_STORE })
81
+ if (at === 'feed') {
82
+ void readPublicReplies(identity)
83
+ const now = Date.now()
84
+ const since = Number(url.searchParams.get('since') ?? 86_400_000)
85
+ const asks = interactions(asksDir)
86
+ const rows = desk.feed({ now, sinceMs: since > 0 ? since : undefined, all: true, ours, asks: asks.posts })
87
+ const lastRead: Partial<Record<Platform, number>> = {}
88
+ for (const p of desk.log.posts().values()) lastRead[p.platform] = Math.max(lastRead[p.platform] ?? 0, p.last)
89
+ const w = desk.watch()
90
+ const off = desk.off()
91
+ const feed: VeilleFeed = {
92
+ now,
93
+ identity: { id: identity.id, name: identity.name },
94
+ off,
95
+ review: asks.review,
96
+ command: START_COMMAND,
97
+ asksRepo: v.asks.name,
98
+ columns: COLUMNS.filter((c) => !off.includes(c.platform)).map((c) => {
99
+ const mine = rows.filter((r) => r.platform === c.platform)
100
+ const of = (g: FeedRow['group']): FeedRow[] => mine.filter((r) => r.group === g)
101
+ const r = reads.of(c.platform, now)
102
+ const last = Math.max(lastRead[c.platform] ?? 0, r?.last ?? 0)
103
+ return {
104
+ platform: c.platform,
105
+ rows: [...of('now'), ...of('maybe')].slice(0, ROWS_A_COLUMN).concat(of('done').slice(0, DONE_A_COLUMN)),
106
+ counts: { now: of('now').length, maybe: of('maybe').length, done: of('done').length },
107
+ lastRead: last > 0 ? last : null,
108
+ reads: r,
109
+ expired: mine.filter((x) => x.group === 'done' && !x.handled && x.passed == null).length,
110
+ explore: w.explore.filter((e) => e.platform === c.platform),
111
+ }
112
+ }),
113
+ }
114
+ return Response.json(feed, { headers: NO_STORE })
115
+ }
116
+ if (at === 'post') {
117
+ const row = rowOf(url.searchParams.get('key') ?? '')
118
+ if (row == null) return bad(`${url.searchParams.get('key')}?`, 404)
119
+ return Response.json({ row, media: media(row) } satisfies VeillePost, { headers: NO_STORE })
120
+ }
121
+ if (at === 'file') return ranged(req, draftFile(root, url.searchParams.get('path')), NO_STORE)
122
+ return null
123
+ }
124
+ if (req.method !== 'POST') return null
125
+ const b = await body(req)
126
+ if (at === 'explore') {
127
+ // an explore button: the page in the identity's Chrome profile, where the extension reads; only a page of the list
128
+ const page = desk.watch().explore.find((e) => e.url === b.url)
129
+ if (page == null) return bad(`${String(b.url)}: not a line of ${identity.watchFile}, Explore`)
130
+ await openTab(page.url, identity.email)
131
+ return ok({})
132
+ }
133
+ if (at === 'review') {
134
+ // « Revoir »: one item for every column on, their active posts as compact lines; an open one is joined
135
+ const open = interactions(asksDir).review
136
+ if (open) return ok({ id: open.id, command: START_COMMAND })
137
+ const off = desk.off()
138
+ const cols = new Map([...readColumns(desk, ours)].filter(([p]) => !off.includes(p)))
139
+ const raise = reviewRaise(cols, voice())
140
+ if (raise == null) return bad('no active post in any column')
141
+ return ok({ id: await raiseReview(asksDir, raise, desk.watch().topic), command: START_COMMAND })
142
+ }
143
+ if (at === 'platform') {
144
+ const platform = String(b.platform ?? '')
145
+ if (!isPlatform(platform)) return bad(`platform ${platform}?`)
146
+ desk.setOn(platform, b.on !== false)
147
+ return ok({ off: desk.off() })
148
+ }
149
+ if (at === 'file-copy') {
150
+ await copyFile(draftFile(root, b.path))
151
+ return ok({})
152
+ }
153
+ if (at === 'file-reveal') {
154
+ await reveal(draftFile(root, b.path))
155
+ return ok({})
156
+ }
157
+ const key = String(b.key ?? '')
158
+ if (!KEY.test(key) || !isPlatform(key.split(':')[0])) return bad(`post ${key}?`)
159
+ if (at === 'handled') {
160
+ desk.setHandled(key, b.on !== false)
161
+ return ok({})
162
+ }
163
+ if (at === 'text') {
164
+ if (typeof b.text !== 'string') return bad('{ key, text } is expected')
165
+ desk.writeReply(key, { text: b.text.slice(0, 5000), media: typeof b.media === 'string' && b.media !== '' ? b.media : null, at: Date.now(), by: 'owner' })
166
+ return ok({})
167
+ }
168
+ const row = rowOf(key)
169
+ if (row == null) return bad(`${key}: not in the log`, 404)
170
+ if (at === 'propose') {
171
+ if (row.asked) return ok({ id: row.asked.id, command: START_COMMAND })
172
+ const title = `Répondre à @${row.author} : ${row.text.length > 60 ? `${row.text.slice(0, 59)}…` : row.text}`
173
+ return ok({ id: await raisePost(asksDir, { key, title, brief: brief(row, media(row), voice()), topic: desk.watch().topic }), command: START_COMMAND })
174
+ }
175
+ if (at === 'open') {
176
+ const text = typeof b.text === 'string' ? b.text : (row.reply?.text ?? '')
177
+ const file = typeof b.media === 'string' && b.media !== '' ? draftFile(root, b.media) : null
178
+ await openAll([replyUrl(row, text) ?? row.url], file, identity.email)
179
+ return ok({ prefilled: replyUrl(row, text) != null })
180
+ }
181
+ return null
182
+ } catch (e) {
183
+ return bad(e)
184
+ }
185
+ }
@@ -0,0 +1,81 @@
1
+ import { readdirSync, statSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+ import { Desk } from './desk.ts'
4
+ import { handleKey, type VeilleIdentity } from './identity.ts'
5
+ import { Reads } from './reads.ts'
6
+ import { blueskyReplies, detect, mastodonReplies } from './replied.ts'
7
+ import type { Batch } from './log.ts'
8
+ import type { Replied } from './platforms.ts'
9
+ import { kept, matches, searchOf } from './watch.ts'
10
+
11
+ // one identity's Veille in this process: its desk and its reads, shared by the daemon's batch route and every hub page
12
+ // that shows it, so a batch and a feed read one index. The state is in files: another process sees it too
13
+
14
+ type Held = { desk: Desk; reads: Reads; publicAt: number }
15
+ const held = new Map<string, Held>()
16
+
17
+ export function veilleOf(x: VeilleIdentity): Held {
18
+ let h = held.get(x.id)
19
+ if (h == null || h.desk.dir !== x.logDir) {
20
+ h = { desk: new Desk(x.logDir, x.watchFile), reads: new Reads(join(x.logDir, 'reads.json')), publicAt: 0 }
21
+ held.set(x.id, h)
22
+ }
23
+ return h
24
+ }
25
+
26
+ /** the identity's own accounts, `<platform>:<handle>` */
27
+ export const oursOf = (x: VeilleIdentity): Set<string> => new Set(x.accounts.map((a) => handleKey(a.platform, a.handle)))
28
+
29
+ /** one batch of the extension: our own posts say which posts he replied to; of the others only the niche is kept, or
30
+ * every post of his search when its query is of the niche (What is kept) */
31
+ export function takeBatch(x: VeilleIdentity, b: Batch, now = Date.now()): { lines: number; dropped: number } {
32
+ const { desk, reads } = veilleOf(x)
33
+ const us = oursOf(x)
34
+ const mine = b.posts.filter((p) => us.has(handleKey(p.platform, p.author)))
35
+ const theirs = b.posts.filter((p) => !us.has(handleKey(p.platform, p.author)))
36
+ for (const r of detect(mine, b.page, desk.log.posts(), desk.drafts(), now)) desk.setReplied(r.key, r.replied, now)
37
+ const w = desk.watch()
38
+ const search = searchOf(b.page)
39
+ const via = search != null && matches({ text: search }, w).length > 0 ? search : null
40
+ const posts = via ? theirs.map((p) => ({ ...p, via })) : theirs.filter((p) => kept(p, w))
41
+ reads.add(b.platform, theirs, new Set(posts.map((p) => p.id)), search, now)
42
+ return { ...desk.log.add({ ...b, posts }, now), dropped: theirs.length - posts.length }
43
+ }
44
+
45
+ /** our Bluesky and Mastodon accounts' public reads, at most this often (His replies, detected) */
46
+ const PUBLIC_EVERY_MS = 2 * 60_000
47
+
48
+ /** our Bluesky and Mastodon replies read from their public APIs, a parent the log holds marked; never awaited by a page */
49
+ export async function readPublicReplies(x: VeilleIdentity): Promise<void> {
50
+ const h = veilleOf(x)
51
+ if (Date.now() - h.publicAt < PUBLIC_EVERY_MS) return
52
+ h.publicAt = Date.now()
53
+ const log = h.desk.log.posts()
54
+ const reads: Record<string, (handle: string) => Promise<{ key: string; replied: Replied }[]>> = { bluesky: blueskyReplies, mastodon: mastodonReplies }
55
+ for (const a of x.accounts) {
56
+ const read = reads[a.platform]
57
+ if (read == null) continue
58
+ try {
59
+ for (const r of await read(a.handle)) if (log.has(r.key)) h.desk.setReplied(r.key, r.replied)
60
+ } catch (e) {
61
+ console.warn(`WARN veille: ${x.id} ${a.platform} replies not read (${(e as Error).message})`)
62
+ }
63
+ }
64
+ }
65
+
66
+ /** the newest file of a folder, its time; 0 when it holds none */
67
+ function newest(dir: string): number {
68
+ let t = 0
69
+ try {
70
+ for (const f of readdirSync(dir)) t = Math.max(t, statSync(join(dir, f)).mtimeMs)
71
+ } catch {
72
+ // no such folder yet
73
+ }
74
+ return t
75
+ }
76
+
77
+ /** moves at every write of the log, a mark, a draft or a pass, from any process */
78
+ export const deskStamp = (x: VeilleIdentity): string => {
79
+ const { desk } = veilleOf(x)
80
+ return `${desk.log.stamp}:${newest(desk.dir)}:${newest(desk.repliesDir)}`
81
+ }