rvlib-shipkit 2.18.0 → 2.20.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 (186) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/asks/asks-queue.ts +63 -10
  6. package/src/checks/SK040-release-words.check.ts +43 -0
  7. package/src/checks/SK041-annex-links.check.ts +28 -0
  8. package/src/checks/SK042-post-kinds.check.ts +73 -0
  9. package/src/cli/cmd_Annex.ts +179 -0
  10. package/src/cli/cmd_Asks.ts +3 -1
  11. package/src/cli/cmd_Commands.ts +4 -1
  12. package/src/cli/cmd_GlobalProcesses.ts +34 -11
  13. package/src/cli/cmd_Home.ts +41 -4
  14. package/src/cli/cmd_Messages.ts +155 -0
  15. package/src/cli/cmd_Releases.ts +48 -0
  16. package/src/cli/cmd_Review.ts +161 -6
  17. package/src/cli/cmd_Secret.ts +4 -30
  18. package/src/cli/cmd_Shot.ts +4 -4
  19. package/src/cli/cmd_Social.ts +179 -3
  20. package/src/cli/cmd_Trailer.ts +15 -3
  21. package/src/cli/family-pages.ts +2 -0
  22. package/src/cli/kit/index.ts +1 -1
  23. package/src/cli/kit/verb.ts +11 -3
  24. package/src/cli/registry.ts +8 -2
  25. package/src/collections/actions.ts +29 -1
  26. package/src/collections/collection-types.ts +10 -1
  27. package/src/collections/providers.ts +5 -2
  28. package/src/commands/model.ts +36 -0
  29. package/src/commands/registry.ts +49 -0
  30. package/src/commands/routes.ts +59 -0
  31. package/src/commands/runner.ts +35 -0
  32. package/src/commands/runs.ts +112 -0
  33. package/src/core/app-icon.ts +4 -3
  34. package/src/core/icon-type.ts +8 -0
  35. package/src/core/jobs.ts +4 -3
  36. package/src/core/layout.ts +5 -2
  37. package/src/core/squircle.ts +95 -0
  38. package/src/home/daemon-jobs.ts +26 -2
  39. package/src/home/global-units.ts +3 -0
  40. package/src/home/gui-app/ShipkitGui.swift +302 -5
  41. package/src/home/gui-app.ts +63 -33
  42. package/src/home/hmr-keep.ts +134 -0
  43. package/src/home/home-paths.ts +5 -1
  44. package/src/home/home-start.ts +14 -14
  45. package/src/home/lib-watch.ts +21 -11
  46. package/src/home/pm.ts +1 -1
  47. package/src/home/process-apps.ts +181 -0
  48. package/src/home/resources.ts +3 -3
  49. package/src/home/run-daemon.ts +11 -2
  50. package/src/home/run-pm.ts +9 -1
  51. package/src/home/run-web.ts +7 -4
  52. package/src/home/serve-web.ts +64 -14
  53. package/src/home/supervise.ts +3 -1
  54. package/src/identities/collection.ts +49 -0
  55. package/src/identities/identities.ts +130 -11
  56. package/src/identities/machine.ts +4 -3
  57. package/src/identities/rating.ts +33 -0
  58. package/src/identities/shown.ts +170 -0
  59. package/src/identities/steps.ts +5 -0
  60. package/src/media-store/purge.ts +15 -1
  61. package/src/media-store/remote.ts +22 -6
  62. package/src/messages/brief.ts +117 -0
  63. package/src/messages/collection.ts +40 -0
  64. package/src/messages/model.ts +171 -0
  65. package/src/messages/routes.ts +15 -0
  66. package/src/messages/score.ts +180 -0
  67. package/src/messages/tabs.ts +13 -0
  68. package/src/release/notes.ts +130 -0
  69. package/src/release/run-bump.ts +41 -18
  70. package/src/release/run-release.ts +22 -4
  71. package/src/release/run-releases.ts +17 -15
  72. package/src/release/unit-resolve.ts +9 -0
  73. package/src/releases/add.ts +66 -0
  74. package/src/releases/collection.ts +36 -0
  75. package/src/releases/from-card.ts +66 -0
  76. package/src/releases/model.ts +267 -0
  77. package/src/releases/pictures.ts +89 -0
  78. package/src/releases/routes.ts +36 -0
  79. package/src/releases/store.ts +71 -0
  80. package/src/repo-config.ts +5 -0
  81. package/src/review/cells.ts +0 -11
  82. package/src/review/format.ts +10 -6
  83. package/src/review/http.ts +7 -2
  84. package/src/review/model.ts +92 -3
  85. package/src/review/notes.ts +2 -48
  86. package/src/review/routes.ts +28 -10
  87. package/src/review/stage-card.ts +197 -0
  88. package/src/review/stage-routes.ts +123 -0
  89. package/src/review/store.ts +117 -19
  90. package/src/review/trailer-card.ts +99 -0
  91. package/src/review/trailer-desk.ts +57 -4
  92. package/src/review/trailer-model.ts +41 -7
  93. package/src/review/trailer-notes.ts +45 -0
  94. package/src/review/trailer-routes.ts +22 -13
  95. package/src/secrets/manager.ts +59 -0
  96. package/src/secrets/name.ts +2 -0
  97. package/src/serve/hub-app/app-bridge.ts +71 -0
  98. package/src/serve/hub-app/col-card.tsx +10 -0
  99. package/src/serve/hub-app/cols-svc.ts +37 -6
  100. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  101. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  102. package/src/serve/hub-app/commands.css +24 -0
  103. package/src/serve/hub-app/hash-route.ts +40 -1
  104. package/src/serve/hub-app/home-st.ts +11 -2
  105. package/src/serve/hub-app/home.html +3 -0
  106. package/src/serve/hub-app/hub-app.tsx +6 -0
  107. package/src/serve/hub-app/hub.css +1 -0
  108. package/src/serve/hub-app/icons.tsx +5 -0
  109. package/src/serve/hub-app/identities-view.tsx +4 -1
  110. package/src/serve/hub-app/identities.css +1 -0
  111. package/src/serve/hub-app/index.html +3 -0
  112. package/src/serve/hub-app/keys.ts +2 -2
  113. package/src/serve/hub-app/machine-st.ts +41 -10
  114. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  115. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  116. package/src/serve/hub-app/messages.css +35 -0
  117. package/src/serve/hub-app/releases/releases-page.tsx +94 -0
  118. package/src/serve/hub-app/releases/releases-st.ts +69 -0
  119. package/src/serve/hub-app/releases.css +25 -0
  120. package/src/serve/hub-app/repo-sections.ts +15 -1
  121. package/src/serve/hub-app/repo-st.ts +56 -5
  122. package/src/serve/hub-app/review/clip-st.ts +31 -3
  123. package/src/serve/hub-app/review/note-place.ts +31 -0
  124. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  125. package/src/serve/hub-app/review/review-st.ts +77 -2
  126. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  127. package/src/serve/hub-app/review/review-views.tsx +164 -58
  128. package/src/serve/hub-app/review/thread-st.ts +108 -41
  129. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  130. package/src/serve/hub-app/review/trailer-page.tsx +62 -31
  131. package/src/serve/hub-app/review/trailer-st.ts +138 -26
  132. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
  133. package/src/serve/hub-app/review.css +49 -6
  134. package/src/serve/hub-app/social/comms-page.tsx +55 -23
  135. package/src/serve/hub-app/social/identity-pictures.ts +112 -0
  136. package/src/serve/hub-app/social/kit.tsx +9 -6
  137. package/src/serve/hub-app/social/post-card.tsx +10 -2
  138. package/src/serve/hub-app/social/social-model.ts +37 -3
  139. package/src/serve/hub-app/social/social-page.tsx +236 -82
  140. package/src/serve/hub-app/social/social-st.ts +79 -26
  141. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  142. package/src/serve/hub-app/social/stage-st.ts +310 -0
  143. package/src/serve/hub-app/social/step-layout.ts +42 -0
  144. package/src/serve/hub-app/social.css +68 -4
  145. package/src/serve/hub-app/tree-build.ts +38 -1
  146. package/src/serve/hub-app/tree-svc.ts +10 -3
  147. package/src/serve/project-gutter-route.ts +4 -2
  148. package/src/serve/same-origin.ts +24 -1
  149. package/src/serve/serve-hub.ts +27 -3
  150. package/src/shipkit-files.ts +9 -7
  151. package/src/shot/shooter.ts +3 -3
  152. package/src/shot/shot-ask.ts +14 -3
  153. package/src/shot/shot.shipkit.ts +1 -1
  154. package/src/social/discord-layout.ts +282 -0
  155. package/src/social/fit.ts +84 -0
  156. package/src/social/identity-words.ts +74 -0
  157. package/src/social/kind-pages.ts +41 -0
  158. package/src/social/kinds.ts +92 -0
  159. package/src/social/load.ts +105 -9
  160. package/src/social/md.ts +14 -6
  161. package/src/social/media-limit.ts +63 -2
  162. package/src/social/presence.ts +1 -1
  163. package/src/social/publish/bluesky.ts +58 -19
  164. package/src/social/publish/discord.ts +3 -2
  165. package/src/social/publish/index.ts +31 -5
  166. package/src/social/reach.ts +49 -0
  167. package/src/social/release-stage.ts +173 -0
  168. package/src/social/routes.ts +44 -9
  169. package/src/social/stage.ts +227 -0
  170. package/src/social/strip.ts +85 -0
  171. package/src/social/text.ts +6 -2
  172. package/src/social/unit.ts +57 -1
  173. package/src/social/writes.ts +11 -0
  174. package/src/stores/routes.ts +2 -2
  175. package/src/suite/judge-suites.ts +1 -1
  176. package/src/suite/suite-cli.ts +5 -5
  177. package/src/trailer/build.ts +90 -52
  178. package/src/trailer/draft.ts +28 -0
  179. package/src/trailer/footage.ts +4 -2
  180. package/src/trailer/grammar.ts +25 -13
  181. package/src/trailer/graph.ts +32 -9
  182. package/src/trailer/profile.ts +35 -0
  183. package/src/trailer/prune.ts +15 -10
  184. package/src/trailer/public-words.ts +41 -0
  185. package/src/trailer/stitch.ts +22 -10
  186. package/src/trailer/titles.ts +47 -2
