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
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
//
|
|
7
7
|
// the one constraint a reader breaks first: it is in every session's context,
|
|
8
8
|
// so a contribution over its cap is cut here, and SK033 fails in its repo.
|
|
9
|
-
import {
|
|
9
|
+
import { createHash } from 'crypto'
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'fs'
|
|
10
11
|
import { homedir } from 'os'
|
|
11
12
|
import { dirname, join } from 'path'
|
|
12
13
|
import { CONTRIBUTION_FILE, CONTRIBUTION_MAX_BYTES, CONTRIBUTION_MAX_LINES, contributionBody, contributionOver, loadsContext } from '../core/global-contribution.ts'
|
|
13
14
|
import { KEYWORD_FILE } from '../core/layout.ts'
|
|
15
|
+
import { yieldLoop } from '../core/loop-watch.ts'
|
|
16
|
+
import { repoUnitFiles } from '../core/discover-checks.ts'
|
|
14
17
|
import { evaluateLeak, globalKeywordFile, maskPattern, parsePatterns } from '../hooks/leak-guard.ts'
|
|
15
18
|
import { homeRepo, houseRepos } from '../serve/project-gutter.ts'
|
|
16
19
|
import { scanGlobalUnits, type GlobalProcessDecl } from './global-units.ts'
|
|
@@ -131,6 +134,36 @@ export function houseLeak(houseRoot: string): Leak | null {
|
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
|
|
137
|
+
const stampOf = (f: string): string => {
|
|
138
|
+
try {
|
|
139
|
+
const st = statSync(f)
|
|
140
|
+
return `${st.mtimeMs}:${st.size}`
|
|
141
|
+
} catch {
|
|
142
|
+
return '-'
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** the outside of every source the file is made of, one repo at a time with the loop given back between two: the
|
|
147
|
+
* house index, the keyword lists, the file itself, and each repo's package.json, contribution and unit files. A stat
|
|
148
|
+
* each (the unit list is the walk the hubs keep), so the daemon looks every minute and starts the writer only when it
|
|
149
|
+
* moved. What a unit module imports is not in it: GLOBAL_CONTEXT_MAX_MS bounds that */
|
|
150
|
+
export async function contextSourcesStamp(root: string, home: string = homedir()): Promise<string | null> {
|
|
151
|
+
const h = houseRepos(homeRepo(root), home)
|
|
152
|
+
if (h.index == null) return null
|
|
153
|
+
const parts = [h.index, stampOf(h.index), stampOf(globalContextPath(h.index)), ...[globalKeywordFile(), join(h.home, KEYWORD_FILE)].map((f) => (f == null ? '-' : stampOf(f)))]
|
|
154
|
+
for (const r of h.repos) {
|
|
155
|
+
await yieldLoop()
|
|
156
|
+
parts.push(r.path, stampOf(join(r.path, 'package.json')), stampOf(join(r.path, CONTRIBUTION_FILE)))
|
|
157
|
+
for (const f of repoUnitFiles(r.path)) parts.push(f, stampOf(f))
|
|
158
|
+
}
|
|
159
|
+
return createHash('sha256').update(parts.join('\n')).digest('hex').slice(0, 16)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** the sources' stamp the last write was made from (machine db), and when */
|
|
163
|
+
export const GLOBAL_CONTEXT_DONE = 'global-context-done'
|
|
164
|
+
/** a write at least this often, whatever the stamp says: a unit module's own imports are not in it */
|
|
165
|
+
export const GLOBAL_CONTEXT_MAX_MS = 6 * 3600_000
|
|
166
|
+
|
|
134
167
|
/** THE computation, for the house the repo at `root` belongs to: where the
|
|
135
168
|
* file goes and what it holds. The cli and the daemon both call it. Null
|
|
136
169
|
* when `root` includes no house index, or one that does not load the file */
|
package/src/home/home-routes.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// decides WHEN a hub loads and never what is true: every verdict still comes
|
|
4
4
|
// from each repo's own runner and ledger. The machine resources are pm's
|
|
5
5
|
// (run-pm.ts), and the page reaches them through the web at /api/pm/*.
|
|
6
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
6
7
|
import { existsSync, readFileSync } from 'fs'
|
|
7
8
|
import { dirname, join } from 'path'
|
|
8
9
|
import { fileURLToPath } from 'url'
|
|
@@ -19,15 +20,18 @@ import type { Planner, PlanRow } from '../plan/planner.ts'
|
|
|
19
20
|
import type { Widgets, WidgetView } from './widgets.ts'
|
|
20
21
|
import { ActivityCache, repoActivity, windowMinutes } from './activity.ts'
|
|
21
22
|
import { devRepos, InsightsCache, type Scope } from './insights.ts'
|
|
22
|
-
import { GLOBAL_CONTEXT_EVERY_MS, houseContext, writeIfChanged } from './global-context.ts'
|
|
23
23
|
import { HouseRuns } from '../serve/house-runs.ts'
|
|
24
24
|
import { pushFleet } from '../fleet/push-fleet.ts'
|
|
25
25
|
import { appIconOf, appIconPngs, identityOfRoot } from '../core/app-icon.ts'
|
|
26
26
|
import { inboxResponse } from './inbox.ts'
|
|
27
|
+
import { veilleBatchRoute } from '../veille/batch.ts'
|
|
28
|
+
import { postTrackerRoute } from '../social/tracker-route.ts'
|
|
27
29
|
|
|
28
30
|
/** how far back a repo's git page lists its commits */
|
|
29
31
|
export const GIT_PAGE_MS = 7 * 24 * 3600_000
|
|
30
32
|
import type { HouseView } from '../ledger/house-runs.ts'
|
|
33
|
+
import { identitiesRoute } from '../identities/machine-route.ts'
|
|
34
|
+
import { siteRoutes } from '../site/routes.ts'
|
|
31
35
|
|
|
32
36
|
/** how often the daemon looks at every repo */
|
|
33
37
|
export const TICK_MS = 2_000
|
|
@@ -138,25 +142,18 @@ export function homeRoutes(d: HomeDeps) {
|
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
let active = new Set<string>()
|
|
141
|
-
let contextAt = -Infinity
|
|
142
145
|
if (d.plan != null) d.plan.active = (name) => active.has(name)
|
|
143
146
|
|
|
144
147
|
async function tick(): Promise<void> {
|
|
145
|
-
await refresh
|
|
148
|
+
await loopWatch.spanned('tick: projects', refresh)
|
|
146
149
|
active = activeSet(rows, d.state.data.active, rows.find((r) => r.path === d.root)?.name ?? d.name)
|
|
147
|
-
// the plan's clock: one look per tick, and it starts at most one batch
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (Date.now() - contextAt >= GLOBAL_CONTEXT_EVERY_MS) {
|
|
152
|
-
contextAt = Date.now()
|
|
153
|
-
void houseContext(d.root)
|
|
154
|
-
.then((c) => { if (c != null && writeIfChanged(c.path, c.text)) console.log(`ok: wrote ${c.path}`) })
|
|
155
|
-
.catch((e) => console.error(`WARN the global context could not be written: ${(e as Error).message}`))
|
|
156
|
-
}
|
|
150
|
+
// the plan's clock: one look per tick, and it starts at most one batch. The run records it looks at are read
|
|
151
|
+
// first, one repo at a time
|
|
152
|
+
await loopWatch.spanned('tick: plan records', () => d.plan?.refresh())
|
|
153
|
+
loopWatch.timed('tick: plan', () => d.plan?.tick())
|
|
157
154
|
// a widget render never holds the tick back
|
|
158
|
-
void d.widgets?.tick(repos.map((r) => ({ name: r.name, path: r.path }))).catch((e) => console.error(`WARN the widgets broke: ${(e as Error).message}`))
|
|
159
|
-
await d.hubs.tick(active)
|
|
155
|
+
void loopWatch.spanned('tick: widgets', () => d.widgets?.tick(repos.map((r) => ({ name: r.name, path: r.path })))).catch((e) => console.error(`WARN the widgets broke: ${(e as Error).message}`))
|
|
156
|
+
await loopWatch.spanned('tick: hubs', () => d.hubs.tick(active))
|
|
160
157
|
}
|
|
161
158
|
|
|
162
159
|
function answer(): HomeAnswer {
|
|
@@ -196,8 +193,18 @@ export function homeRoutes(d: HomeDeps) {
|
|
|
196
193
|
if (path === '/hub.json')
|
|
197
194
|
// the identity a client probes (homeUp), through the web or here
|
|
198
195
|
return Response.json({ hub: 'shipkit-home', name: d.name, root: d.root, version: LIB_VERSION, held: heldNow() == null ? null : heldText(heldNow()!) }, { headers: { 'access-control-allow-origin': '*' } })
|
|
196
|
+
// the Veille extension's batches, from an identity's Chrome profile: its own header guard (veille/batch.ts)
|
|
197
|
+
const batch = await veilleBatchRoute(req, path)
|
|
198
|
+
if (batch != null) return batch
|
|
199
|
+
// the post tracker's half of the same extension: its own header guard (social/tracker-route.ts)
|
|
200
|
+
const tracked = await postTrackerRoute(req, path)
|
|
201
|
+
if (tracked != null) return tracked
|
|
199
202
|
if (!sameOrigin(req)) return new Response('refused: a request that changes something must come from the home page', { status: 403 })
|
|
200
203
|
if (path.startsWith('/api/projects')) return d.gutter.handle(req, path)
|
|
204
|
+
// who speaks for each repo, and where its data lives (identities/machine-route.ts)
|
|
205
|
+
if (path.startsWith('/api/home/identities')) return identitiesRoute(req, path, d.root)
|
|
206
|
+
// each identity's website: its pages, its preview, what changed since its deploy (site/routes.ts)
|
|
207
|
+
if (path.startsWith('/api/home/sites/')) return siteRoutes(req, path, d.root)
|
|
201
208
|
// the activity page's push button: every house repo with unpushed commits, never a force (fleet/push-fleet.ts)
|
|
202
209
|
if (path === '/api/home/push-all' && req.method === 'POST') {
|
|
203
210
|
if (repos.length === 0) await refresh()
|
package/src/home/hubs.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// which each loaded hub joins. An edit of a repo config reloads that repo's
|
|
9
9
|
// hub alone, once its gate is done: the daemon runs with no bun watch, so one
|
|
10
10
|
// repo's edit never restarts the others (lib-watch.ts).
|
|
11
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
11
12
|
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'fs'
|
|
12
13
|
import { dirname, join } from 'path'
|
|
13
14
|
import type { WiredRepo } from '../serve/project-gutter.ts'
|
|
@@ -17,6 +18,9 @@ import { capLog, tailLines, type ProcStatus } from './supervise.ts'
|
|
|
17
18
|
import { hubBase, hubLog } from './home-paths.ts'
|
|
18
19
|
import { NOT_INSTALLED } from './home-words.ts'
|
|
19
20
|
|
|
21
|
+
/** the loop given back to the pages before each hub load of the queue */
|
|
22
|
+
export const LOAD_GAP_MS = 20
|
|
23
|
+
|
|
20
24
|
/** what the home needs of a loaded hub */
|
|
21
25
|
export type LoadedHub = Pick<HubRuntime, 'handler' | 'start' | 'stop' | 'ping' | 'busy'> & { uses: string[] }
|
|
22
26
|
|
|
@@ -120,6 +124,8 @@ export class Hubs {
|
|
|
120
124
|
if (e.loading != null) return e.loading
|
|
121
125
|
this.set(e, 'starting')
|
|
122
126
|
const run = this.queue.then(async () => {
|
|
127
|
+
// a load is a burst of sync work (a config import, a tree walk): the loop goes back to the pages between two
|
|
128
|
+
await new Promise((r) => setTimeout(r, LOAD_GAP_MS))
|
|
123
129
|
const blocked = hubBlocker(e.repo.path)
|
|
124
130
|
if (blocked != null) {
|
|
125
131
|
this.set(e, 'down', blocked)
|
|
@@ -127,16 +133,17 @@ export class Hubs {
|
|
|
127
133
|
}
|
|
128
134
|
const io = this.io(e)
|
|
129
135
|
try {
|
|
130
|
-
|
|
136
|
+
const prepare = this.o.prepare
|
|
137
|
+
if (prepare != null) await loopWatch.spanned(`hub prepare: ${e.repo.name}`, () => prepare(e.repo, io)).catch((err) => io.printErr(`WARN ${e.repo.name}: ${(err as Error).message}`))
|
|
131
138
|
e.stamp = configStamp(e.repo.path)
|
|
132
|
-
const rt = await this.o.load(e.repo, io, { fresh: fresh || e.loads > 0 })
|
|
139
|
+
const rt = await loopWatch.spanned(`hub load: ${e.repo.name}`, () => this.o.load(e.repo, io, { fresh: fresh || e.loads > 0 }))
|
|
133
140
|
// a stop by hand came while it loaded, and wins
|
|
134
141
|
if (e.held) {
|
|
135
142
|
rt.stop()
|
|
136
143
|
this.set(e, 'down', 'stopped by hand')
|
|
137
144
|
return
|
|
138
145
|
}
|
|
139
|
-
rt.start()
|
|
146
|
+
loopWatch.timed(`hub start: ${e.repo.name}`, () => rt.start())
|
|
140
147
|
e.rt = rt
|
|
141
148
|
e.loads++
|
|
142
149
|
this.set(e, 'up')
|
package/src/home/inbox-shape.ts
CHANGED
|
@@ -15,6 +15,14 @@ export type InboxKind = 'card' | 'question' | 'ask' | 'need' | 'raised'
|
|
|
15
15
|
export type InboxTone = 'review' | 'red' | 'yellow'
|
|
16
16
|
/** the main list (what waits on him) or the folded one (what can wait, what he can only read) */
|
|
17
17
|
export type InboxList = 'main' | 'yellow'
|
|
18
|
+
/** the review store's rows only (the default), or every row, the checks and asks included */
|
|
19
|
+
export type InboxShow = 'cards' | 'all'
|
|
20
|
+
/** what the rows group by: each one on or off on its own, nested in this order */
|
|
21
|
+
export const INBOX_GROUPS = ['repo', 'kind', 'lane'] as const
|
|
22
|
+
export type InboxGroup = (typeof INBOX_GROUPS)[number]
|
|
23
|
+
|
|
24
|
+
/** a row the review store gives: a card, a question, an item raised in it */
|
|
25
|
+
export const isCardKind = (k: InboxKind): boolean => k === 'card' || k === 'question' || k === 'raised'
|
|
18
26
|
|
|
19
27
|
export interface InboxRow {
|
|
20
28
|
/** `<repo>/<id>`, one per row of the whole inbox */
|
|
@@ -31,6 +39,8 @@ export interface InboxRow {
|
|
|
31
39
|
title: string
|
|
32
40
|
/** one more line: the lane and the versions, the need's sentence */
|
|
33
41
|
sub?: string
|
|
42
|
+
/** the lane the card belongs to; a need has none */
|
|
43
|
+
lane?: string
|
|
34
44
|
/** epoch ms of its newest move, null when nothing dates it */
|
|
35
45
|
at: number | null
|
|
36
46
|
/** the review preview thumb, on the home's origin */
|
|
@@ -55,7 +65,11 @@ export interface InboxAnswer {
|
|
|
55
65
|
total: number
|
|
56
66
|
offset: number
|
|
57
67
|
limit: number
|
|
68
|
+
/** the rows of each list the page shows */
|
|
58
69
|
counts: Record<InboxList, number>
|
|
70
|
+
/** the rows of each list with every kind: what « all » would show */
|
|
71
|
+
all: Record<InboxList, number>
|
|
72
|
+
show: InboxShow
|
|
59
73
|
/** per repo, the rows of each list: its own badges count the same */
|
|
60
74
|
repos: Record<string, Record<InboxList, number>>
|
|
61
75
|
/** a repo whose items are not here, and why (its hub is down, a read broke) */
|
|
@@ -98,6 +112,7 @@ function reviewRow(repo: string, r: ThreadRow, kind: InboxKind, tone: InboxTone)
|
|
|
98
112
|
tone,
|
|
99
113
|
title: r.title,
|
|
100
114
|
...(sub !== '' ? { sub } : {}),
|
|
115
|
+
...(r.lane ? { lane: r.lane } : {}),
|
|
101
116
|
at: Number.isFinite(at) ? at : null,
|
|
102
117
|
thumb: r.thumb != null && IMAGE.test(r.thumb) ? `${hubOf(repo)}/api/review/${r.head}/preview/thumb/${r.thumb}` : null,
|
|
103
118
|
open: inboxAddress(repo, r.head),
|
|
@@ -164,25 +179,59 @@ export function inboxRows<S extends InboxSource>(sources: readonly S[], dated: (
|
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
/** the query from a url's search: a value out of range is its default */
|
|
167
|
-
export function inboxQuery(p: URLSearchParams): { list: InboxList; offset: number; limit: number } {
|
|
182
|
+
export function inboxQuery(p: URLSearchParams): { list: InboxList; show: InboxShow; offset: number; limit: number } {
|
|
168
183
|
const n = (k: string, d: number, max: number): number => {
|
|
169
184
|
const v = Number(p.get(k) || NaN)
|
|
170
185
|
return Number.isInteger(v) && v >= 0 ? Math.min(v, max) : d
|
|
171
186
|
}
|
|
172
|
-
return { list: p.get('list') === 'yellow' ? 'yellow' : 'main', offset: n('offset', 0, Number.MAX_SAFE_INTEGER), limit: Math.max(1, n('limit', INBOX_PAGE, INBOX_MAX)) }
|
|
187
|
+
return { list: p.get('list') === 'yellow' ? 'yellow' : 'main', show: p.get('show') === 'all' ? 'all' : 'cards', offset: n('offset', 0, Number.MAX_SAFE_INTEGER), limit: Math.max(1, n('limit', INBOX_PAGE, INBOX_MAX)) }
|
|
173
188
|
}
|
|
174
189
|
|
|
175
190
|
/** one page of one list */
|
|
176
191
|
export function inboxPage(all: ReturnType<typeof inboxRows>, q: ReturnType<typeof inboxQuery>, missing: InboxAnswer['missing']): InboxAnswer {
|
|
177
|
-
|
|
192
|
+
// the kinds filter before the page cuts, so a card past the first page is never lost behind a check
|
|
193
|
+
const shown = (l: InboxList): InboxRow[] => (q.show === 'all' ? all[l] : all[l].filter((r) => isCardKind(r.kind)))
|
|
194
|
+
const rows = shown(q.list)
|
|
178
195
|
return {
|
|
179
196
|
list: q.list,
|
|
180
197
|
rows: rows.slice(q.offset, q.offset + q.limit),
|
|
181
198
|
total: rows.length,
|
|
182
199
|
offset: q.offset,
|
|
183
200
|
limit: q.limit,
|
|
184
|
-
counts: { main:
|
|
201
|
+
counts: { main: shown('main').length, yellow: shown('yellow').length },
|
|
202
|
+
all: { main: all.main.length, yellow: all.yellow.length },
|
|
203
|
+
show: q.show,
|
|
185
204
|
repos: all.repos,
|
|
186
205
|
missing,
|
|
187
206
|
}
|
|
188
207
|
}
|
|
208
|
+
|
|
209
|
+
const KIND_LABEL: Record<InboxKind, string> = { card: 'cards', question: 'questions', ask: 'asks', need: 'needs', raised: 'raised' }
|
|
210
|
+
|
|
211
|
+
/** a group of rows: its words, its rows' count, then its rows or its inner groups */
|
|
212
|
+
export type InboxGroupNode = { key: string; label: string; n: number; rows: InboxRow[]; groups: InboxGroupNode[] | null }
|
|
213
|
+
|
|
214
|
+
const groupOf = (r: InboxRow, by: InboxGroup): string => (by === 'repo' ? r.repo : by === 'kind' ? KIND_LABEL[r.kind] : r.lane ?? 'no lane')
|
|
215
|
+
|
|
216
|
+
/** the rows grouped by each axis that is on, nested repo then kind then lane; a group keeps its rows' order, and the
|
|
217
|
+
* groups come in the order their first row comes (newest first). No axis on: one group of every row */
|
|
218
|
+
export function groupRows(rows: readonly InboxRow[], on: readonly InboxGroup[], prefix = ''): InboxGroupNode[] {
|
|
219
|
+
const axes = INBOX_GROUPS.filter((g) => on.includes(g))
|
|
220
|
+
const [by, ...rest] = axes
|
|
221
|
+
if (by == null) return [{ key: prefix || 'all', label: '', n: rows.length, rows: [...rows], groups: null }]
|
|
222
|
+
const order: string[] = []
|
|
223
|
+
const of = new Map<string, InboxRow[]>()
|
|
224
|
+
for (const r of rows) {
|
|
225
|
+
const k = groupOf(r, by)
|
|
226
|
+
if (!of.has(k)) {
|
|
227
|
+
of.set(k, [])
|
|
228
|
+
order.push(k)
|
|
229
|
+
}
|
|
230
|
+
of.get(k)!.push(r)
|
|
231
|
+
}
|
|
232
|
+
return order.map((k) => {
|
|
233
|
+
const rs = of.get(k)!
|
|
234
|
+
const key = `${prefix}${by}:${k}/`
|
|
235
|
+
return { key, label: k, n: rs.length, rows: rs, groups: rest.length > 0 ? groupRows(rs, rest, key) : null }
|
|
236
|
+
})
|
|
237
|
+
}
|
package/src/home/inbox.ts
CHANGED
|
@@ -72,8 +72,23 @@ export const datedIn = (root: string): Dated => (n: Resource) => {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/** one read of every hub's rows is shared by every page that asks within this long */
|
|
76
|
+
export const INBOX_SHARE_MS = 1_000
|
|
77
|
+
const shared = new WeakMap<object, { end: number | null; read: ReturnType<typeof readSources> }>()
|
|
78
|
+
|
|
79
|
+
/** what every hub that is up holds; concurrent pages (windows, the phone) share one read while it runs and for
|
|
80
|
+
* INBOX_SHARE_MS after it ended */
|
|
81
|
+
export function inboxSources(hubs: Pick<Hubs, 'loaded'>, now: () => number = Date.now): ReturnType<typeof readSources> {
|
|
82
|
+
const held = shared.get(hubs)
|
|
83
|
+
if (held != null && (held.end == null || now() - held.end < INBOX_SHARE_MS)) return held.read
|
|
84
|
+
const entry: { end: number | null; read: ReturnType<typeof readSources> } = { end: null, read: readSources(hubs) }
|
|
85
|
+
shared.set(hubs, entry)
|
|
86
|
+
entry.read.then(() => { entry.end = now() }, () => { if (shared.get(hubs) === entry) shared.delete(hubs) })
|
|
87
|
+
return entry.read
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
/** what every hub that is up holds, read in parallel; a repo whose read broke is named, never dropped silently */
|
|
76
|
-
|
|
91
|
+
async function readSources(hubs: Pick<Hubs, 'loaded'>): Promise<{ sources: (InboxSource & { root: string })[]; missing: InboxAnswer['missing'] }> {
|
|
77
92
|
const missing: InboxAnswer['missing'] = []
|
|
78
93
|
const read = await Promise.all(
|
|
79
94
|
hubs.loaded().map(async ({ repo, rt }) => {
|
package/src/home/lib-watch.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { existsSync, readFileSync, realpathSync, statSync, watch, type FSWatcher
|
|
|
12
12
|
import { dirname, extname, join, relative, resolve } from 'path'
|
|
13
13
|
import { copyStamp, heldNow, homeLib, LAST_GOOD_ENV, lastGood, OWN_LIB, setHeld, takeLastGood } from '../core/last-good.ts'
|
|
14
14
|
import { LIB_VERSION } from '../core/lib-version.ts'
|
|
15
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
15
16
|
import { bootEntries, probeLoad, TreeProbe } from '../core/load-probe.ts'
|
|
16
17
|
import { reexecBlocker, reexecSelf } from '../core/reexec.ts'
|
|
17
18
|
import { StaleRestart } from '../serve/stale-restart.ts'
|
|
@@ -57,6 +58,10 @@ export function libGraph(entry: string, o: { bundles?: boolean } = {}): Set<stri
|
|
|
57
58
|
return out
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
/** a burst of saves is one change once no write came for this long: an agent saves file after file, and each
|
|
62
|
+
* restart rescans every house repo */
|
|
63
|
+
export const SETTLE_MS = 5_000
|
|
64
|
+
|
|
60
65
|
export class LibWatch {
|
|
61
66
|
private w: FSWatcher | null = null
|
|
62
67
|
private last: { file: string; at: number } | null = null
|
|
@@ -68,9 +73,9 @@ export class LibWatch {
|
|
|
68
73
|
private settleMs: number
|
|
69
74
|
|
|
70
75
|
/** `only`: absolute paths; an edit of any other file is not a change */
|
|
71
|
-
constructor(
|
|
76
|
+
constructor(root: string, o: { settleMs?: number; now?: () => number; only?: Set<string> } = {}) {
|
|
72
77
|
this.now = o.now ?? Date.now
|
|
73
|
-
this.settleMs = o.settleMs ??
|
|
78
|
+
this.settleMs = o.settleMs ?? SETTLE_MS
|
|
74
79
|
// an APFS clone of the tree (the last good copy, a scratch checkout)
|
|
75
80
|
// fires a change on every source file it reads: only a moved mtime,
|
|
76
81
|
// or a file gone, is a write
|
|
@@ -207,13 +212,15 @@ export function reloadOnOwnCode(o: {
|
|
|
207
212
|
const keeper = o.keep === true && !onCopy
|
|
208
213
|
? setInterval(() => {
|
|
209
214
|
if (lib.seq === kept || !lib.settled() || Date.now() - Math.max(lastGood(tree)?.at ?? 0, triedAt) < KEEP_EVERY_MS) return
|
|
215
|
+
const probed = loopWatch.span('load probe')
|
|
210
216
|
const v = probe.loads()
|
|
217
|
+
probed()
|
|
211
218
|
if (v === 'pending') return
|
|
212
219
|
if (v !== 'ok') return hold(v)
|
|
213
220
|
hold(null)
|
|
214
221
|
kept = lib.seq
|
|
215
222
|
triedAt = Date.now()
|
|
216
|
-
void takeLastGood(tree).catch((e: Error) => o.io.printErr(`WARN the last good copy of the shipkit source could not be kept: ${e.message}`))
|
|
223
|
+
void loopWatch.spanned('last good copy', () => takeLastGood(tree)).catch((e: Error) => o.io.printErr(`WARN the last good copy of the shipkit source could not be kept: ${e.message}`))
|
|
217
224
|
}, 2_000)
|
|
218
225
|
: null
|
|
219
226
|
function stop(): void {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// the machine's own stores and their caps (core/retention.ts owns the model):
|
|
2
2
|
// every log under the home dir, and the gui window's Chrome profile. And the
|
|
3
|
-
// daemon's
|
|
3
|
+
// daemon's retention job that sweeps every store, the repos' and these, in a
|
|
4
|
+
// child process (daemon-jobs.ts).
|
|
4
5
|
import { existsSync, lstatSync, readdirSync, rmSync, statSync } from 'fs'
|
|
5
6
|
import { join } from 'path'
|
|
6
7
|
import { repoStores, sweepStores, walkUse, type Store } from '../core/retention.ts'
|
|
7
8
|
import { capLog, LOG_MAX_BYTES } from './supervise.ts'
|
|
9
|
+
import { machineSet } from '../core/machine-db.ts'
|
|
8
10
|
|
|
9
11
|
/** a log nothing wrote for this long belongs to a process that is gone (a
|
|
10
12
|
* repo removed, a resource dropped) */
|
|
@@ -85,33 +87,17 @@ export function machineStores(dir: string): Store[] {
|
|
|
85
87
|
|
|
86
88
|
/** how often the daemon sweeps, after the one on boot */
|
|
87
89
|
export const SWEEP_EVERY_MS = 60 * 60 * 1000
|
|
88
|
-
/** the
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
let running = false
|
|
98
|
-
const once = async (): Promise<void> => {
|
|
99
|
-
if (running) return
|
|
100
|
-
running = true
|
|
101
|
-
try {
|
|
102
|
-
const now = (o.now ?? Date.now)()
|
|
103
|
-
for (const root of o.roots()) {
|
|
104
|
-
for (const r of await sweepStores(repoStores(root), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} in ${root} failed: ${r.error}`)
|
|
105
|
-
}
|
|
106
|
-
for (const r of await sweepStores(machineStores(o.dir), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} failed: ${r.error}`)
|
|
107
|
-
o.also?.(now)
|
|
108
|
-
} finally {
|
|
109
|
-
running = false
|
|
110
|
-
}
|
|
90
|
+
/** when the last sweep ended, in the machine db: the daemon's job sweeps once SWEEP_EVERY_MS passed, a restart
|
|
91
|
+
* included */
|
|
92
|
+
export const SWEPT_AT = 'retention-swept-at'
|
|
93
|
+
/** one sweep of the daemon's retention job, in its child process: every repo, then the machine, then `also`; its
|
|
94
|
+
* end time kept, so the daemon's next look waits SWEEP_EVERY_MS whatever restarts in between */
|
|
95
|
+
export async function sweepTick(o: { roots: string[]; dir: string; printErr: (l: string) => void; now?: () => number; also?: (now: number) => void }): Promise<void> {
|
|
96
|
+
const now = (o.now ?? Date.now)()
|
|
97
|
+
for (const root of o.roots) {
|
|
98
|
+
for (const r of await sweepStores(repoStores(root), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} in ${root} failed: ${r.error}`)
|
|
111
99
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
every.unref()
|
|
116
|
-
return { stop: () => { clearTimeout(boot); clearInterval(every) }, once }
|
|
100
|
+
for (const r of await sweepStores(machineStores(o.dir), now)) if (r.error != null) o.printErr(`WARN retention sweep of ${r.id} failed: ${r.error}`)
|
|
101
|
+
o.also?.(now)
|
|
102
|
+
machineSet(SWEPT_AT, (o.now ?? Date.now)())
|
|
117
103
|
}
|
package/src/home/run-daemon.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// it runs with no bun watch and an edit of its own code restarts it in place
|
|
7
7
|
// at once (lib-watch.ts): the new image follows the jobs still running. The
|
|
8
8
|
// machine resources are pm's.
|
|
9
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
10
|
+
import { MemoryWatch } from '../core/memory-watch.ts'
|
|
9
11
|
import { fileURLToPath } from 'url'
|
|
10
12
|
import { installOneLib } from '../core/one-lib.ts'
|
|
11
13
|
import { reclaimPreviousImage } from '../core/instance.ts'
|
|
@@ -16,17 +18,15 @@ import { projectGutter } from '../serve/project-gutter-route.ts'
|
|
|
16
18
|
import { loadRepoConfig } from '../repo-config.ts'
|
|
17
19
|
import { ensureIdentity } from '../core/identity.ts'
|
|
18
20
|
import { homedir } from 'os'
|
|
19
|
-
import {
|
|
21
|
+
import { join } from 'path'
|
|
22
|
+
import { childLog, daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
|
|
20
23
|
import { inboxAddress } from './inbox-shape.ts'
|
|
21
24
|
import { HomeState } from './home-state.ts'
|
|
22
25
|
import { Hubs } from './hubs.ts'
|
|
23
26
|
import { Planner } from '../plan/planner.ts'
|
|
24
27
|
import { machineCatchUp } from '../plan/catch-up.ts'
|
|
25
28
|
import { serveDaemon } from './serve-daemon.ts'
|
|
26
|
-
import {
|
|
27
|
-
import { startMediaStore } from '../media-store/daemon.ts'
|
|
28
|
-
import { mediaKinds } from '../media-kinds.ts'
|
|
29
|
-
import { landMotherhome } from '../core/motherhome.ts'
|
|
29
|
+
import { startJobs } from './daemon-jobs.ts'
|
|
30
30
|
import { Widgets } from './widgets.ts'
|
|
31
31
|
|
|
32
32
|
const CLI = fileURLToPath(new URL('../cli.ts', import.meta.url))
|
|
@@ -114,25 +114,22 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
|
|
|
114
114
|
publicHost,
|
|
115
115
|
})
|
|
116
116
|
io.print(`daemon → http://127.0.0.1:${home.server.port} (the page: http://localhost:${port})`)
|
|
117
|
-
// nothing grows unbound
|
|
118
|
-
// machine's
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const media = startMediaStore({ roots: () => house.repos.filter((r) => only == null || only.has(r.name)).map((r) => r.path), kinds: mediaKinds, print: io.print, printErr: io.printErr })
|
|
127
|
-
const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { sweeps.stop(); media.stop(); home.stop() }, keep: true, io })
|
|
117
|
+
// the retention sweep (nothing grows unbound, core/retention.ts), the media store and the backup of the
|
|
118
|
+
// machine-only state, each a niced child process: never a job's body on this loop (daemon-jobs.ts). A daemon
|
|
119
|
+
// limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none
|
|
120
|
+
const jobs = onlyRepos() == null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
|
|
121
|
+
// a job that holds the loop holds every page: each stall is said with the work that overlapped it
|
|
122
|
+
const stalls = loopWatch.start(io.printErr)
|
|
123
|
+
// its memory as a trend: a line only when it moved by a tenth, at most every 10 minutes
|
|
124
|
+
const memory = new MemoryWatch().start(io.print)
|
|
125
|
+
const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { stalls(); memory(); jobs?.stop(); home.stop() }, keep: true, io })
|
|
128
126
|
io.print(` ${house.repos.length} repos, state in ${dir}, reloads on ${code.files} lib files`)
|
|
129
127
|
for (const sig of ['SIGINT', 'SIGTERM'] as const)
|
|
130
128
|
process.on(sig, () => {
|
|
131
129
|
// the repo processes it started keep running: they are their
|
|
132
130
|
// own process groups, and the next daemon adopts them
|
|
133
131
|
code.stop()
|
|
134
|
-
|
|
135
|
-
media.stop()
|
|
132
|
+
jobs?.stop()
|
|
136
133
|
home.stop()
|
|
137
134
|
process.exit(0)
|
|
138
135
|
})
|
package/src/home/run-pm.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// It never loads the repo config itself (pm-config.ts), and it runs from this
|
|
6
6
|
// file, never from cli.ts (execPm): cli.ts loads every command, about 170 MB
|
|
7
7
|
// against pm's own 20.
|
|
8
|
+
import { stampConsole } from '../core/log-stamp.ts'
|
|
8
9
|
import { fileURLToPath } from 'url'
|
|
9
10
|
import { daemonPort, homeDir, homePort, homeUp, homeUrl, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
|
|
10
11
|
import { reloadOnOwnCode } from './lib-watch.ts'
|
|
@@ -171,5 +172,6 @@ export async function runPm(root: string, io: HomeIo, o: { port?: number } = {})
|
|
|
171
172
|
if (import.meta.main) {
|
|
172
173
|
const i = process.argv.indexOf('--port')
|
|
173
174
|
const port = i < 0 ? undefined : Number(process.argv[i + 1])
|
|
175
|
+
stampConsole()
|
|
174
176
|
process.exitCode = await runPm(process.cwd(), { print: (l) => console.log(l), printErr: (l) => console.error(l) }, { port })
|
|
175
177
|
}
|
package/src/home/serve-daemon.ts
CHANGED
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
// (serve-web.ts) serves the page and proxies here, so a browser only ever
|
|
4
4
|
// sees the web origin. A terminal client (via-hub.ts, attach.ts) talks here
|
|
5
5
|
// directly, so a gate never depends on the web.
|
|
6
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
6
7
|
import { homeRoutes, TICK_MS, type HomeDeps } from './home-routes.ts'
|
|
7
8
|
|
|
8
9
|
export function serveDaemon(d: HomeDeps & { daemonPort: number }) {
|
|
9
10
|
const routes = homeRoutes(d)
|
|
10
|
-
const fetch =
|
|
11
|
-
(await routes.handle(req, srv)) ?? new Response('not found', { status: 404 })
|
|
11
|
+
const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
|
|
12
|
+
loopWatch.spanned(`${req.method} ${new URL(req.url).pathname}`, async () => (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 }))
|
|
12
13
|
const server = Bun.serve({ port: d.daemonPort, hostname: '127.0.0.1', fetch })
|
|
13
14
|
let stopped = false
|
|
14
15
|
let running = false
|
|
15
16
|
const timer = setInterval(() => {
|
|
16
17
|
if (running || stopped) return
|
|
17
18
|
running = true
|
|
18
|
-
void routes.tick().catch((e) => console.error(`WARN the daemon tick broke: ${(e as Error).message}`)).finally(() => { running = false })
|
|
19
|
+
void loopWatch.spanned('daemon tick', () => routes.tick()).catch((e) => console.error(`WARN the daemon tick broke: ${(e as Error).message}`)).finally(() => { running = false })
|
|
19
20
|
}, TICK_MS)
|
|
20
21
|
void routes.tick().catch(() => {})
|
|
21
22
|
return {
|