rvlib-shipkit 2.12.0 → 2.13.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.
- package/CHANGELOG.md +48 -13
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/check.ts +1 -1
- package/src/checks/SK001-package-json-shape.check.ts +4 -0
- package/src/checks/SK003-claude-md-shape.check.ts +1 -1
- package/src/checks/SK004-gitignore-policy.check.ts +27 -2
- package/src/checks/SK005-rvlib-versions.check.ts +1 -1
- package/src/checks/SK008-reviewer-agent.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +1 -1
- package/src/checks/SK015-nested-repo.check.ts +1 -1
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Media.ts +7 -5
- package/src/cli/cmd_Review.ts +4 -2
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +4 -1
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +5 -2
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/family-pages.ts +3 -0
- package/src/cli/registry.ts +13 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +1 -49
- package/src/collections/checks.ts +2 -1
- package/src/collections/collection-types.ts +11 -2
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +2 -1
- package/src/collections/tests.ts +19 -8
- package/src/contracts/apply-contracts.ts +1 -3
- package/src/contracts/contract-manifests.ts +2 -3
- package/src/contracts/contract-types.ts +0 -1
- package/src/contracts/contracts-engine.ts +0 -3
- package/src/core/app-icon.ts +9 -3
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/discover-checks.ts +37 -5
- package/src/core/fix-scope.ts +4 -2
- package/src/core/floor-resolve.ts +68 -48
- package/src/core/floor.ts +9 -0
- package/src/core/git-root.ts +24 -0
- package/src/core/last-good.ts +3 -1
- package/src/core/layout.ts +8 -0
- package/src/core/log-stamp.ts +36 -0
- package/src/core/loop-watch.ts +93 -0
- package/src/core/machine-link.ts +134 -0
- package/src/core/memory-watch.ts +41 -0
- package/src/core/one-way-in-policy.ts +27 -19
- package/src/core/run-ci.ts +6 -8
- package/src/core/run-fixers.ts +9 -9
- package/src/core/slots.ts +21 -0
- package/src/core/tree-rev.ts +60 -0
- package/src/core/unit-files.ts +42 -0
- package/src/drill/render.ts +140 -0
- package/src/drill/run.ts +269 -0
- package/src/fleet/scan-fleet.ts +6 -5
- package/src/home/daemon-jobs.ts +201 -0
- package/src/home/global-context.ts +34 -1
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +53 -4
- package/src/home/inbox.ts +16 -1
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +2 -0
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +28 -19
- package/src/hooks/leak-guard.ts +10 -3
- package/src/hooks/run-hooks.ts +2 -6
- package/src/identities/identities.ts +334 -0
- package/src/identities/machine-route.ts +126 -0
- package/src/identities/machine.ts +62 -0
- package/src/init-repo.ts +1 -1
- package/src/ledger/check-stats.ts +10 -9
- package/src/ledger/gate-checks.ts +32 -1
- package/src/ledger/record-kept.ts +112 -0
- package/src/ledger/repo-view.ts +10 -0
- package/src/ledger/run-log.ts +17 -12
- package/src/ledger/run-timeline.ts +8 -4
- package/src/ledger/store.ts +7 -0
- package/src/ledger/suite-log.ts +17 -13
- package/src/media-kinds.ts +2 -1
- package/src/media-store/backup/daemon.ts +73 -0
- package/src/media-store/backup/keys.ts +25 -0
- package/src/media-store/backup/manifest.ts +193 -0
- package/src/media-store/backup/restore.ts +192 -0
- package/src/media-store/backup/run.ts +278 -0
- package/src/media-store/backup/secret.ts +86 -0
- package/src/media-store/backup/snapshot.ts +64 -0
- package/src/media-store/backup/sources.ts +199 -0
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/put.ts +4 -2
- package/src/media-store/space.ts +23 -4
- package/src/pages/forward.ts +35 -0
- package/src/pages/frame-client.ts +118 -0
- package/src/pages/routes.ts +29 -0
- package/src/pages/unit.ts +92 -0
- package/src/plan/planner.ts +12 -0
- package/src/plan/repo-source.ts +19 -5
- package/src/reflect/transcript.ts +35 -10
- package/src/release/public-clean.ts +301 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +2 -1
- package/src/release/run-release.ts +4 -1
- package/src/repo-config.ts +53 -2
- package/src/review/http.ts +16 -2
- package/src/review/model.ts +15 -4
- package/src/review/notes.ts +77 -0
- package/src/review/project.ts +6 -38
- package/src/review/routes.ts +4 -12
- package/src/review/store.ts +41 -1
- package/src/review/trailer-media.ts +7 -4
- package/src/review/trailer-shots.ts +21 -4
- package/src/review/unit.ts +1 -1
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/project-scaffold.ts +5 -4
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/col-card.tsx +3 -17
- package/src/serve/hub-app/col-tables-view.tsx +2 -1
- package/src/serve/hub-app/cols-svc.ts +0 -13
- package/src/serve/hub-app/dock-st.ts +4 -2
- package/src/serve/hub-app/dock-view.tsx +2 -0
- package/src/serve/hub-app/frames-st.ts +35 -0
- package/src/serve/hub-app/hash-route.ts +64 -1
- package/src/serve/hub-app/home-st.ts +31 -7
- package/src/serve/hub-app/home-strip.css +9 -1
- package/src/serve/hub-app/home-strip.tsx +7 -6
- package/src/serve/hub-app/home.html +5 -0
- package/src/serve/hub-app/hub-app.tsx +49 -5
- package/src/serve/hub-app/hub.css +29 -11
- package/src/serve/hub-app/icons.tsx +16 -1
- package/src/serve/hub-app/identities-st.ts +210 -0
- package/src/serve/hub-app/identities-view.tsx +352 -0
- package/src/serve/hub-app/identities.css +48 -0
- package/src/serve/hub-app/identity-address.ts +52 -0
- package/src/serve/hub-app/inbox-st.ts +59 -6
- package/src/serve/hub-app/inbox-view.tsx +48 -6
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +10 -2
- package/src/serve/hub-app/list-walk.ts +89 -0
- package/src/serve/hub-app/machine-st.ts +12 -0
- package/src/serve/hub-app/media-view.tsx +2 -1
- package/src/serve/hub-app/pages-frames.tsx +134 -0
- package/src/serve/hub-app/pages-svc.ts +111 -0
- package/src/serve/hub-app/palette-st.ts +18 -3
- package/src/serve/hub-app/palette-view.tsx +9 -2
- package/src/serve/hub-app/planned-view.tsx +2 -1
- package/src/serve/hub-app/project-list.css +18 -14
- package/src/serve/hub-app/project-list.tsx +88 -49
- package/src/serve/hub-app/projects-svc.ts +33 -3
- package/src/serve/hub-app/repo-sections.ts +19 -2
- package/src/serve/hub-app/repo-st.ts +75 -19
- package/src/serve/hub-app/review/review-cells.tsx +3 -3
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +1 -1
- package/src/serve/hub-app/review/review-st.ts +19 -8
- package/src/serve/hub-app/review/review-thread.tsx +11 -9
- package/src/serve/hub-app/review/review-views.tsx +84 -19
- package/src/serve/hub-app/review/thread-st.ts +1 -10
- package/src/serve/hub-app/review/trailer-page.tsx +2 -1
- package/src/serve/hub-app/review.css +17 -8
- package/src/serve/hub-app/site/site-part.tsx +173 -0
- package/src/serve/hub-app/site/site-st.ts +157 -0
- package/src/serve/hub-app/site.css +35 -0
- package/src/serve/hub-app/social/calendar.tsx +182 -0
- package/src/serve/hub-app/social/comms-page.tsx +306 -0
- package/src/serve/hub-app/social/kit.tsx +244 -0
- package/src/serve/hub-app/social/post-card.tsx +456 -0
- package/src/serve/hub-app/social/problems.tsx +60 -0
- package/src/serve/hub-app/social/social-model.ts +154 -0
- package/src/serve/hub-app/social/social-page.tsx +674 -0
- package/src/serve/hub-app/social/social-st.ts +986 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +311 -0
- package/src/serve/hub-app/stores/stores-st.ts +286 -0
- package/src/serve/hub-app/stores.css +54 -0
- package/src/serve/hub-app/timeline-geometry.ts +1 -1
- package/src/serve/hub-app/timeline-view.tsx +3 -2
- package/src/serve/hub-app/tree-build.ts +6 -0
- package/src/serve/hub-app/tree-row.tsx +27 -4
- package/src/serve/hub-app/tree-svc.ts +18 -49
- package/src/serve/hub-app/veille/veille-page.tsx +514 -0
- package/src/serve/hub-app/veille/veille-st.ts +443 -0
- package/src/serve/hub-app/veille.css +84 -0
- package/src/serve/hub-runtime.ts +14 -9
- package/src/serve/project-gutter-route.ts +44 -12
- package/src/serve/run-lanes.ts +7 -4
- package/src/serve/same-origin.ts +1 -1
- package/src/serve/serve-hub.ts +20 -12
- package/src/serve/tracked-watch.ts +24 -3
- package/src/serve/warm-cell.ts +5 -1
- package/src/shipkit-files.ts +15 -4
- package/src/shipkit.ts +0 -1
- package/src/shot/box.ts +162 -0
- package/src/shot/browser-slot.ts +62 -0
- package/src/shot/client.ts +43 -7
- package/src/shot/clip-encoder.ts +93 -12
- package/src/shot/film-box.ts +188 -0
- package/src/shot/shooter.ts +50 -15
- package/src/shot/shot-ask.ts +10 -2
- package/src/shot/stepped-clip.ts +5 -4
- package/src/site/desk.ts +242 -0
- package/src/site/routes.ts +66 -0
- package/src/site/unit.ts +62 -0
- package/src/social/brands.ts +22 -0
- package/src/social/compose.ts +97 -0
- package/src/social/desk-index.ts +123 -0
- package/src/social/desk-wire.ts +64 -0
- package/src/social/drafts.ts +183 -0
- package/src/social/house.ts +24 -0
- package/src/social/load.ts +319 -0
- package/src/social/md.ts +70 -0
- package/src/social/media-facts.ts +53 -0
- package/src/social/media-kind.ts +189 -0
- package/src/social/media-limit.ts +42 -0
- package/src/social/media-of.ts +30 -0
- package/src/social/migrate.ts +123 -0
- package/src/social/open.ts +17 -0
- package/src/social/post-url.ts +158 -0
- package/src/social/presence.ts +332 -0
- package/src/social/public-read.ts +53 -0
- package/src/social/publish/bluesky.ts +168 -0
- package/src/social/publish/discord.ts +76 -0
- package/src/social/publish/index.ts +24 -0
- package/src/social/publish/secret.ts +13 -0
- package/src/social/push.ts +31 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +180 -0
- package/src/social/stats.ts +134 -0
- package/src/social/text.ts +267 -0
- package/src/social/tracker-route.ts +39 -0
- package/src/social/tracker.ts +255 -0
- package/src/social/unit.ts +53 -0
- package/src/social/writes.ts +130 -0
- package/src/start-repo.ts +14 -9
- package/src/stores/collection.ts +27 -0
- package/src/stores/desk.ts +336 -0
- package/src/stores/model.ts +187 -0
- package/src/stores/routes.ts +126 -0
- package/src/stores/unit.ts +57 -0
- package/src/suite/calibrate.ts +127 -0
- package/src/suite/core-counters.ts +91 -0
- package/src/suite/judge-suites.ts +94 -34
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trailer/adapter.ts +4 -0
- package/src/trailer/build.ts +42 -11
- package/src/trailer/ffmpeg.ts +11 -0
- package/src/trailer/footage.ts +30 -13
- package/src/trailer/grammar.ts +18 -2
- package/src/trailer/graph.ts +28 -6
- package/src/trailer/passage.ts +17 -5
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/tui-app.tsx +0 -1
- package/src/veille/asks.ts +155 -0
- package/src/veille/auto.ts +31 -0
- package/src/veille/batch.ts +27 -0
- package/src/veille/chrome.ts +127 -0
- package/src/veille/collection.ts +28 -0
- package/src/veille/desk.ts +242 -0
- package/src/veille/identity.ts +80 -0
- package/src/veille/import.ts +68 -0
- package/src/veille/log.ts +183 -0
- package/src/veille/platforms.ts +118 -0
- package/src/veille/reads.ts +66 -0
- package/src/veille/replied.ts +110 -0
- package/src/veille/routes.ts +185 -0
- package/src/veille/service.ts +81 -0
- package/src/veille/watch.ts +116 -0
- package/src/veille/worth.ts +46 -0
- package/src/wiki/scan-md.ts +18 -0
- package/src/collections/posts.ts +0 -142
- package/src/contracts/manifests/social.contract.ts +0 -20
- package/src/scaffold/files/agent-coding.md +0 -35
- package/src/ts/typecheck-cache.ts +0 -11
|
@@ -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 build/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 build/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
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import type { Explore } from './platforms.ts'
|
|
4
|
+
|
|
5
|
+
// the watch list (wiki build/shipkit/veille.md, What is kept): the identity's `veille.md`, the one file he edits. Its
|
|
6
|
+
// tags, keywords and authors decide which posts the log keeps; its explore lines are the columns' buttons; its voice the
|
|
7
|
+
// pages a reply reads; its rules the numbers of the worth; its front matter the repo whose review store takes the asks
|
|
8
|
+
|
|
9
|
+
export type Rules = { now: number; maybe: number; halfLifeH: number; maxAgeD: number; crowd: number; promo: number; promoWords: number; autoReviewMin: number }
|
|
10
|
+
/** `asks`: the house repo whose review store takes the items, `topic` their topic there; `voice`: the pages and the skill
|
|
11
|
+
* a reply reads, `~` expanded */
|
|
12
|
+
export type Watch = { asks: string | null; topic: string | null; tags: string[]; keywords: string[]; authors: string[]; explore: Explore[]; voice: string[]; rules: Rules }
|
|
13
|
+
|
|
14
|
+
const DEFAULTS: Rules = { now: 45, maybe: 15, halfLifeH: 96, maxAgeD: 7, crowd: 40, promo: 0.4, promoWords: 8, autoReviewMin: 30 }
|
|
15
|
+
const RULE_KEYS: Record<string, keyof Rules> = {
|
|
16
|
+
now: 'now',
|
|
17
|
+
maybe: 'maybe',
|
|
18
|
+
'half-life-h': 'halfLifeH',
|
|
19
|
+
'max-age-d': 'maxAgeD',
|
|
20
|
+
crowd: 'crowd',
|
|
21
|
+
promo: 'promo',
|
|
22
|
+
'promo-words': 'promoWords',
|
|
23
|
+
'auto-review-min': 'autoReviewMin',
|
|
24
|
+
}
|
|
25
|
+
const DAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
|
|
26
|
+
|
|
27
|
+
/** `- <platform>: <label> <url> [(<weekday>)]`; a wrong line fails loud */
|
|
28
|
+
function exploreOf(line: string, file: string): Explore {
|
|
29
|
+
const m = /^([a-z]+):\s+(.+?)\s+(https:\/\/\S+)(?:\s+\(([a-z]+)\))?$/i.exec(line)
|
|
30
|
+
if (m == null) throw new Error(`${file}, Explore: « ${line} » is not « <platform>: <label> <url> [(<weekday>)] »`)
|
|
31
|
+
const day = m[4] == null ? null : DAYS.indexOf(m[4].toLowerCase())
|
|
32
|
+
if (day === -1) throw new Error(`${file}, Explore: « ${m[4]} » is not a weekday (${DAYS.join(', ')})`)
|
|
33
|
+
return { platform: m[1]!.toLowerCase(), label: m[2]!, url: m[3]!, day }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** the file's sections as lists and its rules table; a rule it lacks keeps its default, a wrong one fails loud */
|
|
37
|
+
export function parseWatch(text: string, file = 'veille.md'): Watch {
|
|
38
|
+
const front = /^---\n([\s\S]*?)\n---\n/.exec(text)
|
|
39
|
+
const meta = new Map((front?.[1] ?? '').split('\n').flatMap((l) => {
|
|
40
|
+
const m = /^([a-z-]+):\s*(.*?)\s*$/.exec(l)
|
|
41
|
+
return m ? [[m[1]!, m[2]!] as const] : []
|
|
42
|
+
}))
|
|
43
|
+
const sections = new Map<string, string[]>()
|
|
44
|
+
let at = ''
|
|
45
|
+
for (const line of text.slice(front?.[0].length ?? 0).split('\n')) {
|
|
46
|
+
const h = /^##\s+(.+?)\s*$/.exec(line)
|
|
47
|
+
if (h) at = h[1]!.toLowerCase()
|
|
48
|
+
else sections.set(at, [...(sections.get(at) ?? []), line])
|
|
49
|
+
}
|
|
50
|
+
const lines = (name: string): string[] =>
|
|
51
|
+
(sections.get(name) ?? []).flatMap((l) => {
|
|
52
|
+
const m = /^\s*[-*]\s+(.+?)\s*$/.exec(l)
|
|
53
|
+
return m ? [m[1]!] : []
|
|
54
|
+
})
|
|
55
|
+
const items = (name: string): string[] => lines(name).map((l) => l.replace(/^#/, '').toLowerCase())
|
|
56
|
+
const rules = { ...DEFAULTS }
|
|
57
|
+
for (const l of sections.get('rules') ?? []) {
|
|
58
|
+
const m = /^\|\s*([a-z-]+)\s*\|\s*([^|]+?)\s*\|/.exec(l)
|
|
59
|
+
if (m == null || m[1] === 'rule' || /^-+$/.test(m[1]!)) continue
|
|
60
|
+
const key = RULE_KEYS[m[1]!]
|
|
61
|
+
const n = Number(m[2])
|
|
62
|
+
if (key == null) throw new Error(`${file}: no rule « ${m[1]} » (${Object.keys(RULE_KEYS).join(', ')})`)
|
|
63
|
+
if (!Number.isFinite(n) || n <= 0) throw new Error(`${file}: rule ${m[1]} is « ${m[2]} », a positive number is expected`)
|
|
64
|
+
rules[key] = n
|
|
65
|
+
}
|
|
66
|
+
const voice = lines('voice').map((l) => l.replace(/^`|`$/g, '').replace(/^~(?=\/)/, homedir()))
|
|
67
|
+
return { asks: meta.get('asks') || null, topic: meta.get('topic') || null, tags: items('tags'), keywords: items('keywords'), authors: items('watch'), explore: lines('explore').map((l) => exploreOf(l, file)), voice, rules }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const cache = new Map<string, { at: number; watch: Watch }>()
|
|
71
|
+
|
|
72
|
+
/** the file, read again at most once a second */
|
|
73
|
+
export function watch(file: string): Watch {
|
|
74
|
+
const held = cache.get(file)
|
|
75
|
+
if (held && Date.now() - held.at < 1000) return held.watch
|
|
76
|
+
const w = parseWatch(readFileSync(file, 'utf8'), file)
|
|
77
|
+
cache.set(file, { at: Date.now(), watch: w })
|
|
78
|
+
return w
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const fold = (s: string): string => s.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase()
|
|
82
|
+
|
|
83
|
+
/** the tags and keywords a post holds, each once and without spaces: a `#tag` in its text or in the search that read it
|
|
84
|
+
* (`via`), its subreddit, a keyword phrase (also written without its spaces) */
|
|
85
|
+
export function matches(p: { text: string; place?: string; via?: string }, w: Pick<Watch, 'tags' | 'keywords'>): string[] {
|
|
86
|
+
const text = fold(p.via ? `${p.text} ${viaTags(p.via)}` : p.text)
|
|
87
|
+
const hashtags = new Set([...text.matchAll(/#([\p{L}\p{N}_]+)/gu)].map((m) => m[1]!))
|
|
88
|
+
const place = fold(p.place ?? '').replace(/^r\//, '')
|
|
89
|
+
const words = ` ${text.replace(/[^\p{L}\p{N}]+/gu, ' ')} `
|
|
90
|
+
const tags = w.tags.filter((t) => hashtags.has(t) || place === t)
|
|
91
|
+
const keywords = w.keywords.filter((k) => words.includes(` ${k} `) || words.includes(` ${k.replaceAll(' ', '')} `))
|
|
92
|
+
// a keyword and the tag it spells without its spaces (« game dev », #gamedev) are one word
|
|
93
|
+
return [...new Set([...tags, ...keywords.map((k) => k.replaceAll(' ', ''))])]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** a search query read as tags: each word also a `#word`, so « indiedev » counts like « #indiedev » */
|
|
97
|
+
const viaTags = (q: string): string => `${q} ${q.split(/\s+/).filter((x) => x !== '' && !x.startsWith('#')).map((x) => `#${x}`).join(' ')}`
|
|
98
|
+
|
|
99
|
+
/** the log keeps it: a tag, a keyword, or an author he watches */
|
|
100
|
+
export const kept = (p: { platform: string; author: string; text: string; place?: string; via?: string }, w: Watch): boolean =>
|
|
101
|
+
matches(p, w).length > 0 || w.authors.includes(`${p.platform}:${p.author.toLowerCase()}`)
|
|
102
|
+
|
|
103
|
+
/** the query of a search or tag page (His search is his intent): its `q`, or the tag of a tag
|
|
104
|
+
* page as `#tag`; null on a timeline */
|
|
105
|
+
export function searchOf(page: string): string | null {
|
|
106
|
+
let u: URL
|
|
107
|
+
try {
|
|
108
|
+
u = new URL(page, 'https://example.com')
|
|
109
|
+
} catch {
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
const tag = /^\/(?:hashtag|tags|tag|explore\/tags)\/([^/]+)/.exec(u.pathname)?.[1]
|
|
113
|
+
if (tag) return `#${decodeURIComponent(tag)}`
|
|
114
|
+
const q = /\/search\/?$|\/explore\/search\//.test(u.pathname) ? u.searchParams.get('q') : null
|
|
115
|
+
return q?.trim() ? q.trim().slice(0, 120) : null
|
|
116
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Group, Parts } from './platforms.ts'
|
|
2
|
+
import type { Rules } from './watch.ts'
|
|
3
|
+
|
|
4
|
+
// worth replying (wiki build/shipkit/veille.md, Worth replying): five parts of 0 to 1 and one number of 0 to 100. Every
|
|
5
|
+
// constant is a rule of the identity's watch list
|
|
6
|
+
|
|
7
|
+
export type Counts = { text: string; likes: number | null; reposts: number | null; replies: number | null; views: number | null; followers: number | null; at: number | null; first: number }
|
|
8
|
+
|
|
9
|
+
const H = 3600_000
|
|
10
|
+
const interactions = (p: Counts): number => (p.likes ?? 0) + 3 * (p.reposts ?? 0) + 2 * (p.replies ?? 0) + (p.views ?? 0) / 100
|
|
11
|
+
|
|
12
|
+
const STORE = /\b(?:store\.steampowered\.com|s\.team|itch\.io|apps\.apple\.com|play\.google\.com)\b/i
|
|
13
|
+
/** a call to buy or wishlist; « my wishlist », « wishlist count » and #wishlistwednesday are not calls */
|
|
14
|
+
const CALL =
|
|
15
|
+
/(?<![#\w])(?<!(?:my|your|our|the|to) )wish ?list(?!s\b|ed\b|\s*(?:count|goal|number|milestone|wednesday))|\bout now\b|\bdemo out\b|\bon sale\b|\bavailable now\b|\bplay the demo\b|\b(?:get|buy|grab) it now\b|\bbuy now\b/i
|
|
16
|
+
const FIRST_PERSON = /\b(?:i|i'm|i've|i'd|i'll|me|my|we|we're|we've|our)\b/i
|
|
17
|
+
|
|
18
|
+
/** an ad or a post to talk to (wiki build/shipkit/veille.md, Worth replying): 1 with no call; halfway for a dev's own work
|
|
19
|
+
* with a call, in `promoWords` words or more; `promo` for any other call */
|
|
20
|
+
export function promoOf(text: string, r: Pick<Rules, 'promo' | 'promoWords'>): number {
|
|
21
|
+
const t = text.replace(/[’‘]/g, "'")
|
|
22
|
+
if (!STORE.test(t) && !CALL.test(t)) return 1
|
|
23
|
+
const rest = t
|
|
24
|
+
.replace(/https?:\/\/\S+/g, ' ')
|
|
25
|
+
.replace(/[#@][\p{L}\p{N}_]+/gu, ' ')
|
|
26
|
+
.replace(new RegExp(CALL.source, 'gi'), ' ')
|
|
27
|
+
const words = rest.split(/[^\p{L}\p{N}']+/u).filter((w) => w.length > 1 || /^[ai]$/i.test(w)).length
|
|
28
|
+
return FIRST_PERSON.test(rest) && words >= r.promoWords ? (1 + r.promo) / 2 : r.promo
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** the author is notified of every reply: the crowd is the main penalty, the age a soft one capped at `maxAgeD` */
|
|
32
|
+
export function parts(p: Counts, matched: number, now: number, r: Rules): Parts {
|
|
33
|
+
const ageH = Math.max(0, now - (p.at ?? p.first)) / H
|
|
34
|
+
return {
|
|
35
|
+
fresh: ageH > r.maxAgeD * 24 ? 0 : 0.5 ** (ageH / r.halfLifeH),
|
|
36
|
+
traction: Math.min(1, Math.log10(1 + interactions(p) + (p.followers ?? 0) / 100) / 4),
|
|
37
|
+
niche: Math.min(1, 0.6 + 0.2 * matched),
|
|
38
|
+
seen: 1 / (1 + (p.replies ?? 0) / r.crowd),
|
|
39
|
+
promo: promoOf(p.text, r),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const worthOf = (x: Parts): number => Math.round(100 * x.fresh * (0.3 + 0.7 * x.traction) * x.niche * x.seen * x.promo)
|
|
44
|
+
|
|
45
|
+
/** its group: done when handled or passed, else by its worth; under `maybe` it has expired */
|
|
46
|
+
export const groupOf = (worth: number, closed: boolean, r: Rules): Group => (closed || worth < r.maybe ? 'done' : worth >= r.now ? 'now' : 'maybe')
|
package/src/wiki/scan-md.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'fs'
|
|
|
16
16
|
import { basename, dirname, join, relative, resolve } from 'path'
|
|
17
17
|
import type { MdEdge, MdGraph, MdNode } from 'rvlib-shipkit/src/wiki/md-graph.ts'
|
|
18
18
|
import { vendoredAround } from 'rvlib-shipkit/src/core/vendored-read.ts'
|
|
19
|
+
import { treeRevAt } from 'rvlib-shipkit/src/core/tree-rev.ts'
|
|
19
20
|
|
|
20
21
|
export type ScanMdConfig = {
|
|
21
22
|
root: string // absolute dir to scan
|
|
@@ -35,7 +36,24 @@ export function scanMdGraph(cfg: ScanMdConfig): MdGraph {
|
|
|
35
36
|
return scanMd(cfg).graph
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
/** how long a kept scan stands for what no save watch sees: an ignored page, a target outside the repo */
|
|
40
|
+
const SCAN_KEEP_MS = 60_000
|
|
41
|
+
const scans = new Map<string, { rev: number; at: number; scan: MdScan }>()
|
|
42
|
+
|
|
43
|
+
/** the scan, kept while the tree it sits in holds still (core/tree-rev.ts): every hub of the daemon draws the house
|
|
44
|
+
* wiki, and a scan reads and parses every page. Outside a process a save watch runs in, it is read every time */
|
|
38
45
|
export function scanMd(cfg: ScanMdConfig): MdScan {
|
|
46
|
+
const rev = treeRevAt(cfg.root)
|
|
47
|
+
if (rev == null) return scanMdNow(cfg)
|
|
48
|
+
const key = JSON.stringify([cfg.root, cfg.index ?? null, cfg.skipDirs ?? [], cfg.boundary ?? null])
|
|
49
|
+
const held = scans.get(key)
|
|
50
|
+
if (held != null && held.rev === rev && Date.now() - held.at < SCAN_KEEP_MS) return held.scan
|
|
51
|
+
const scan = scanMdNow(cfg)
|
|
52
|
+
scans.set(key, { rev, at: Date.now(), scan })
|
|
53
|
+
return scan
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function scanMdNow(cfg: ScanMdConfig): MdScan {
|
|
39
57
|
const skip = new Set(['node_modules', '.git', 'dist', 'tmp', ...(cfg.skipDirs ?? [])])
|
|
40
58
|
const repo = vendoredAround(cfg.root)
|
|
41
59
|
const vendored = new Set((repo?.dirs ?? []).map((d) => join(repo!.root, d)))
|
package/src/collections/posts.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// social-posts collection — projects `.shipkit/social/<channel>/` post files
|
|
2
|
-
// (contract v2) into the needs feed. Status-aware: rejected/posted history
|
|
3
|
-
// stays on disk as training data and never floods the feed. Drafts-as-rolls:
|
|
4
|
-
// variants are sibling files `<slug>.a.md`, `<slug>.b.md`; picking one flips
|
|
5
|
-
// it to picked and the others to rejected (files KEPT). Severities:
|
|
6
|
-
// any file missing `status:` → red (metadata with no inventable default)
|
|
7
|
-
// drafts awaiting a pick → yellow (a pick is a taste act)
|
|
8
|
-
// picked but not posted → red (paste-from-elsewhere: post + URL proof)
|
|
9
|
-
import { existsSync, readdirSync, readFileSync, statSync } from 'fs'
|
|
10
|
-
import { join } from 'path'
|
|
11
|
-
import type { Collection, Instance } from './collection-types.ts'
|
|
12
|
-
|
|
13
|
-
export type PostFile = {
|
|
14
|
-
channel: string
|
|
15
|
-
file: string
|
|
16
|
-
slug: string
|
|
17
|
-
variant: string | null
|
|
18
|
-
status: 'draft' | 'picked' | 'posted' | 'rejected' | null
|
|
19
|
-
kind: string | null
|
|
20
|
-
posted: string | null
|
|
21
|
-
body: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const fm = (md: string, key: string): string | null => md.match(new RegExp(`^${key}:\\s*(.+)$`, 'm'))?.[1]?.trim() ?? null
|
|
25
|
-
|
|
26
|
-
/** the paste-ready text: the `## Post` section body (Angle/Feedback never leak into the paste) */
|
|
27
|
-
export const postSection = (md: string): string => md.match(/^## Post\s*\n([\s\S]*?)(?=^## |\s*$(?![\s\S]))/m)?.[1]?.trim() ?? ''
|
|
28
|
-
|
|
29
|
-
export function parsePostFile(dir: string, channel: string, file: string): PostFile {
|
|
30
|
-
const md = readFileSync(join(dir, file), 'utf8')
|
|
31
|
-
const m = file.match(/^(.*?)(?:\.([a-z]))?\.md$/)
|
|
32
|
-
const status = fm(md, 'status')
|
|
33
|
-
return {
|
|
34
|
-
channel,
|
|
35
|
-
file,
|
|
36
|
-
slug: m?.[1] ?? file,
|
|
37
|
-
variant: m?.[2] ?? null,
|
|
38
|
-
status: status === 'draft' || status === 'picked' || status === 'posted' || status === 'rejected' ? status : null,
|
|
39
|
-
kind: fm(md, 'kind'),
|
|
40
|
-
posted: fm(md, 'posted'),
|
|
41
|
-
body: md,
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function listPosts(root: string): PostFile[] {
|
|
46
|
-
const social = join(root, '.shipkit/social')
|
|
47
|
-
if (!existsSync(social)) return []
|
|
48
|
-
const out: PostFile[] = []
|
|
49
|
-
for (const ch of readdirSync(social)) {
|
|
50
|
-
const d = join(social, ch)
|
|
51
|
-
if (!statSync(d).isDirectory()) continue
|
|
52
|
-
for (const f of readdirSync(d).filter((x) => x.endsWith('.md')).sort()) out.push(parsePostFile(d, ch, f))
|
|
53
|
-
}
|
|
54
|
-
return out
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function socialPostsCollection(root: string): Collection {
|
|
58
|
-
return {
|
|
59
|
-
id: 'posts',
|
|
60
|
-
title: 'posts',
|
|
61
|
-
kind: 'post',
|
|
62
|
-
media: 'text',
|
|
63
|
-
list: async () => {
|
|
64
|
-
const bySlug = new Map<string, PostFile[]>()
|
|
65
|
-
for (const p of listPosts(root)) {
|
|
66
|
-
const key = `${p.channel}/${p.slug}`
|
|
67
|
-
bySlug.set(key, [...(bySlug.get(key) ?? []), p])
|
|
68
|
-
}
|
|
69
|
-
const out: Instance[] = []
|
|
70
|
-
const feedback = (v: PostFile): string[] | undefined => {
|
|
71
|
-
const lines = v.body.split('\n').filter((l) => /^- \d{4}-\d{2}-\d{2}: /.test(l))
|
|
72
|
-
return lines.length > 0 ? lines.slice(-3) : undefined
|
|
73
|
-
}
|
|
74
|
-
for (const [key, variants] of bySlug) {
|
|
75
|
-
const fileOf = (v: PostFile): string => `.shipkit/social/${v.channel}/${v.file}`
|
|
76
|
-
// the row is the post, the venue is the slot beside it
|
|
77
|
-
const place = { label: key.split('/').slice(1).join('/'), slot: variants[0]!.channel }
|
|
78
|
-
const missing = variants.filter((v) => v.status == null)
|
|
79
|
-
if (missing.length > 0) {
|
|
80
|
-
out.push({
|
|
81
|
-
id: `post:${key}:invalid`,
|
|
82
|
-
...place,
|
|
83
|
-
text: `${key} — missing/invalid status: frontmatter (${missing.map((v) => v.file).join(', ')})`,
|
|
84
|
-
type: 'post',
|
|
85
|
-
path: fileOf(missing[0]!),
|
|
86
|
-
severity: 'red',
|
|
87
|
-
file: fileOf(missing[0]!),
|
|
88
|
-
})
|
|
89
|
-
continue
|
|
90
|
-
}
|
|
91
|
-
const picked = variants.find((v) => v.status === 'picked')
|
|
92
|
-
if (picked != null) {
|
|
93
|
-
out.push({
|
|
94
|
-
id: `post:${key}:topost`,
|
|
95
|
-
...place,
|
|
96
|
-
text: `${key} — picked, waiting to be POSTED (copy → post → paste the URL)`,
|
|
97
|
-
type: 'post',
|
|
98
|
-
path: fileOf(picked),
|
|
99
|
-
severity: 'red',
|
|
100
|
-
artifact: { copy: postSection(picked.body) },
|
|
101
|
-
verbs: ['paste-proof', 'rate'],
|
|
102
|
-
candidates: [{ id: picked.file, label: picked.variant ?? 'post' }],
|
|
103
|
-
file: fileOf(picked),
|
|
104
|
-
remarks: feedback(picked),
|
|
105
|
-
})
|
|
106
|
-
continue
|
|
107
|
-
}
|
|
108
|
-
const drafts = variants.filter((v) => v.status === 'draft')
|
|
109
|
-
if (drafts.length > 0) {
|
|
110
|
-
out.push({
|
|
111
|
-
id: `post:${key}:pick`,
|
|
112
|
-
...place,
|
|
113
|
-
text: `${key} — ${drafts.length} draft(s), pick one`,
|
|
114
|
-
type: 'post',
|
|
115
|
-
path: fileOf(drafts[0]!),
|
|
116
|
-
severity: 'yellow',
|
|
117
|
-
verbs: ['pick', 'rate'],
|
|
118
|
-
candidates: drafts.map((v) => ({ id: v.file, label: v.variant ?? 'draft', hint: postSection(v.body).slice(0, 200) })),
|
|
119
|
-
file: fileOf(drafts[0]!),
|
|
120
|
-
remarks: feedback(drafts[0]!),
|
|
121
|
-
})
|
|
122
|
-
continue
|
|
123
|
-
}
|
|
124
|
-
// posted / rejected history: VISIBLE (browse-all), never in needs
|
|
125
|
-
const posted = variants.find((v) => v.status === 'posted')
|
|
126
|
-
const shown = posted ?? variants[0]!
|
|
127
|
-
out.push({
|
|
128
|
-
id: `post:${key}:${posted != null ? 'posted' : 'rejected'}`,
|
|
129
|
-
...place,
|
|
130
|
-
text: `${key} — ${posted != null ? `posted${posted.posted != null ? ` (${posted.posted})` : ''}` : 'rejected'}`,
|
|
131
|
-
type: 'post',
|
|
132
|
-
path: fileOf(shown),
|
|
133
|
-
// posted and rejected are history: visible, never loud
|
|
134
|
-
state: 'quiet',
|
|
135
|
-
file: fileOf(shown),
|
|
136
|
-
remarks: feedback(shown),
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
return out
|
|
140
|
-
},
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// normative WHAT for .shipkit/social/ (posts ONLY — the Discord server contract is
|
|
2
|
-
// discord.contract.ts). Declared = the repo config lists social channels.
|
|
3
|
-
// Undeclared, it ships only once a post is out (`status: posted`): a folder
|
|
4
|
-
// of local drafts is work in progress, never a ship.
|
|
5
|
-
import { custom, defineContract, fileMatches } from 'rvlib-shipkit/src/contracts/contract-types.ts'
|
|
6
|
-
|
|
7
|
-
export default defineContract({
|
|
8
|
-
venue: 'social',
|
|
9
|
-
dir: '.shipkit/social',
|
|
10
|
-
owner: 'distribute/post-publicly.md',
|
|
11
|
-
appliesTo: 'declared',
|
|
12
|
-
detect: [fileMatches('.shipkit/social/**/*.md', '^status:\\s*posted\\b')],
|
|
13
|
-
artifacts: [
|
|
14
|
-
custom('declared-channel-dirs', (env) =>
|
|
15
|
-
env.social
|
|
16
|
-
.filter((ch) => !env.exists(`.shipkit/social/${ch}`))
|
|
17
|
-
.map((ch) => `.shipkit/social/${ch}/ missing — declared social channel '${ch}' has no post folder`),
|
|
18
|
-
),
|
|
19
|
-
],
|
|
20
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Coding standards — {{NAME}}
|
|
2
|
-
|
|
3
|
-
The always-loaded page. Keep it to hard gates plus a screen of standards.
|
|
4
|
-
Once it grows past that, split the gates into `process.md`, make that the
|
|
5
|
-
always-loaded one, and route the rest by surface.
|
|
6
|
-
|
|
7
|
-
## Gates
|
|
8
|
-
|
|
9
|
-
- **Spec-first**: the `agent/` page changes BEFORE the code it describes.
|
|
10
|
-
- **`sk ci` is the verification.** Run it, not the linter, the
|
|
11
|
-
typechecker and the tests one at a time.
|
|
12
|
-
- **Repro before fix**: write the failing test, then fix, then re-run it.
|
|
13
|
-
- One code path per concern. Delete the redundant mechanism rather than
|
|
14
|
-
keeping two.
|
|
15
|
-
|
|
16
|
-
## TypeScript
|
|
17
|
-
|
|
18
|
-
- `strict`, `noUncheckedIndexedAccess`, `noUnusedLocals`,
|
|
19
|
-
`noUnusedParameters`, `noFallthroughCasesInSwitch`: all on, always.
|
|
20
|
-
- No `as any`, no `@ts-ignore`. A cast that survives review is listed here
|
|
21
|
-
with the reason it is safe.
|
|
22
|
-
- Imports are absolute (`src/...`), never `../..` chains.
|
|
23
|
-
|
|
24
|
-
## Comments
|
|
25
|
-
|
|
26
|
-
- The default is NO comment. Write one only for what the code cannot say:
|
|
27
|
-
a constraint, an invariant, a performance reason, a workaround.
|
|
28
|
-
- Never narrate the edit, the date, or who asked for it. That is what git
|
|
29
|
-
and the changelog are for.
|
|
30
|
-
- Lowercase, no dash punctuation, matching the density of the file.
|
|
31
|
-
|
|
32
|
-
## Layout
|
|
33
|
-
|
|
34
|
-
- A file past ~600 lines is a smell; carve it at ~800.
|
|
35
|
-
- Anti-patterns: <fill as the project teaches them>.
|