@@ -0,0 +1,134 @@
1
+ // the page's hot reload socket kept across a restart of the web. Bun's client
2
+ // reloads the whole page when its socket comes back, whatever moved, so a web
3
+ // restart for its own server code reloaded a page whose code had not changed.
4
+ // This script runs in the page's head before Bun's client, and hands that
5
+ // client one socket that never drops: under it, the real socket reconnects,
6
+ // says when it last heard the web (`since`), and the web answers whether a
7
+ // file of the page's bundle moved since then (serve-web.ts), and stamps the
8
+ // head it serves. Nothing moved: the client's subscriptions are sent again and
9
+ // it never sees the gap. A file moved, another head, or another dev server
10
+ // version: the client gets its version message
11
+ // and reloads the page, which is the reload that means something.
12
+ //
13
+ // the one constraint a reader breaks first: `keepHmr` ships as its own source
14
+ // text (hmrKeepScript), so it closes over nothing and imports nothing.
15
+
16
+ /** the text frames the web sends on the hot reload socket: its time, the stamp of the head it serves (its own code
17
+ * puts it there, so its edit reaches no page file), then whether the page moved while it was away */
18
+ export const HMR_WORDS = { beat: 't:', head: 'head:', fresh: 'page:fresh', moved: 'page:moved' } as const
19
+ /** how often the web stamps each hot reload socket with its time */
20
+ export const HMR_BEAT_MS = 2_000
21
+ /** a dropped socket tries again after `firstMs`, the wait doubling up to `maxMs` */
22
+ export const HMR_RETRY = { firstMs: 1_000, maxMs: 8_000 }
23
+
24
+ type Win = { WebSocket: typeof WebSocket; location: { href: string }; setTimeout: (f: () => void, ms: number) => unknown }
25
+ type Words = typeof HMR_WORDS
26
+
27
+ /** installs the kept socket on `win`: a socket to `/_bun/hmr` is a kept one, every other socket is native */
28
+ export function keepHmr(win: Win, words: Words, retry: typeof HMR_RETRY): void {
29
+ const Native = win.WebSocket
30
+ /** Bun's version message, the first a socket gets */
31
+ const VERSION = 86
32
+ function Keep(this: Record<string, unknown>, url: string): void {
33
+ const self = this
34
+ let ws: WebSocket
35
+ let closed = false
36
+ let heard = 0
37
+ /** the stamp a socket that came back said, the page's own once that web finds it current */
38
+ let waiting = 0
39
+ let version: string | null = null
40
+ let again = false
41
+ let verdict: string | null = null
42
+ /** the stamp of the head the web served this page with, and of the head the web now serves */
43
+ let loadedHead: string | null = null
44
+ let headNow: string | null = null
45
+ let wait = retry.firstMs
46
+ /** the client's subscriptions and its last route, sent again on a socket that came back */
47
+ const subs = new Map<string, string>()
48
+ self.readyState = 0
49
+ self.binaryType = 'arraybuffer'
50
+ self.url = url
51
+ const tell = (k: 'onopen' | 'onmessage' | 'onclose', e: Event): void => {
52
+ const f = self[k]
53
+ if (typeof f === 'function') f.call(self, e)
54
+ }
55
+ function connect(): void {
56
+ if (closed) return
57
+ const u = new URL(url, win.location.href)
58
+ if (again) u.searchParams.set('since', String(heard))
59
+ ws = new Native(u.href)
60
+ ws.binaryType = 'arraybuffer'
61
+ ws.onopen = (e) => {
62
+ wait = retry.firstMs
63
+ if (again) return
64
+ self.readyState = 1
65
+ tell('onopen', e)
66
+ }
67
+ ws.onmessage = (e) => {
68
+ if (typeof e.data === 'string') {
69
+ // a stamp counts only once the page is current on this socket: a web that drops before its
70
+ // version message never makes a missed edit look seen
71
+ if (e.data.startsWith(words.beat)) {
72
+ const t = Number(e.data.slice(words.beat.length)) || 0
73
+ if (again) waiting = t
74
+ else heard = t || heard
75
+ } else if (e.data.startsWith(words.head)) {
76
+ const h = e.data.slice(words.head.length)
77
+ if (!again) loadedHead ??= h
78
+ headNow = h
79
+ } else if (e.data === words.fresh || e.data === words.moved) verdict = e.data
80
+ return
81
+ }
82
+ const b = new Uint8Array(e.data as ArrayBuffer)
83
+ if (b[0] === VERSION) {
84
+ const v = new TextDecoder().decode(b.subarray(1))
85
+ if (again && verdict === words.fresh && v === version && headNow === loadedHead) {
86
+ again = false
87
+ heard = waiting || heard
88
+ for (const m of subs.values()) ws.send(m)
89
+ return
90
+ }
91
+ version ??= v
92
+ }
93
+ tell('onmessage', e)
94
+ }
95
+ ws.onerror = (e) => { e.preventDefault() }
96
+ ws.onclose = (e) => {
97
+ // closed by the client, or a first socket that never opened: the client's own to retry
98
+ if (closed || self.readyState !== 1) {
99
+ closed = true
100
+ self.readyState = 3
101
+ tell('onclose', e)
102
+ return
103
+ }
104
+ again = true
105
+ verdict = null
106
+ headNow = null
107
+ waiting = 0
108
+ win.setTimeout(connect, wait)
109
+ wait = Math.min(wait * 2, retry.maxMs)
110
+ }
111
+ }
112
+ self.send = (m: string | BufferSource): void => {
113
+ if (typeof m === 'string' && (m[0] === 's' || m[0] === 'n')) subs.set(m[0] === 'n' ? 'n' : m, m)
114
+ if (ws.readyState === 1 && !again) ws.send(m)
115
+ }
116
+ self.close = (): void => {
117
+ closed = true
118
+ ws.close()
119
+ }
120
+ connect()
121
+ }
122
+ function Socket(url: string | URL, protocols?: string | string[]): object {
123
+ const u = new URL(String(url), win.location.href)
124
+ if (u.pathname === '/_bun/hmr' && protocols === undefined) return new (Keep as unknown as new (url: string) => object)(u.href)
125
+ return protocols === undefined ? new Native(url) : new Native(url, protocols)
126
+ }
127
+ Socket.prototype = Native.prototype
128
+ Object.assign(Socket, { CONNECTING: 0, OPEN: 1, CLOSING: 2, CLOSED: 3 })
129
+ win.WebSocket = Socket as unknown as typeof WebSocket
130
+ }
131
+
132
+ /** the script the web puts in the page's head, before Bun's client runs */
133
+ export const hmrKeepScript = (retry = HMR_RETRY): string => `<script>(${keepHmr.toString()})(window, ${JSON.stringify(HMR_WORDS)}, ${JSON.stringify(retry)})</script>`
134
+ export const HMR_KEEP_SCRIPT = hmrKeepScript()
@@ -2,7 +2,11 @@
2
2
  // Nothing here lives in a repo: the home is per machine, and a repo that is
