pilothub 0.0.1

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 (272) hide show
  1. package/.env.local.example +19 -0
  2. package/.github/workflows/ci.yml +40 -0
  3. package/.oxlintrc.json +3 -0
  4. package/AGENTS.md +45 -0
  5. package/CHANGELOG.md +138 -0
  6. package/DEPRECATIONS.md +7 -0
  7. package/LICENSE +21 -0
  8. package/README.md +150 -0
  9. package/biome.json +41 -0
  10. package/convex/_generated/api.d.ts +153 -0
  11. package/convex/_generated/api.js +23 -0
  12. package/convex/_generated/dataModel.d.ts +60 -0
  13. package/convex/_generated/server.d.ts +143 -0
  14. package/convex/_generated/server.js +93 -0
  15. package/convex/auth.config.ts +8 -0
  16. package/convex/auth.ts +19 -0
  17. package/convex/comments.ts +88 -0
  18. package/convex/crons.ts +34 -0
  19. package/convex/devSeed.ts +459 -0
  20. package/convex/devSeedExtra.ts +541 -0
  21. package/convex/downloads.ts +78 -0
  22. package/convex/githubBackups.ts +170 -0
  23. package/convex/githubBackupsNode.ts +183 -0
  24. package/convex/githubImport.ts +317 -0
  25. package/convex/githubSoulBackups.ts +170 -0
  26. package/convex/githubSoulBackupsNode.ts +186 -0
  27. package/convex/http.ts +194 -0
  28. package/convex/httpApi.handlers.test.ts +488 -0
  29. package/convex/httpApi.test.ts +70 -0
  30. package/convex/httpApi.ts +305 -0
  31. package/convex/httpApiV1.handlers.test.ts +584 -0
  32. package/convex/httpApiV1.ts +1172 -0
  33. package/convex/leaderboards.ts +39 -0
  34. package/convex/lib/access.ts +36 -0
  35. package/convex/lib/apiTokenAuth.ts +36 -0
  36. package/convex/lib/badges.ts +50 -0
  37. package/convex/lib/changelog.test.ts +34 -0
  38. package/convex/lib/changelog.ts +278 -0
  39. package/convex/lib/embeddings.ts +38 -0
  40. package/convex/lib/githubBackup.ts +443 -0
  41. package/convex/lib/githubImport.test.ts +247 -0
  42. package/convex/lib/githubImport.ts +425 -0
  43. package/convex/lib/githubSoulBackup.ts +443 -0
  44. package/convex/lib/leaderboards.ts +103 -0
  45. package/convex/lib/moderation.ts +42 -0
  46. package/convex/lib/public.ts +89 -0
  47. package/convex/lib/searchText.test.ts +46 -0
  48. package/convex/lib/searchText.ts +27 -0
  49. package/convex/lib/skillBackfill.test.ts +34 -0
  50. package/convex/lib/skillBackfill.ts +67 -0
  51. package/convex/lib/skillPublish.test.ts +28 -0
  52. package/convex/lib/skillPublish.ts +284 -0
  53. package/convex/lib/skillStats.ts +80 -0
  54. package/convex/lib/skills.test.ts +197 -0
  55. package/convex/lib/skills.ts +273 -0
  56. package/convex/lib/soulChangelog.ts +273 -0
  57. package/convex/lib/soulPublish.ts +236 -0
  58. package/convex/lib/tokens.test.ts +33 -0
  59. package/convex/lib/tokens.ts +51 -0
  60. package/convex/lib/webhooks.test.ts +91 -0
  61. package/convex/lib/webhooks.ts +112 -0
  62. package/convex/maintenance.test.ts +270 -0
  63. package/convex/maintenance.ts +840 -0
  64. package/convex/rateLimits.ts +50 -0
  65. package/convex/schema.ts +472 -0
  66. package/convex/search.test.ts +12 -0
  67. package/convex/search.ts +254 -0
  68. package/convex/seed.test.ts +37 -0
  69. package/convex/seed.ts +254 -0
  70. package/convex/seedSouls.ts +111 -0
  71. package/convex/skillStatEvents.ts +568 -0
  72. package/convex/skills.ts +1606 -0
  73. package/convex/soulComments.ts +88 -0
  74. package/convex/soulDownloads.ts +14 -0
  75. package/convex/soulStars.ts +71 -0
  76. package/convex/souls.ts +570 -0
  77. package/convex/stars.ts +108 -0
  78. package/convex/statsMaintenance.ts +205 -0
  79. package/convex/telemetry.ts +434 -0
  80. package/convex/tokens.ts +88 -0
  81. package/convex/tsconfig.json +7 -0
  82. package/convex/uploads.ts +20 -0
  83. package/convex/users.ts +122 -0
  84. package/convex/webhooks.ts +50 -0
  85. package/convex.json +3 -0
  86. package/docs/README.md +32 -0
  87. package/docs/api.md +51 -0
  88. package/docs/architecture.md +61 -0
  89. package/docs/auth.md +54 -0
  90. package/docs/cli.md +117 -0
  91. package/docs/deploy.md +78 -0
  92. package/docs/diffing.md +84 -0
  93. package/docs/github-import.md +171 -0
  94. package/docs/http-api.md +187 -0
  95. package/docs/manual-testing.md +64 -0
  96. package/docs/mintlify.md +43 -0
  97. package/docs/quickstart.md +120 -0
  98. package/docs/skill-format.md +58 -0
  99. package/docs/soul-format.md +37 -0
  100. package/docs/spec.md +177 -0
  101. package/docs/telemetry.md +91 -0
  102. package/docs/troubleshooting.md +49 -0
  103. package/docs/webhook.md +51 -0
  104. package/e2e/menu-smoke.pw.test.ts +49 -0
  105. package/e2e/pilothub.e2e.test.ts +494 -0
  106. package/e2e/search-exact.pw.test.ts +97 -0
  107. package/package.json +84 -0
  108. package/packages/pilothub/LICENSE +22 -0
  109. package/packages/pilothub/README.md +57 -0
  110. package/packages/pilothub/bin/pilothub.js +2 -0
  111. package/packages/pilothub/package.json +41 -0
  112. package/packages/pilothub/src/browserAuth.test.ts +96 -0
  113. package/packages/pilothub/src/browserAuth.ts +174 -0
  114. package/packages/pilothub/src/cli/buildInfo.ts +94 -0
  115. package/packages/pilothub/src/cli/commands/auth.ts +97 -0
  116. package/packages/pilothub/src/cli/commands/delete.test.ts +73 -0
  117. package/packages/pilothub/src/cli/commands/delete.ts +83 -0
  118. package/packages/pilothub/src/cli/commands/publish.test.ts +122 -0
  119. package/packages/pilothub/src/cli/commands/publish.ts +108 -0
  120. package/packages/pilothub/src/cli/commands/skills.test.ts +191 -0
  121. package/packages/pilothub/src/cli/commands/skills.ts +380 -0
  122. package/packages/pilothub/src/cli/commands/star.ts +46 -0
  123. package/packages/pilothub/src/cli/commands/sync.test.ts +310 -0
  124. package/packages/pilothub/src/cli/commands/sync.ts +200 -0
  125. package/packages/pilothub/src/cli/commands/syncHelpers.test.ts +26 -0
  126. package/packages/pilothub/src/cli/commands/syncHelpers.ts +427 -0
  127. package/packages/pilothub/src/cli/commands/syncTypes.ts +27 -0
  128. package/packages/pilothub/src/cli/commands/unstar.ts +48 -0
  129. package/packages/pilothub/src/cli/helpStyle.ts +45 -0
  130. package/packages/pilothub/src/cli/pilotbotConfig.test.ts +159 -0
  131. package/packages/pilothub/src/cli/pilotbotConfig.ts +147 -0
  132. package/packages/pilothub/src/cli/registry.test.ts +63 -0
  133. package/packages/pilothub/src/cli/registry.ts +43 -0
  134. package/packages/pilothub/src/cli/scanSkills.test.ts +64 -0
  135. package/packages/pilothub/src/cli/scanSkills.ts +84 -0
  136. package/packages/pilothub/src/cli/slug.ts +16 -0
  137. package/packages/pilothub/src/cli/types.ts +12 -0
  138. package/packages/pilothub/src/cli/ui.ts +75 -0
  139. package/packages/pilothub/src/cli.ts +311 -0
  140. package/packages/pilothub/src/config.ts +36 -0
  141. package/packages/pilothub/src/discovery.test.ts +75 -0
  142. package/packages/pilothub/src/discovery.ts +19 -0
  143. package/packages/pilothub/src/http.test.ts +156 -0
  144. package/packages/pilothub/src/http.ts +301 -0
  145. package/packages/pilothub/src/schema/ark.ts +29 -0
  146. package/packages/pilothub/src/schema/index.ts +5 -0
  147. package/packages/pilothub/src/schema/routes.ts +22 -0
  148. package/packages/pilothub/src/schema/schemas.ts +260 -0
  149. package/packages/pilothub/src/schema/textFiles.test.ts +23 -0
  150. package/packages/pilothub/src/schema/textFiles.ts +66 -0
  151. package/packages/pilothub/src/skills.test.ts +191 -0
  152. package/packages/pilothub/src/skills.ts +172 -0
  153. package/packages/pilothub/src/types.ts +10 -0
  154. package/packages/pilothub/tsconfig.json +14 -0
  155. package/packages/schema/README.md +3 -0
  156. package/packages/schema/dist/ark.d.ts +4 -0
  157. package/packages/schema/dist/ark.js +26 -0
  158. package/packages/schema/dist/ark.js.map +1 -0
  159. package/packages/schema/dist/index.d.ts +5 -0
  160. package/packages/schema/dist/index.js +5 -0
  161. package/packages/schema/dist/index.js.map +1 -0
  162. package/packages/schema/dist/routes.d.ts +21 -0
  163. package/packages/schema/dist/routes.js +22 -0
  164. package/packages/schema/dist/routes.js.map +1 -0
  165. package/packages/schema/dist/schemas.d.ts +297 -0
  166. package/packages/schema/dist/schemas.js +243 -0
  167. package/packages/schema/dist/schemas.js.map +1 -0
  168. package/packages/schema/dist/textFiles.d.ts +5 -0
  169. package/packages/schema/dist/textFiles.js +66 -0
  170. package/packages/schema/dist/textFiles.js.map +1 -0
  171. package/packages/schema/package.json +26 -0
  172. package/packages/schema/src/ark.ts +29 -0
  173. package/packages/schema/src/index.ts +5 -0
  174. package/packages/schema/src/routes.ts +22 -0
  175. package/packages/schema/src/schemas.test.ts +123 -0
  176. package/packages/schema/src/schemas.ts +287 -0
  177. package/packages/schema/src/textFiles.test.ts +23 -0
  178. package/packages/schema/src/textFiles.ts +66 -0
  179. package/packages/schema/tsconfig.json +15 -0
  180. package/pilothub +46 -0
  181. package/playwright.config.ts +33 -0
  182. package/public/.well-known/pilothub.json +6 -0
  183. package/public/api/v1/openapi.json +379 -0
  184. package/public/favicon.ico +0 -0
  185. package/public/logo192.png +0 -0
  186. package/public/logo512.png +0 -0
  187. package/public/manifest.json +25 -0
  188. package/public/og.png +0 -0
  189. package/public/og.svg +98 -0
  190. package/public/pilot-logo.png +0 -0
  191. package/public/pilot-mark.png +0 -0
  192. package/public/robots.txt +3 -0
  193. package/public/tanstack-circle-logo.png +0 -0
  194. package/public/tanstack-word-logo-white.svg +1 -0
  195. package/scripts/check-peer-deps.ts +56 -0
  196. package/scripts/docs-list.ts +148 -0
  197. package/scripts/run-playwright-local.sh +14 -0
  198. package/server/og/fetchSkillOgMeta.ts +27 -0
  199. package/server/og/fetchSoulOgMeta.ts +27 -0
  200. package/server/og/ogAssets.ts +80 -0
  201. package/server/og/skillOgSvg.test.ts +59 -0
  202. package/server/og/skillOgSvg.ts +258 -0
  203. package/server/og/soulOgSvg.ts +209 -0
  204. package/server/routes/og/skill.png.ts +103 -0
  205. package/server/routes/og/soul.png.ts +111 -0
  206. package/src/__tests__/skill-detail-page.test.tsx +86 -0
  207. package/src/__tests__/skills-index.test.tsx +145 -0
  208. package/src/__tests__/upload.route.test.tsx +228 -0
  209. package/src/components/AppProviders.tsx +19 -0
  210. package/src/components/ClientOnly.tsx +18 -0
  211. package/src/components/Footer.tsx +29 -0
  212. package/src/components/Header.tsx +295 -0
  213. package/src/components/InstallSwitcher.tsx +53 -0
  214. package/src/components/SkillCard.tsx +36 -0
  215. package/src/components/SkillDetailPage.tsx +817 -0
  216. package/src/components/SkillDiffCard.tsx +485 -0
  217. package/src/components/SoulCard.tsx +19 -0
  218. package/src/components/SoulDetailPage.tsx +263 -0
  219. package/src/components/UserBootstrap.tsx +18 -0
  220. package/src/components/ui/dropdown-menu.tsx +67 -0
  221. package/src/components/ui/toggle-group.tsx +35 -0
  222. package/src/convex/client.ts +3 -0
  223. package/src/lib/badges.ts +29 -0
  224. package/src/lib/diffing.test.ts +163 -0
  225. package/src/lib/diffing.ts +106 -0
  226. package/src/lib/gravatar.test.ts +9 -0
  227. package/src/lib/gravatar.ts +158 -0
  228. package/src/lib/og.test.ts +142 -0
  229. package/src/lib/og.ts +156 -0
  230. package/src/lib/publicUser.ts +39 -0
  231. package/src/lib/roles.ts +19 -0
  232. package/src/lib/site.test.ts +130 -0
  233. package/src/lib/site.ts +84 -0
  234. package/src/lib/theme-transition.test.ts +134 -0
  235. package/src/lib/theme-transition.ts +134 -0
  236. package/src/lib/theme.test.tsx +88 -0
  237. package/src/lib/theme.ts +43 -0
  238. package/src/lib/uploadFiles.jsdom.test.ts +33 -0
  239. package/src/lib/uploadFiles.test.ts +123 -0
  240. package/src/lib/uploadFiles.ts +245 -0
  241. package/src/lib/uploadUtils.test.ts +78 -0
  242. package/src/lib/uploadUtils.ts +93 -0
  243. package/src/lib/useAuthStatus.ts +12 -0
  244. package/src/lib/utils.test.ts +9 -0
  245. package/src/lib/utils.ts +6 -0
  246. package/src/logo.svg +12 -0
  247. package/src/routeTree.gen.ts +345 -0
  248. package/src/router.tsx +17 -0
  249. package/src/routes/$owner/$slug.tsx +55 -0
  250. package/src/routes/__root.tsx +136 -0
  251. package/src/routes/admin.tsx +11 -0
  252. package/src/routes/cli/auth.tsx +168 -0
  253. package/src/routes/dashboard.tsx +97 -0
  254. package/src/routes/import.tsx +415 -0
  255. package/src/routes/index.tsx +252 -0
  256. package/src/routes/management.tsx +529 -0
  257. package/src/routes/settings.tsx +203 -0
  258. package/src/routes/skills/index.tsx +422 -0
  259. package/src/routes/souls/$slug.tsx +55 -0
  260. package/src/routes/souls/index.tsx +243 -0
  261. package/src/routes/stars.tsx +68 -0
  262. package/src/routes/u/$handle.tsx +307 -0
  263. package/src/routes/upload/utils.ts +81 -0
  264. package/src/routes/upload.tsx +499 -0
  265. package/src/styles.css +2718 -0
  266. package/tsconfig.json +24 -0
  267. package/tsconfig.oxlint.json +16 -0
  268. package/vercel.json +8 -0
  269. package/vite.config.ts +48 -0
  270. package/vitest.config.ts +47 -0
  271. package/vitest.e2e.config.ts +11 -0
  272. package/vitest.setup.ts +1 -0
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
4
+ import { dirname, join, relative } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+
7
+ const DOCS_DIR = resolveDocsDir()
8
+
9
+ const EXCLUDED_DIRS = new Set(['archive', 'research'])
10
+
11
+ function resolveDocsDir() {
12
+ const env = process.env.DOCS_DIR?.trim()
13
+ if (env) return env
14
+
15
+ const fromCwd = join(process.cwd(), 'docs')
16
+ if (existsSync(fromCwd)) return fromCwd
17
+
18
+ const docsListFile = fileURLToPath(import.meta.url)
19
+ const docsListDir = dirname(docsListFile)
20
+ return join(docsListDir, '..', 'docs')
21
+ }
22
+
23
+ function compactStrings(values: unknown[]): string[] {
24
+ const result: string[] = []
25
+ for (const value of values) {
26
+ if (value === null || value === undefined) continue
27
+ const normalized = String(value).trim()
28
+ if (normalized.length > 0) result.push(normalized)
29
+ }
30
+ return result
31
+ }
32
+
33
+ function walkMarkdownFiles(dir: string, base: string = dir): string[] {
34
+ const entries = readdirSync(dir, { withFileTypes: true })
35
+ const files: string[] = []
36
+ for (const entry of entries) {
37
+ if (entry.name.startsWith('.')) continue
38
+ const fullPath = join(dir, entry.name)
39
+ if (entry.isDirectory()) {
40
+ if (EXCLUDED_DIRS.has(entry.name)) continue
41
+ files.push(...walkMarkdownFiles(fullPath, base))
42
+ continue
43
+ }
44
+ if (entry.isFile() && entry.name.endsWith('.md')) {
45
+ files.push(relative(base, fullPath))
46
+ }
47
+ }
48
+ return files.sort((a, b) => a.localeCompare(b))
49
+ }
50
+
51
+ function extractMetadata(fullPath: string): {
52
+ summary: string | null
53
+ readWhen: string[]
54
+ error?: string
55
+ } {
56
+ const content = readFileSync(fullPath, 'utf8')
57
+
58
+ if (!content.startsWith('---')) {
59
+ return { summary: null, readWhen: [], error: 'missing front matter' }
60
+ }
61
+
62
+ const endIndex = content.indexOf('\n---', 3)
63
+ if (endIndex === -1) {
64
+ return { summary: null, readWhen: [], error: 'unterminated front matter' }
65
+ }
66
+
67
+ const frontMatter = content.slice(3, endIndex).trim()
68
+ const lines = frontMatter.split('\n')
69
+
70
+ let summaryLine: string | null = null
71
+ const readWhen: string[] = []
72
+ let collectingField: 'read_when' | null = null
73
+
74
+ for (const rawLine of lines) {
75
+ const line = rawLine.trim()
76
+
77
+ if (line.startsWith('summary:')) {
78
+ summaryLine = line
79
+ collectingField = null
80
+ continue
81
+ }
82
+
83
+ if (line.startsWith('read_when:')) {
84
+ collectingField = 'read_when'
85
+ const inline = line.slice('read_when:'.length).trim()
86
+ if (inline.startsWith('[') && inline.endsWith(']')) {
87
+ try {
88
+ const parsed = JSON.parse(inline.replace(/'/g, '"')) as unknown
89
+ if (Array.isArray(parsed)) {
90
+ readWhen.push(...compactStrings(parsed))
91
+ }
92
+ } catch {
93
+ // ignore malformed inline arrays
94
+ }
95
+ }
96
+ continue
97
+ }
98
+
99
+ if (collectingField === 'read_when') {
100
+ if (line.startsWith('- ')) {
101
+ const hint = line.slice(2).trim()
102
+ if (hint) readWhen.push(hint)
103
+ } else if (line === '') {
104
+ // ignore
105
+ } else {
106
+ collectingField = null
107
+ }
108
+ }
109
+ }
110
+
111
+ if (!summaryLine) {
112
+ return { summary: null, readWhen, error: 'summary key missing' }
113
+ }
114
+
115
+ const summaryValue = summaryLine.slice('summary:'.length).trim()
116
+ const normalized = summaryValue
117
+ .replace(/^['"]|['"]$/g, '')
118
+ .replace(/\s+/g, ' ')
119
+ .trim()
120
+
121
+ if (!normalized) {
122
+ return { summary: null, readWhen, error: 'summary is empty' }
123
+ }
124
+
125
+ return { summary: normalized, readWhen }
126
+ }
127
+
128
+ console.log('Listing all markdown files in docs folder:')
129
+
130
+ const markdownFiles = walkMarkdownFiles(DOCS_DIR)
131
+
132
+ for (const relativePath of markdownFiles) {
133
+ const fullPath = join(DOCS_DIR, relativePath)
134
+ const { summary, readWhen, error } = extractMetadata(fullPath)
135
+ if (summary) {
136
+ console.log(`${relativePath} - ${summary}`)
137
+ if (readWhen.length > 0) {
138
+ console.log(` Read when: ${readWhen.join('; ')}`)
139
+ }
140
+ } else {
141
+ const reason = error ? ` - [${error}]` : ''
142
+ console.log(`${relativePath}${reason}`)
143
+ }
144
+ }
145
+
146
+ console.log(
147
+ '\nReminder: keep docs up to date as behavior changes. When your task matches any "Read when" hint above, read that doc before coding, and suggest new coverage when it is missing.',
148
+ )
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ PORT="${PLAYWRIGHT_PORT:-4173}"
5
+
6
+ if [[ -n "${PLAYWRIGHT_BASE_URL:-}" ]]; then
7
+ echo "Running against $PLAYWRIGHT_BASE_URL"
8
+ bun run test:pw
9
+ exit 0
10
+ fi
11
+
12
+ echo "Running against local preview server on http://127.0.0.1:$PORT"
13
+ bun run build
14
+ PLAYWRIGHT_PORT="$PORT" bun run test:pw
@@ -0,0 +1,27 @@
1
+ export type SkillOgMeta = {
2
+ displayName: string | null
3
+ summary: string | null
4
+ owner: string | null
5
+ version: string | null
6
+ }
7
+
8
+ export async function fetchSkillOgMeta(slug: string, apiBase: string): Promise<SkillOgMeta | null> {
9
+ try {
10
+ const url = new URL(`/api/v1/skills/${encodeURIComponent(slug)}`, apiBase)
11
+ const response = await fetch(url.toString(), { headers: { Accept: 'application/json' } })
12
+ if (!response.ok) return null
13
+ const payload = (await response.json()) as {
14
+ skill?: { displayName?: string; summary?: string | null } | null
15
+ owner?: { handle?: string | null } | null
16
+ latestVersion?: { version?: string | null } | null
17
+ }
18
+ return {
19
+ displayName: payload.skill?.displayName ?? null,
20
+ summary: payload.skill?.summary ?? null,
21
+ owner: payload.owner?.handle ?? null,
22
+ version: payload.latestVersion?.version ?? null,
23
+ }
24
+ } catch {
25
+ return null
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ export type SoulOgMeta = {
2
+ displayName: string | null
3
+ summary: string | null
4
+ owner: string | null
5
+ version: string | null
6
+ }
7
+
8
+ export async function fetchSoulOgMeta(slug: string, apiBase: string): Promise<SoulOgMeta | null> {
9
+ try {
10
+ const url = new URL(`/api/v1/souls/${encodeURIComponent(slug)}`, apiBase)
11
+ const response = await fetch(url.toString(), { headers: { Accept: 'application/json' } })
12
+ if (!response.ok) return null
13
+ const payload = (await response.json()) as {
14
+ soul?: { displayName?: string; summary?: string | null } | null
15
+ owner?: { handle?: string | null } | null
16
+ latestVersion?: { version?: string | null } | null
17
+ }
18
+ return {
19
+ displayName: payload.soul?.displayName ?? null,
20
+ summary: payload.soul?.summary ?? null,
21
+ owner: payload.owner?.handle ?? null,
22
+ version: payload.latestVersion?.version ?? null,
23
+ }
24
+ } catch {
25
+ return null
26
+ }
27
+ }
@@ -0,0 +1,80 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import { pathToFileURL } from 'node:url'
3
+
4
+ export const FONT_SANS = 'Bricolage Grotesque'
5
+ export const FONT_MONO = 'IBM Plex Mono'
6
+
7
+ type GlobalNitroMain = {
8
+ __nitro_main__?: unknown
9
+ }
10
+
11
+ let markDataUrlPromise: Promise<string> | null = null
12
+ let resvgWasmPromise: Promise<Uint8Array> | null = null
13
+ let fontBuffersPromise: Promise<Uint8Array[]> | null = null
14
+
15
+ function getServerRootUrl() {
16
+ const nitroMain = (globalThis as unknown as GlobalNitroMain).__nitro_main__
17
+ if (typeof nitroMain === 'string') {
18
+ try {
19
+ return new URL('./', nitroMain)
20
+ } catch {
21
+ // fall through
22
+ }
23
+ }
24
+ return pathToFileURL(`${process.cwd()}/`)
25
+ }
26
+
27
+ function getServerUrl(pathname: string) {
28
+ return new URL(pathname.replace(/^\//, ''), getServerRootUrl())
29
+ }
30
+
31
+ export async function getMarkDataUrl() {
32
+ if (!markDataUrlPromise) {
33
+ markDataUrlPromise = (async () => {
34
+ const candidates = [getServerUrl('pilot-mark.png'), getServerUrl('public/pilot-mark.png')]
35
+ let lastError: unknown = null
36
+ for (const url of candidates) {
37
+ try {
38
+ const buffer = await readFile(url)
39
+ return `data:image/png;base64,${buffer.toString('base64')}`
40
+ } catch (error) {
41
+ lastError = error
42
+ }
43
+ }
44
+ throw lastError
45
+ })()
46
+ }
47
+ return markDataUrlPromise
48
+ }
49
+
50
+ export async function getResvgWasm() {
51
+ if (!resvgWasmPromise) {
52
+ resvgWasmPromise = readFile(getServerUrl('node_modules/@resvg/resvg-wasm/index_bg.wasm')).then(
53
+ (buffer) => new Uint8Array(buffer),
54
+ )
55
+ }
56
+ return resvgWasmPromise
57
+ }
58
+
59
+ export async function getFontBuffers() {
60
+ if (!fontBuffersPromise) {
61
+ fontBuffersPromise = Promise.all([
62
+ readFile(
63
+ getServerUrl(
64
+ 'node_modules/@fontsource/bricolage-grotesque/files/bricolage-grotesque-latin-800-normal.woff2',
65
+ ),
66
+ ),
67
+ readFile(
68
+ getServerUrl(
69
+ 'node_modules/@fontsource/bricolage-grotesque/files/bricolage-grotesque-latin-500-normal.woff2',
70
+ ),
71
+ ),
72
+ readFile(
73
+ getServerUrl(
74
+ 'node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-500-normal.woff2',
75
+ ),
76
+ ),
77
+ ]).then((buffers) => buffers.map((buffer) => new Uint8Array(buffer)))
78
+ }
79
+ return fontBuffersPromise
80
+ }
@@ -0,0 +1,59 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { buildSkillOgSvg } from './skillOgSvg'
3
+
4
+ describe('skill OG SVG', () => {
5
+ it('includes title, description, and labels', () => {
6
+ const svg = buildSkillOgSvg({
7
+ markDataUrl: 'data:image/png;base64,AAA=',
8
+ title: 'Discord Doctor',
9
+ description: 'Quick diagnosis and repair for Discord bot.',
10
+ ownerLabel: '@jhillock',
11
+ versionLabel: 'v1.2.3',
12
+ footer: 'pilothub.com/jhillock/discord-doctor',
13
+ })
14
+
15
+ expect(svg).toContain('Discord Doctor')
16
+ expect(svg).toContain('Quick diagnosis and repair')
17
+ expect(svg).toContain('@jhillock')
18
+ expect(svg).toContain('v1.2.3')
19
+ expect(svg).toContain('pilothub.com/jhillock/discord-doctor')
20
+ })
21
+
22
+ it('wraps long titles to avoid clipping', () => {
23
+ const svg = buildSkillOgSvg({
24
+ markDataUrl: 'data:image/png;base64,AAA=',
25
+ title: 'Excalidraw Flowchart',
26
+ description: 'Create Excalidraw flowcharts from descriptions.',
27
+ ownerLabel: '@swiftlysisngh',
28
+ versionLabel: 'v1.0.2',
29
+ footer: 'pilothub.com/swiftlysisngh/excalidraw-flowchart',
30
+ })
31
+
32
+ const titleBlock = svg.match(/<text[^>]*font-weight="800"[\s\S]*?<\/text>/)?.[0] ?? ''
33
+ const titleTspans = titleBlock.match(/<tspan /g) ?? []
34
+ expect(titleTspans.length).toBe(2)
35
+ expect(svg).toContain('Excalidraw')
36
+ expect(svg).toContain('Flowchart')
37
+ })
38
+
39
+ it('clips and wraps long descriptions', () => {
40
+ const longWord = 'a'.repeat(200)
41
+ const svg = buildSkillOgSvg({
42
+ markDataUrl: 'data:image/png;base64,AAA=',
43
+ title: 'Gurkerlcli',
44
+ description: `Prefix ${longWord} suffix`,
45
+ ownerLabel: '@pasogott',
46
+ versionLabel: 'v0.1.0',
47
+ footer: 'pilothub.com/pasogott/gurkerlcli',
48
+ })
49
+
50
+ expect(svg).toContain('<clipPath id="cardClip">')
51
+ expect(svg).toContain('clip-path="url(#cardClip)"')
52
+ expect(svg).not.toContain(longWord)
53
+ expect(svg).toContain('…')
54
+
55
+ const descBlock = svg.match(/<text[^>]*font-size="26"[\s\S]*?<\/text>/)?.[0] ?? ''
56
+ const descTspans = descBlock.match(/<tspan /g) ?? []
57
+ expect(descTspans.length).toBeLessThanOrEqual(3)
58
+ })
59
+ })
@@ -0,0 +1,258 @@
1
+ import { FONT_MONO, FONT_SANS } from './ogAssets'
2
+
3
+ export type SkillOgSvgParams = {
4
+ markDataUrl: string
5
+ title: string
6
+ description: string
7
+ ownerLabel: string
8
+ versionLabel: string
9
+ footer: string
10
+ }
11
+
12
+ function escapeXml(value: string) {
13
+ return value
14
+ .replace(/&/g, '&amp;')
15
+ .replace(/</g, '&lt;')
16
+ .replace(/>/g, '&gt;')
17
+ .replace(/"/g, '&quot;')
18
+ .replace(/'/g, '&#39;')
19
+ }
20
+
21
+ function glyphWidthFactor(char: string) {
22
+ if (char === ' ') return 0.28
23
+ if (char === '…') return 0.62
24
+ if (/[ilI.,:;|!'"`]/.test(char)) return 0.28
25
+ if (/[mwMW@%&]/.test(char)) return 0.9
26
+ if (/[A-Z]/.test(char)) return 0.68
27
+ if (/[0-9]/.test(char)) return 0.6
28
+ return 0.56
29
+ }
30
+
31
+ function estimateTextWidth(value: string, fontSize: number) {
32
+ let width = 0
33
+ for (const char of value) width += glyphWidthFactor(char) * fontSize
34
+ return width
35
+ }
36
+
37
+ function truncateToWidth(value: string, maxWidth: number, fontSize: number) {
38
+ const trimmed = value.trim()
39
+ if (!trimmed) return ''
40
+ if (estimateTextWidth(trimmed, fontSize) <= maxWidth) return trimmed
41
+
42
+ const ellipsis = '…'
43
+ const ellipsisWidth = estimateTextWidth(ellipsis, fontSize)
44
+ let out = ''
45
+ for (const char of trimmed) {
46
+ const next = out + char
47
+ if (estimateTextWidth(next, fontSize) + ellipsisWidth > maxWidth) break
48
+ out = next
49
+ }
50
+ return `${out.replace(/\s+$/g, '').replace(/[.。,;:!?]+$/g, '')}${ellipsis}`
51
+ }
52
+
53
+ function wrapText(value: string, maxWidth: number, fontSize: number, maxLines: number) {
54
+ const words = value.trim().split(/\s+/).filter(Boolean)
55
+ const lines: string[] = []
56
+ let current = ''
57
+
58
+ function pushLine(line: string) {
59
+ if (!line) return
60
+ lines.push(line)
61
+ }
62
+
63
+ function splitLongWord(word: string) {
64
+ if (estimateTextWidth(word, fontSize) <= maxWidth) return [word]
65
+ const parts: string[] = []
66
+ let remaining = word
67
+ while (remaining && estimateTextWidth(remaining, fontSize) > maxWidth) {
68
+ let chunk = ''
69
+ for (const char of remaining) {
70
+ const next = chunk + char
71
+ if (estimateTextWidth(`${next}…`, fontSize) > maxWidth) break
72
+ chunk = next
73
+ }
74
+ if (!chunk) break
75
+ parts.push(`${chunk}…`)
76
+ remaining = remaining.slice(chunk.length)
77
+ }
78
+ if (remaining) parts.push(remaining)
79
+ return parts
80
+ }
81
+
82
+ for (const word of words) {
83
+ if (estimateTextWidth(word, fontSize) > maxWidth) {
84
+ if (current) {
85
+ pushLine(current)
86
+ current = ''
87
+ if (lines.length >= maxLines - 1) break
88
+ }
89
+ const parts = splitLongWord(word)
90
+ for (const part of parts) {
91
+ pushLine(part)
92
+ if (lines.length >= maxLines) break
93
+ }
94
+ current = ''
95
+ if (lines.length >= maxLines - 1) break
96
+ continue
97
+ }
98
+
99
+ const next = current ? `${current} ${word}` : word
100
+ if (estimateTextWidth(next, fontSize) <= maxWidth) {
101
+ current = next
102
+ continue
103
+ }
104
+ pushLine(current)
105
+ current = word
106
+ if (lines.length >= maxLines - 1) break
107
+ }
108
+ if (lines.length < maxLines && current) pushLine(current)
109
+ if (lines.length > maxLines) lines.length = maxLines
110
+
111
+ const usedWords = lines.join(' ').split(/\s+/).filter(Boolean).length
112
+ if (usedWords < words.length) {
113
+ lines[lines.length - 1] = truncateToWidth(lines.at(-1) ?? '', maxWidth, fontSize)
114
+ }
115
+ return lines
116
+ }
117
+
118
+ export function buildSkillOgSvg(params: SkillOgSvgParams) {
119
+ const rawTitle = params.title.trim() || 'PilotHub Skill'
120
+ const rawDescription = params.description.trim() || 'Published on PilotHub.'
121
+
122
+ const cardX = 72
123
+ const cardY = 96
124
+ const cardW = 640
125
+ const cardH = 456
126
+ const cardR = 34
127
+
128
+ const contentX = 114
129
+ const contentRightPadding = 28
130
+ const contentMaxWidth = cardX + cardW - contentX - contentRightPadding
131
+
132
+ const titleMaxLines = 2
133
+ const descMaxLines = 3
134
+
135
+ const titleProbeLines = wrapText(rawTitle, contentMaxWidth, 80, titleMaxLines)
136
+ const titleFontSize = titleProbeLines.length > 1 ? 72 : 80
137
+ const titleLines = wrapText(rawTitle, contentMaxWidth, titleFontSize, titleMaxLines)
138
+
139
+ const descLines = wrapText(rawDescription, contentMaxWidth, 26, descMaxLines)
140
+ const titleY = titleLines.length > 1 ? 258 : 280
141
+ const titleLineHeight = 84
142
+
143
+ const descY = titleLines.length > 1 ? 395 : 380
144
+ const descLineHeight = 34
145
+
146
+ const pillText = `${params.ownerLabel} • ${params.versionLabel}`
147
+ const underlineY = cardY + cardH - 80
148
+ const footerY = cardY + cardH - 18
149
+
150
+ const titleTspans = titleLines
151
+ .map((line, index) => {
152
+ const dy = index === 0 ? 0 : titleLineHeight
153
+ return `<tspan x="114" dy="${dy}">${escapeXml(line)}</tspan>`
154
+ })
155
+ .join('')
156
+
157
+ const descTspans = descLines
158
+ .map((line, index) => {
159
+ const dy = index === 0 ? 0 : descLineHeight
160
+ return `<tspan x="114" dy="${dy}">${escapeXml(line)}</tspan>`
161
+ })
162
+ .join('')
163
+
164
+ return `<?xml version="1.0" encoding="UTF-8"?>
165
+ <svg width="1200" height="630" viewBox="0 0 1200 630" fill="none" xmlns="http://www.w3.org/2000/svg">
166
+ <defs>
167
+ <linearGradient id="bg" x1="0" y1="0" x2="1200" y2="630" gradientUnits="userSpaceOnUse">
168
+ <stop stop-color="#14110F"/>
169
+ <stop offset="0.55" stop-color="#1A1512"/>
170
+ <stop offset="1" stop-color="#14110F"/>
171
+ </linearGradient>
172
+
173
+ <radialGradient id="glowOrange" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(260 60) rotate(120) scale(520 420)">
174
+ <stop stop-color="#E86A47" stop-opacity="0.55"/>
175
+ <stop offset="1" stop-color="#E86A47" stop-opacity="0"/>
176
+ </radialGradient>
177
+
178
+ <radialGradient id="glowSea" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(1050 120) rotate(140) scale(520 420)">
179
+ <stop stop-color="#4AD8B7" stop-opacity="0.35"/>
180
+ <stop offset="1" stop-color="#4AD8B7" stop-opacity="0"/>
181
+ </radialGradient>
182
+
183
+ <filter id="softBlur" x="-40%" y="-40%" width="180%" height="180%">
184
+ <feGaussianBlur stdDeviation="24"/>
185
+ </filter>
186
+
187
+ <filter id="cardShadow" x="-20%" y="-20%" width="140%" height="140%">
188
+ <feDropShadow dx="0" dy="18" stdDeviation="26" flood-color="#000000" flood-opacity="0.6"/>
189
+ </filter>
190
+
191
+ <linearGradient id="pill" x1="0" y1="0" x2="520" y2="0" gradientUnits="userSpaceOnUse">
192
+ <stop stop-color="#E86A47" stop-opacity="0.22"/>
193
+ <stop offset="1" stop-color="#E86A47" stop-opacity="0.08"/>
194
+ </linearGradient>
195
+
196
+ <linearGradient id="stroke" x1="0" y1="0" x2="0" y2="1">
197
+ <stop stop-color="#FFFFFF" stop-opacity="0.16"/>
198
+ <stop offset="1" stop-color="#FFFFFF" stop-opacity="0.06"/>
199
+ </linearGradient>
200
+
201
+ <clipPath id="cardClip">
202
+ <rect x="${cardX}" y="${cardY}" width="${cardW}" height="${cardH}" rx="${cardR}"/>
203
+ </clipPath>
204
+ </defs>
205
+
206
+ <rect width="1200" height="630" fill="url(#bg)"/>
207
+ <circle cx="260" cy="60" r="520" fill="url(#glowOrange)" filter="url(#softBlur)"/>
208
+ <circle cx="1050" cy="120" r="520" fill="url(#glowSea)" filter="url(#softBlur)"/>
209
+
210
+ <g opacity="0.08">
211
+ <path d="M0 84 C160 120 340 40 520 86 C700 132 820 210 1200 160" stroke="#FFFFFF" stroke-opacity="0.10" stroke-width="2"/>
212
+ <path d="M0 188 C220 240 360 160 560 204 C760 248 900 330 1200 300" stroke="#FFFFFF" stroke-opacity="0.08" stroke-width="2"/>
213
+ <path d="M0 440 C240 380 420 520 620 470 C820 420 960 500 1200 460" stroke="#FFFFFF" stroke-opacity="0.06" stroke-width="2"/>
214
+ </g>
215
+
216
+ <g opacity="0.22" filter="url(#softBlur)">
217
+ <image href="${params.markDataUrl}" x="740" y="70" width="560" height="560" preserveAspectRatio="xMidYMid meet"/>
218
+ </g>
219
+
220
+ <g filter="url(#cardShadow)">
221
+ <rect x="${cardX}" y="${cardY}" width="${cardW}" height="${cardH}" rx="${cardR}" fill="#201B18" fill-opacity="0.92" stroke="url(#stroke)"/>
222
+ </g>
223
+
224
+ <g clip-path="url(#cardClip)">
225
+ <image href="${params.markDataUrl}" x="108" y="134" width="46" height="46" preserveAspectRatio="xMidYMid meet"/>
226
+
227
+ <g>
228
+ <rect x="166" y="136" width="520" height="42" rx="21" fill="url(#pill)" stroke="#E86A47" stroke-opacity="0.28"/>
229
+ <text x="186" y="163"
230
+ fill="#F6EFE4"
231
+ font-size="18"
232
+ font-weight="600"
233
+ font-family="${FONT_SANS}, sans-serif"
234
+ opacity="0.92">${escapeXml(pillText)}</text>
235
+ </g>
236
+
237
+ <text x="114" y="${titleY}"
238
+ fill="#F6EFE4"
239
+ font-size="${titleFontSize}"
240
+ font-weight="800"
241
+ font-family="${FONT_SANS}, sans-serif">${titleTspans}</text>
242
+
243
+ <text x="114" y="${descY}"
244
+ fill="#C6B8A8"
245
+ font-size="26"
246
+ font-weight="500"
247
+ font-family="${FONT_SANS}, sans-serif">${descTspans}</text>
248
+
249
+ <rect x="114" y="${underlineY}" width="110" height="6" rx="3" fill="#E86A47"/>
250
+ <text x="114" y="${footerY}"
251
+ fill="#F6EFE4"
252
+ font-size="20"
253
+ font-weight="500"
254
+ opacity="0.90"
255
+ font-family="${FONT_MONO}, monospace">${escapeXml(params.footer)}</text>
256
+ </g>
257
+ </svg>`
258
+ }