3
3
  // cloned elsewhere carries none of it.
4
4
  import { homedir } from 'os'
5
- import { join } from 'path'
5
+ import { dirname, join } from 'path'
6
+ import { gitRoot } from '../core/git-root.ts'
7
+
8
+ /** the house repo: the checkout that holds the house wiki index, the one root pm and the daemon run from */
9
+ export const houseOfIndex = (index: string): string | null => gitRoot(dirname(index))?.top ?? null
6
10
 
7
11
  /** just below the hashed hub range (4800-4979), so no repo hub can hash onto it */
8
12
  export const DEFAULT_HOME_PORT = 4799
@@ -3,8 +3,7 @@
3
3
  // serve handoff both come through here.
4
4
  import { existsSync, mkdirSync, readFileSync } from 'fs'
5
5
  import { homedir } from 'os'
6
- import { dirname, join, resolve } from 'path'
7
- import { gitRoot } from '../core/git-root.ts'
6
+ import { join, resolve } from 'path'
8
7
  import { homeRepo, houseIndex } from '../serve/project-gutter.ts'
9
8
  import type { WrapperOf } from './gui-app.ts'
10
9
 
@@ -12,7 +11,7 @@ import type { WrapperOf } from './gui-app.ts'
12
11
  // at the startup of every command that imports this module
13
12
  const gui = (): Promise<typeof import('./gui-app.ts')> => import('./gui-app.ts')
14
13
  import { installedHouseRoot, LABEL, plistPath } from './home-launchd.ts'
15
- import { childLog, daemonPort, daemonUp, homeDir, homePort, homeUp, pmLog } from './home-paths.ts'
14
+ import { childLog, daemonPort, daemonUp, homeDir, homePort, homeUp, houseOfIndex, pmLog } from './home-paths.ts'
16
15
 
17
16
  /** the pm LaunchAgent is installed: on this machine no hub runs outside the home */
18
17
  export const homeInstalled = (): boolean => existsSync(plistPath())
@@ -62,16 +61,17 @@ export function houseCli(root: string, own: string): string {
62
61
  return own
63
62
  }
64
63
 
65
- /** the repo that hosts the house wiki, seen from any house repo, or null */
66
- export function houseRootOf(cwd: string): string | null {
67
- const index = houseIndex(homeRepo(cwd), homedir())
68
- if (index == null) return null
69
- return gitRoot(dirname(index))?.top ?? null
64
+ /** the repo that hosts the house wiki, seen from any folder of any house repo, or null */
65
+ export function houseRootOf(cwd: string, home = homedir()): string | null {
66
+ const index = houseIndex(homeRepo(cwd), home)
67
+ return index == null ? null : houseOfIndex(index)
70
68
  }
71
69
 
72
- /** the house the shipkit app wears the mark of: the one cwd sits in, else the
73
- * one the installed pm runs from. Never cwd itself, which carries no mark */
74
- export const guiRoot = (cwd: string, plist = plistPath()): string | null => houseRootOf(cwd) ?? installedHouseRoot(plist)
70
+ /** the house this machine runs: the one cwd sits in, else the one the
71
+ * installed pm runs from. Never cwd itself: a daemon run from a folder
72
+ * inside a repo finds no repo config there and never boots. The pm agent's
73
+ * root and the shipkit app's mark */
74
+ export const houseRoot = (cwd: string, o: { plist?: string; home?: string } = {}): string | null => houseRootOf(cwd, o.home) ?? installedHouseRoot(o.plist ?? plistPath())
75
75
 
76
76
  export const CHROME =process.env.CHROME ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
77
77
  /** the window's own Chrome profile: its own dock icon and cookies, apart from the everyday browser */
@@ -96,7 +96,7 @@ export async function openWindow(url: string, o: { root?: string | null; version
96
96
  const { BUNDLE_ID, canBuildGui, ensureGuiApp, quitCmd } = await gui()
97
97
  if (canBuildGui()) {
98
98
  try {
99
- const { app, rebuilt } = await ensureGuiApp({ root: o.root ?? guiRoot(process.cwd()),version: o.version ?? '0' })
99
+ const { app, rebuilt } = await ensureGuiApp({ root: o.root ?? houseRoot(process.cwd()), version: o.version ?? '0' })
100
100
  // a running copy is the old build: it quits, and the new one opens the window
101
101
  if (rebuilt) Bun.spawnSync(quitCmd(BUNDLE_ID), { stdout: 'ignore', stderr: 'ignore' })
102
102
  const cmd = ['open', '-a', app, url]
@@ -109,8 +109,8 @@ export async function openWindow(url: string, o: { root?: string | null; version
109
109
  return chromeWindow(url)
110
110
  }
111
111
 
112
- /** a global process's own app: built on first use in its repo's
113
- * `.shipkit/wrapper/`, then opened with no url, so a running copy comes to
112
+ /** a global process's own app: built in ~/Applications when missing or
113
+ * stale, then opened with no url, so a running copy comes to
114
114
  * the front instead of stacking windows. Where no app can be built, a
115
115
  * Chrome app window on its url */
116
116
  export async function openProcessApp(d: WrapperOf, o: { version: string; warn?: (l: string) => void }): Promise<string[]> {
@@ -21,26 +21,34 @@ const CODE = /\.(ts|tsx|js|jsx|json|css|html)$/
21
21
  const LOADER: Record<string, 'ts' | 'tsx' | 'js' | 'jsx'> = { '.ts': 'ts', '.tsx': 'tsx', '.js': 'js', '.jsx': 'jsx' }
22
22
  const TRY = ['', '.ts', '.tsx', '.js', '/index.ts', '/index.tsx']
23
23
 
24
- function resolveRel(from: string, spec: string): string | null {
24
+ /** how libGraph reads the tree: the disk, or a test's files */
25
+ export type TreeIo = { exists: (f: string) => boolean; read: (f: string) => string }
26
+ const DISK: TreeIo = { exists: existsSync, read: (f) => readFileSync(f, 'utf8') }
27
+
28
+ function resolveRel(from: string, spec: string, io: TreeIo): string | null {
25
29
  const base = resolve(dirname(from), spec)
26
- for (const s of TRY) if (existsSync(base + s) && extname(base + s) !== '') return base + s
30
+ for (const s of TRY) if (io.exists(base + s) && extname(base + s) !== '') return base + s
27
31
  return null
28
32
  }
29
33
 
30
34
  /** every lib file `entry` reaches through its relative imports, type only
31
- * imports left out (an edit there changes no running code). With `bundles`,
32
- * an imported html page is followed into the scripts and styles it names:
33
- * the web serves those, the daemon only holds the page object */
34
- export function libGraph(entry: string, o: { bundles?: boolean } = {}): Set<string> {
35
+ * imports left out (an edit there changes no running code). An imported
36
+ * html page is left out too: Bun's dev server watches the page and every
37
+ * file of its bundle, and hot swaps an edit into the open page, so no role
38
+ * restarts for it. With `bundles`, the files of the page's bundle: an html
39
+ * page followed into the scripts and styles it names */
40
+ export function libGraph(entry: string, o: { bundles?: boolean; io?: TreeIo } = {}): Set<string> {
41
+ const io = o.io ?? DISK
35
42
  const out = new Set<string>()
36
43
  const todo = [resolve(entry)]
37
44
  while (todo.length > 0) {
38
45
  const f = todo.pop()!
39
46
  if (out.has(f)) continue
40
- out.add(f)
41
47
  const ext = extname(f)
48
+ if (ext === '.html' && o.bundles !== true) continue
49
+ out.add(f)
42
50
  let text: string
43
- try { text = readFileSync(f, 'utf8') } catch { continue }
51
+ try { text = io.read(f) } catch { continue }
44
52
  const specs: string[] = []
45
53
  if (LOADER[ext] != null) {
46
54
  try {
@@ -51,13 +59,16 @@ export function libGraph(entry: string, o: { bundles?: boolean } = {}): Set<stri
51
59
  }
52
60
  for (const s of specs) {
53
61
  if (!s.startsWith('.')) continue
54
- const r = resolveRel(f, s)
62
+ const r = resolveRel(f, s, io)
55
63
  if (r != null) todo.push(r)
56
64
  }
57
65
  }
58
66
  return out
59
67
  }
60
68
 
69
+ /** the files a role restarts on: what its runner module runs */
70
+ export const roleGraph = (entry: string): Set<string> => libGraph(entry)
71
+
61
72
  /** a burst of saves is one change once no write came for this long: an agent saves file after file, and each
62
73
  * restart rescans every house repo */
63
74
  export const SETTLE_MS = 5_000
@@ -148,7 +159,6 @@ export function reloadOnOwnCode(o: {
148
159
  role: 'pm' | 'daemon' | 'web'
149
160
  /** the role's runner module: its graph is what the role reloads on */
150
161
  entry: string
151
- bundles?: boolean
152
162
  busy?: () => boolean
153
163
  before: () => void
154
164
  keep?: boolean
@@ -156,7 +166,7 @@ export function reloadOnOwnCode(o: {
156
166
  }): { stop: () => void; files: number } {
157
167
  const onCopy = copyStamp(OWN_LIB) != null
158
168
  const tree = homeLib()
159
- const graph = libGraph(onCopy ? join(tree, relative(OWN_LIB, o.entry)) : o.entry, { bundles: o.bundles })
169
+ const graph = roleGraph(onCopy ? join(tree, relative(OWN_LIB, o.entry)) : o.entry)
160
170
  const lib = new LibWatch(tree, { only: onCopy ? undefined : graph })
161
171
  if (lib.error != null) o.io.printErr(`WARN no watch on the shipkit source (${lib.error}), so an edit of the ${o.role} needs a restart of it`)
162
172
  const probe = new TreeProbe(() => probeLoad(tree, bootEntries(tree, o.role)), () => `${lib.seq}|${versionAt(tree)}`)
package/src/home/pm.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  import { existsSync } from 'fs'
11
11
  import { join } from 'path'
12
12
  import { LIB_VERSION } from '../core/lib-version.ts'
13
- import { iconImageType } from '../shipkit-files.ts'
13
+ import { iconImageType } from '../core/icon-type.ts'
14
14
  import { sameOrigin } from '../serve/same-origin.ts'
15
15
  import { readBeat } from './beat.ts'
16
16
  import { childBeat, childLog, childPid, daemonPort, homePort, pmLog, pmPort } from './home-paths.ts'
@@ -0,0 +1,181 @@
1
+ // every global process with a url as its own macOS app in ~/Applications,
2
+ // named by its `app` (else its label), where Spotlight and Launchpad find it.
3
+ // The daemon's `apps` job (home/daemon-jobs.ts) builds what is missing or
4
+ // stale through home/gui-app.ts, and removes the apps of a process renamed or
5
+ // gone. A repo's `.shipkit/wrapper/` holds no app: any shipkit bundle there is removed too.
6
+ //
7
+ // the one constraint a reader breaks first: the sweep removes only a bundle
8
+ // shipkit built (shipkitBundleOf), never another app of the folder, and
9
+ // nothing at all when a unit file did not load: its processes would look gone.
10
+ import { createHash } from 'crypto'
11
+ import { existsSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync } from 'fs'
12
+ import { homedir } from 'os'
13
+ import { join } from 'path'
14
+ import { fileURLToPath } from 'url'
15
+ import { repoUnitFiles } from '../core/discover-checks.ts'
16
+ import { LAYOUT } from '../core/layout.ts'
17
+ import { yieldLoop } from '../core/loop-watch.ts'
18
+ import { machineGet } from '../core/machine-db.ts'
19
+ import { homeRepo, houseRepos } from '../serve/project-gutter.ts'
20
+
21
+ /** the one source every app's window is compiled from */
22
+ export const GUI_SOURCE = fileURLToPath(new URL('./gui-app/ShipkitGui.swift', import.meta.url))
23
+
24
+ /** where every app shipkit builds lands: Spotlight indexes it, and skips a dot folder or a symlink */
25
+ export const appsDir = (home = homedir()): string => process.env.SHIPKIT_APPS_DIR ?? join(home, 'Applications')
26
+
27
+ /** every process app's bundle id starts so: the sweep removes nothing else */
28
+ export const WRAPPER_PREFIX = 'dev.shipkit.app.'
29
+ export const wrapperBundleId = (id: string): string => `${WRAPPER_PREFIX}${id.replace(/[^A-Za-z0-9-]+/g, '-')}`
30
+
31
+ type Named = { label: string; app?: string | null }
32
+ export const appNameOf = (d: Named): string => d.app ?? d.label
33
+ export const wrapperPath = (d: Named, dir = appsDir()): string => join(dir, `${appNameOf(d).replace(/[/:]+/g, '-')}.app`)
34
+
35
+ /** the bundle id of a process app shipkit built (its id under WRAPPER_PREFIX
36
+ * and its build stamp), or null for any other app */
37
+ export function shipkitBundleOf(app: string): string | null {
38
+ const plist = join(app, 'Contents', 'Info.plist')
39
+ if (!existsSync(plist) || !existsSync(join(app, 'Contents', 'Resources', 'stamp'))) return null
40
+ let text: string
41
+ try { text = readFileSync(plist, 'utf8') } catch { return null }
42
+ const id = /<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(text)?.[1] ?? null
43
+ return id?.startsWith(WRAPPER_PREFIX) ? id : null
44
+ }
45
+
46
+ /** a process as its app needs it (WrapperOf in gui-app.ts) */
47
+ export type AppOf = Named & { id: string; url: string | null; icon: string | null; root: string }
48
+
49
+ /** the apps the processes want, one a name. The folder is case blind, so
50
+ * two names that differ by case are one: the second process gets no app */
51
+ export function plannedApps<T extends AppOf>(processes: T[], dir: string, reserved: string[] = []): { want: { d: T; path: string }[]; errors: string[] } {
52
+ const taken = new Map<string, string>(reserved.map((p) => [p.toLowerCase(), 'another app']))
53
+ const want: { d: T; path: string }[] = []
54
+ const errors: string[] = []
55
+ for (const d of processes) {
56
+ if (d.url == null) continue
57
+ const path = wrapperPath(d, dir)
58
+ const by = taken.get(path.toLowerCase())
59
+ if (by != null) {
60
+ errors.push(`${d.id}: its app name '${appNameOf(d)}' is ${by}'s too, so it gets no app: give it its own (app: in its unit file)`)
61
+ continue
62
+ }
63
+ taken.set(path.toLowerCase(), d.id)
64
+ want.push({ d, path })
65
+ }
66
+ return { want, errors }
67
+ }
68
+
69
+ /** the bundles shipkit built in these folders that no process wants */
70
+ export function staleApps(dirs: string[], keep: string[]): string[] {
71
+ const kept = new Set(keep.map((p) => p.toLowerCase()))
72
+ const out: string[] = []
73
+ for (const dir of dirs) {
74
+ let names: string[]
75
+ try { names = readdirSync(dir) } catch { continue }
76
+ for (const name of names.sort()) {
77
+ const p = join(dir, name)
78
+ if (name.endsWith('.app') && !kept.has(p.toLowerCase()) && shipkitBundleOf(p) != null) out.push(p)
79
+ }
80
+ }
81
+ return out
82
+ }
83
+
84
+ const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister'
85
+
86
+ /** removes a bundle, and tells launch services it is gone, so Launchpad drops it */
87
+ const removeReal = (app: string): void => {
88
+ rmSync(app, { recursive: true, force: true })
89
+ if (existsSync(LSREGISTER)) Bun.spawnSync([LSREGISTER, '-u', app], { stdout: 'ignore', stderr: 'ignore' })
90
+ }
91
+
92
+ export type AppsTickIo = {
93
+ processes: AppOf[]
94
+ /** the scan's errors: a unit file that did not load stops the sweep */
95
+ scanErrors: string[]
96
+ /** the house repos: each one's `.shipkit/wrapper/` is swept */
97
+ repos: string[]
98
+ dir: string
99
+ /** builds one app (gui-app.ts ensureWrapperApp); null: none can be built here */
100
+ build: ((d: AppOf, dir: string) => Promise<{ app: string; rebuilt: boolean }>) | null
101
+ /** paths in `dir` no process may take (the shipkit app) */
102
+ reserved?: string[]
103
+ remove?: (app: string) => void
104
+ print: (l: string) => void
105
+ printErr: (l: string) => void
106
+ }
107
+
108
+ /** one pass: build what is missing or stale, then remove the stale */
109
+ export async function appsTick(o: AppsTickIo): Promise<{ built: string[]; removed: string[] }> {
110
+ const { want, errors } = plannedApps(o.processes, o.dir, o.reserved)
111
+ for (const e of errors) o.printErr(`WARN ${e}`)
112
+ const built: string[] = []
113
+ if (o.build == null) o.printErr('WARN no app built: this machine has no swiftc and iconutil, or is not macOS')
114
+ else {
115
+ for (const { d } of want) {
116
+ try {
117
+ const r = await o.build(d, o.dir)
118
+ if (r.rebuilt) built.push(r.app)
119
+ } catch (e) {
120
+ o.printErr(`WARN the app of ${d.id} was not built: ${(e as Error).message}`)
121
+ }
122
+ }
123
+ }
124
+ for (const app of built) o.print(`ok: built ${app}`)
125
+ if (o.scanErrors.length > 0) {
126
+ o.printErr(`WARN no stale app removed: a unit file did not load, so its processes look gone (${o.scanErrors[0]})`)
127
+ return { built, removed: [] }
128
+ }
129
+ const homes = o.repos.map((r) => join(r, LAYOUT.wrapper))
130
+ const removed = staleApps([o.dir, ...homes], want.map((w) => w.path))
131
+ for (const app of removed) {
132
+ ;(o.remove ?? removeReal)(app)
133
+ o.print(`ok: removed ${app}, no process has it`)
134
+ }
135
+ for (const home of homes) {
136
+ try { if (readdirSync(home).length === 0) rmdirSync(home) } catch { /* absent */ }
137
+ }
138
+ return { built, removed }
139
+ }
140
+
141
+ /** how often the daemon looks whether the apps' sources moved */
142
+ export const APPS_EVERY_MS = 60_000
143
+ /** the stamp of the last pass (machine db), and when */
144
+ export const APPS_DONE = 'process-apps-done'
145
+ /** a pass at least this often: an icon or a colour is not in the stamp */
146
+ export const APPS_MAX_MS = 6 * 3600_000
147
+
148
+ const statOf = (f: string | null): string => {
149
+ if (f == null) return '-'
150
+ try {
151
+ const st = statSync(f)
152
+ return `${st.mtimeMs}:${st.size}`
153
+ } catch {
154
+ return '-'
155
+ }
156
+ }
157
+
158
+ /** the outside of what the apps are made of, a stat each: every repo's unit
159
+ * files and wrapper folder, the window's source, the names in the apps
160
+ * folder (an app deleted by hand comes back). Null off macOS or with no house */
161
+ export async function appsSourcesStamp(root: string, home: string = homedir(), platform = process.platform): Promise<string | null> {
162
+ if (platform !== 'darwin') return null
163
+ const h = houseRepos(homeRepo(root), home)
164
+ if (h.index == null) return null
165
+ let names: string[] = []
166
+ try { names = readdirSync(appsDir(home)).filter((n) => n.endsWith('.app')).sort() } catch { /* no folder yet */ }
167
+ const parts = [statOf(GUI_SOURCE), names.join('|')]
168
+ for (const r of h.repos) {
169
+ await yieldLoop()
170
+ parts.push(r.path, String(existsSync(join(r.path, LAYOUT.wrapper))))
171
+ for (const f of repoUnitFiles(r.path)) parts.push(f, statOf(f))
172
+ }
173
+ return createHash('sha256').update(parts.join('\n')).digest('hex').slice(0, 16)
174
+ }
175
+
176
+ /** a pass is due when the stamp moved since the last one, or that one is old */
177
+ export function appsDue(now: number, stamp: string | null): boolean {
178
+ if (stamp == null) return false
179
+ const done = machineGet<{ stamp: string; at: number }>(APPS_DONE)
180
+ return done == null || done.stamp !== stamp || now - done.at >= APPS_MAX_MS
181
+ }
@@ -2,7 +2,7 @@
2
2
  // declared once in a repo's `<name>.shipkit.ts` as `globalProcess({...})`
3
3
  // (shipkit-files.ts) and owned by pm: a switch, a restart, its log, its
4
4
  // action buttons, and its url opened in the default browser, in Chrome, or
5
- // as its own app (home/gui-app.ts builds that app in its repo on first use).
5
+ // as its own app (home/process-apps.ts keeps it in ~/Applications).
6
6
  //
7
7
  // two kinds: with no `down`, the command IS the service, supervised like a
8
8
  // hub (restarted on a crash, signalled on stop). With `down`, the command is
@@ -13,7 +13,7 @@ import { homedir } from 'os'
13
13
  import { dirname, join } from 'path'
14
14
  import { fileURLToPath } from 'url'
15
15
  import type { GlobalProcessDecl } from './global-units.ts'
16
- import { iconImageType } from '../shipkit-files.ts'
16
+ import { iconImageType } from '../core/icon-type.ts'
17
17
  import { Proc, realDeps, tailLines, type ProcStatus, type SuperviseDeps } from './supervise.ts'
18
18
  import { resourceLog, resourcePid } from './home-paths.ts'
19
19
  import { groupOf, localPort, portHolders } from '../core/port-holders.ts'
@@ -101,7 +101,7 @@ const openApp: OpenApp = async (d, log) => {
101
101
  mkdirSync(dirname(log), { recursive: true })
102
102
  const fd = openSync(log, 'a')
103
103
  try {
104
- const spec = { id: d.id, label: d.label, url: d.url, icon: d.icon, root: d.root }
104
+ const spec = { id: d.id, label: d.label, app: d.app, url: d.url, icon: d.icon, root: d.root }
105
105
  return await Bun.spawn([process.execPath, OPEN_APP, '--process', JSON.stringify(spec)], { stdio: ['ignore', fd, fd] }).exited
106
106
  } finally {
107
107
  closeSync(fd)
@@ -20,7 +20,7 @@ import { ensureIdentity } from '../core/identity.ts'
20
20
  import { homedir } from 'os'
21
21
  import { join } from 'path'
22
22
  import { startBeat } from './beat.ts'
23
- import { childBeat, childLog, daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
23
+ import { childBeat, childLog, daemonPort, homeDir, homePort, homeUp, houseOfIndex, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
24
24
  import { inboxAddress } from './inbox-shape.ts'
25
25
  import { HomeState } from './home-state.ts'
26
26
  import { Hubs } from './hubs.ts'
@@ -44,7 +44,16 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
44
44
  const own = o.port ?? daemonPort()
45
45
  // the port a page reaches every hub on: the web's
46
46
  const port = homePort()
47
- const house = houseRepos(root, homedir())
47
+ const seen = houseRepos(root, homedir())
48
+ // started in another folder (a house repo, a folder inside one): the daemon runs from the house repo, whose config
49
+ // it loads, never from the folder it started in
50
+ const top = seen.index == null ? null : houseOfIndex(seen.index)
51
+ const moved = top != null && top !== root
52
+ if (moved) {
53
+ io.print(`note: the daemon started in ${root}, so it runs from the house repo ${top}`)
54
+ root = top
55
+ }
56
+ const house = moved ? houseRepos(root, homedir()) : seen
48
57
  if (house.index == null) {
49
58
  io.printErr(`FAIL: ${root} includes no house wiki index in its CLAUDE.md, so the daemon has no repos to load. Run it from the repo that hosts the house wiki`)
50
59
  return 1
@@ -7,7 +7,7 @@
7
7
  // against pm's own 20.
8
8
  import { stampConsole } from '../core/log-stamp.ts'
9
9
  import { fileURLToPath } from 'url'
10
- import { daemonPort, homeDir, homePort, homeUp, homeUrl, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
10
+ import { daemonPort, homeDir, homePort, homeUp, homeUrl, houseOfIndex, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
11
11
  import { reloadOnOwnCode } from './lib-watch.ts'
12
12
  import { Pm, PM_TICK_MS, type Role } from './pm.ts'
13
13
  import { Resources } from './resources.ts'
@@ -81,6 +81,14 @@ export async function runPm(root: string, io: HomeIo, o: { port?: number } = {})
81
81
  let c: PmConfig
82
82
  try {
83
83
  c = await readPmConfig(root)
84
+ // started from another folder (a house repo, a folder inside one): pm and its children run from the house
85
+ // repo, never from the folder pm started in, where the daemon finds no repo config
86
+ const house = c.index == null ? null : houseOfIndex(c.index)
87
+ if (house != null && house !== root) {
88
+ io.print(`note: pm started in ${root}, so it runs from the house repo ${house}`)
89
+ root = house
90
+ c = await readPmConfig(root)
91
+ }
84
92
  } catch (e) {
85
93
  io.printErr(`FAIL: ${(e as Error).message}`)
86
94
  return 1
@@ -1,21 +1,24 @@
1
1
  // `shipkit web`: the page on the home port, in front of the daemon and pm. It
2
2
  // loads no repo and no config, so it starts in a moment and a daemon restart
3
3
  // never moves it: the page stays up and says the daemon is down. An edit of
4
- // its own code, the page included, restarts it in place (lib-watch.ts).
4
+ // its server code restarts it in place (lib-watch.ts), the open page kept
5
+ // (hmr-keep.ts); an edit of the page is Bun's hot reload's, never a restart.
5
6
  import homePage from '../serve/hub-app/home.html'
6
7
  import { fileURLToPath } from 'url'
7
8
  import { startBeat } from './beat.ts'
8
9
  import { childBeat, daemonPort, daemonUrl, homeDir, homePort, homeUp, pmUrl } from './home-paths.ts'
9
- import { reloadOnOwnCode } from './lib-watch.ts'
10
+ import { libGraph, reloadOnOwnCode } from './lib-watch.ts'
10
11
  import { serveWeb } from './serve-web.ts'
11
12
  import type { HomeIo } from './run-daemon.ts'
12
13
 
14
+ const PAGE_FILE = fileURLToPath(new URL('../serve/hub-app/home.html', import.meta.url))
15
+
13
16
  export async function runWeb(io: HomeIo, o: { port?: number } = {}): Promise<number> {
14
17
  const port = o.port ?? homePort()
15
18
  try {
16
- const web = serveWeb({ port, daemon: daemonUrl(daemonPort()), pm: pmUrl(), page: homePage })
19
+ const web = serveWeb({ port, daemon: daemonUrl(daemonPort()), pm: pmUrl(), page: homePage, pageFiles: () => libGraph(PAGE_FILE, { bundles: true }) })
17
20
  const beat = startBeat(childBeat(homeDir(), 'web'))
18
- const code = reloadOnOwnCode({ role: 'web', entry: fileURLToPath(import.meta.url), bundles: true, before: () => { beat(); web.stop() }, io })
21
+ const code = reloadOnOwnCode({ role: 'web', entry: fileURLToPath(import.meta.url), before: () => { beat(); web.stop() }, io })
19
22
  io.print(`home → http://localhost:${web.server.port} (the daemon: ${daemonUrl()}, pm: ${pmUrl()}), reloads on ${code.files} lib files`)
20
23
  for (const sig of ['SIGINT', 'SIGTERM'] as const)
21
24
  process.on(sig, () => {