rvlib-shipkit 2.12.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -21
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/assets/run-assets.ts +2 -2
- package/src/assets/server/studio-server.ts +27 -23
- package/src/check.ts +4 -4
- package/src/checks/SK001-package-json-shape.check.ts +8 -4
- package/src/checks/SK002-contracts-fulfillness.check.ts +2 -2
- package/src/checks/SK003-claude-md-shape.check.ts +20 -13
- package/src/checks/SK004-gitignore-policy.check.ts +45 -6
- package/src/checks/SK005-rvlib-versions.check.ts +2 -2
- package/src/checks/SK006-npm-publish-safety.check.ts +3 -3
- package/src/checks/SK007-github-visibility.check.ts +2 -2
- package/src/checks/SK008-reviewer-agent.check.ts +3 -3
- package/src/checks/SK010-undeclared-unit.check.ts +2 -2
- package/src/checks/SK011-sibling-unit-ranges.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +2 -2
- package/src/checks/SK013-one-way-in-policy.check.ts +2 -2
- package/src/checks/SK015-nested-repo.check.ts +3 -3
- package/src/checks/SK016-legacy-check-shapes.check.ts +2 -2
- package/src/checks/SK017-vscode-hub-task.check.ts +2 -2
- package/src/checks/SK018-test-files-run.check.ts +2 -2
- package/src/checks/SK019-tests-run-in-units.check.ts +2 -2
- package/src/checks/SK020-self-spawning-check.check.ts +2 -2
- package/src/checks/SK022-machine-runs-the-pin.check.ts +2 -2
- package/src/checks/SK024-identity-colors.check.ts +1 -1
- package/src/checks/SK025-release-drift.check.ts +2 -2
- package/src/checks/SK026-asks-autoclose.check.ts +2 -2
- package/src/checks/SK027-agent-wiki-links.check.ts +8 -2
- package/src/checks/SK028-readme.check.ts +2 -2
- package/src/checks/SK029-explicit-check-files.check.ts +3 -3
- package/src/checks/SK030-cache-audit.check.ts +7 -5
- package/src/checks/SK031-trace-audit.check.ts +7 -7
- package/src/checks/SK032-ignored-inputs.check.ts +3 -3
- package/src/checks/SK033-global-contribution.check.ts +11 -4
- package/src/checks/SK034-commit-gates-armed.check.ts +2 -2
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/checks/SK037-keyword-additions.check.ts +43 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Commands.ts +4 -4
- package/src/cli/cmd_ConfigKeys.ts +2 -2
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Init.ts +1 -1
- package/src/cli/cmd_Media.ts +10 -8
- package/src/cli/cmd_Mv.ts +14 -7
- package/src/cli/cmd_Review.ts +6 -4
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +5 -2
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Sound.ts +1 -1
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_TraceAudit.ts +6 -6
- package/src/cli/cmd_Trailer.ts +7 -4
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/cmd_When.ts +2 -2
- package/src/cli/family-pages.ts +19 -16
- 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 +12 -3
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +3 -2
- package/src/collections/tests.ts +19 -8
- package/src/comfy/comfy-panel.ts +2 -2
- 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/contracts/manifests/discord.contract.ts +1 -1
- package/src/contracts/manifests/identity.contract.ts +1 -1
- package/src/contracts/manifests/itch.contract.ts +1 -1
- package/src/contracts/manifests/steam.contract.ts +1 -1
- package/src/core/agent-dir-at.ts +12 -0
- package/src/core/agent-dir.ts +16 -0
- package/src/core/app-icon.ts +9 -3
- package/src/core/budget.ts +1 -1
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/canonical-scripts.ts +2 -2
- package/src/core/discover-checks.ts +38 -6
- 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/global-contribution.ts +4 -1
- package/src/core/ignored-block.ts +1 -1
- package/src/core/ignored-inputs.ts +3 -2
- 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/motherhome.ts +2 -2
- package/src/core/one-way-in-policy.ts +34 -26
- package/src/core/run-ci.ts +9 -11
- package/src/core/run-fixers.ts +9 -9
- package/src/core/runs-matrix.ts +1 -1
- package/src/core/slots.ts +30 -0
- package/src/core/trace-audit.ts +50 -9
- 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 +44 -8
- package/src/home/gui-app/ShipkitGui.swift +91 -2
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +54 -5
- package/src/home/inbox.ts +17 -2
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/pm-config.ts +4 -1
- package/src/home/pm-inputs.ts +2 -0
- package/src/home/resources.ts +7 -2
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +3 -1
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +29 -20
- package/src/hooks/hook-gates.ts +1 -1
- package/src/hooks/leak-guard.ts +69 -9
- package/src/hooks/run-hooks.ts +18 -22
- 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 +3 -3
- 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 +3 -2
- 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/content.ts +1 -1
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/db.ts +1 -1
- package/src/media-store/fact.ts +1 -1
- package/src/media-store/hand.ts +1 -1
- package/src/media-store/kind.ts +1 -1
- package/src/media-store/purge.ts +1 -1
- package/src/media-store/put.ts +5 -3
- package/src/media-store/remote.ts +1 -1
- package/src/media-store/space.ts +24 -5
- package/src/mv/mv-md.ts +63 -22
- 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 +319 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +7 -4
- package/src/repo-config.ts +71 -13
- package/src/review/anim.ts +1 -1
- package/src/review/auto.ts +1 -1
- package/src/review/cells.ts +15 -1
- package/src/review/format.ts +2 -2
- package/src/review/http.ts +16 -2
- package/src/review/marks.ts +1 -1
- package/src/review/media-kind.ts +1 -1
- package/src/review/media-read.ts +1 -1
- package/src/review/model.ts +27 -6
- package/src/review/notes.ts +125 -0
- package/src/review/previews.ts +1 -1
- package/src/review/project.ts +7 -39
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +18 -14
- package/src/review/store.ts +42 -2
- package/src/review/threads.ts +1 -1
- package/src/review/trailer-desk.ts +3 -3
- package/src/review/trailer-media.ts +8 -5
- package/src/review/trailer-model.ts +1 -1
- package/src/review/trailer-routes.ts +1 -1
- package/src/review/trailer-shots.ts +22 -5
- package/src/review/unit.ts +2 -2
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/files/tsconfig.json +1 -1
- package/src/scaffold/project-scaffold.ts +6 -5
- package/src/serve/embed.ts +2 -2
- package/src/serve/hub-app/check-words.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 +32 -8
- 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 +51 -7
- 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 +353 -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 +60 -7
- package/src/serve/hub-app/inbox-view.tsx +49 -7
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/kept-cols.tsx +30 -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-svc.ts +1 -1
- 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 +76 -20
- package/src/serve/hub-app/review/review-board.tsx +1 -1
- package/src/serve/hub-app/review/review-cells.tsx +6 -5
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +6 -5
- package/src/serve/hub-app/review/review-st.ts +34 -15
- package/src/serve/hub-app/review/review-thread.tsx +63 -14
- package/src/serve/hub-app/review/review-views.tsx +133 -51
- package/src/serve/hub-app/review/thread-st.ts +80 -37
- package/src/serve/hub-app/review/trailer-page.tsx +7 -5
- package/src/serve/hub-app/review/trailer-st.ts +1 -1
- package/src/serve/hub-app/review.css +26 -9
- 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 +330 -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 +681 -0
- package/src/serve/hub-app/social/social-st.ts +1014 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +312 -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 +515 -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 +20 -11
- 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 +160 -0
- package/src/shot/browser-slot.ts +74 -0
- package/src/shot/client.ts +42 -7
- package/src/shot/clip-encoder.ts +108 -24
- package/src/shot/film-box.ts +292 -0
- package/src/shot/shooter.ts +71 -17
- 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/card-drafts.ts +24 -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 +332 -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 +37 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +186 -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 +95 -35
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trace/tracer.ts +12 -5
- package/src/trailer/adapter.ts +5 -1
- package/src/trailer/build.ts +45 -12
- 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/holes.ts +1 -1
- package/src/trailer/passage.ts +18 -6
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/prune.ts +1 -1
- package/src/trailer/states.ts +1 -1
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/trailer/words.ts +1 -1
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/run-tui.ts +1 -1
- package/src/tui/tui-app.tsx +0 -1
- package/src/tui/tui-store.ts +1 -1
- package/src/veille/asks.ts +155 -0
- package/src/veille/auto.ts +31 -0
- package/src/veille/batch.ts +27 -0
- package/src/veille/chrome.ts +127 -0
- package/src/veille/collection.ts +28 -0
- package/src/veille/desk.ts +242 -0
- package/src/veille/identity.ts +80 -0
- package/src/veille/import.ts +68 -0
- package/src/veille/log.ts +183 -0
- package/src/veille/platforms.ts +118 -0
- package/src/veille/reads.ts +66 -0
- package/src/veille/replied.ts +110 -0
- package/src/veille/routes.ts +185 -0
- package/src/veille/service.ts +81 -0
- package/src/veille/watch.ts +116 -0
- package/src/veille/worth.ts +46 -0
- package/src/wiki/scan-md.ts +18 -0
- package/src/collections/posts.ts +0 -142
- package/src/contracts/manifests/social.contract.ts +0 -20
- package/src/scaffold/files/agent-coding.md +0 -35
- package/src/ts/typecheck-cache.ts +0 -11
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// THE DAEMON'S BACKGROUND JOBS, OFF ITS LOOP (wiki tools/shipkit/home.md, Nothing heavy on the daemon's loop): the
|
|
2
|
+
// backup, the retention sweep, the media store and the house's global context each run as a child process (`sk daemon job <id>`, niced), started
|
|
3
|
+
// detached with its pid in a file, its lines appended to the daemon's log. The daemon only starts it and reads the
|
|
4
|
+
// pid: an in place restart adopts a child still running and never starts a second one. What a job remembers between
|
|
5
|
+
// two runs lives in the machine db, so a restart never redoes a job's work.
|
|
6
|
+
//
|
|
7
|
+
// the one constraint a reader breaks first: a job's body never runs in the daemon's process. The daemon's loop answers
|
|
8
|
+
// every page; a sync walk, a VACUUM or a hash pass there holds every page with it (tests/daemon-jobs.test.ts)
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'
|
|
10
|
+
import { join } from 'node:path'
|
|
11
|
+
import { machineGet } from '../core/machine-db.ts'
|
|
12
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
13
|
+
import { BACKUP_EVERY_MS } from '../media-store/backup/daemon.ts'
|
|
14
|
+
import { MEDIA_EVERY_MS } from '../media-store/daemon.ts'
|
|
15
|
+
import { SWEEP_EVERY_MS, SWEPT_AT } from './machine-stores.ts'
|
|
16
|
+
import { contextSourcesStamp, GLOBAL_CONTEXT_DONE, GLOBAL_CONTEXT_EVERY_MS, GLOBAL_CONTEXT_MAX_MS } from './global-context.ts'
|
|
17
|
+
|
|
18
|
+
export type JobId = 'backup' | 'retention sweep' | 'media store' | 'global context'
|
|
19
|
+
|
|
20
|
+
export interface DaemonJob {
|
|
21
|
+
id: JobId
|
|
22
|
+
/** the daemon looks this often: a look starts the child unless one runs or `due` says no */
|
|
23
|
+
everyMs: number
|
|
24
|
+
/** the first look after a boot: the repos load first */
|
|
25
|
+
firstMs: number
|
|
26
|
+
/** a cheap read in the daemon (a stat, never a walk; async when it gives the loop back between two): false skips
|
|
27
|
+
* the child for this look. `root` is the house repo the children run in */
|
|
28
|
+
due?: (now: number, root: string) => boolean | Promise<boolean>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** a child gets this long; past it, it is killed and said */
|
|
32
|
+
export const JOB_MAX_MS = 60 * 60_000
|
|
33
|
+
/** the niceness of every job child: the pages and the agents' tools go first */
|
|
34
|
+
export const JOB_NICE = 15
|
|
35
|
+
|
|
36
|
+
export const DAEMON_JOBS: readonly DaemonJob[] = [
|
|
37
|
+
{ id: 'media store', everyMs: MEDIA_EVERY_MS, firstMs: 15_000 },
|
|
38
|
+
{ id: 'retention sweep', everyMs: 5 * 60_000, firstMs: 10_000, due: (now) => now - (machineGet<number>(SWEPT_AT) ?? 0) >= SWEEP_EVERY_MS },
|
|
39
|
+
{ id: 'backup', everyMs: BACKUP_EVERY_MS, firstMs: BACKUP_EVERY_MS },
|
|
40
|
+
// the house's generated context: its unit files are imported to be read, a second of compile the loop never pays
|
|
41
|
+
{ id: 'global context', everyMs: GLOBAL_CONTEXT_EVERY_MS, firstMs: 30_000, due: async (now, root) => contextDue(now, await contextSourcesStamp(root)) },
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
/** the context is due when its sources' stamp moved since the last write, or that write is old */
|
|
45
|
+
export function contextDue(now: number, stamp: string | null): boolean {
|
|
46
|
+
if (stamp == null) return false
|
|
47
|
+
const done = machineGet<{ stamp: string; at: number }>(GLOBAL_CONTEXT_DONE)
|
|
48
|
+
return done == null || done.stamp !== stamp || now - done.at >= GLOBAL_CONTEXT_MAX_MS
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const isJobId = (s: string): s is JobId => DAEMON_JOBS.some((j) => j.id === s)
|
|
52
|
+
|
|
53
|
+
/** the file name of a job: `retention sweep` → `retention-sweep` */
|
|
54
|
+
const slug = (id: JobId): string => id.replace(/\s+/g, '-')
|
|
55
|
+
|
|
56
|
+
// a subshell runs the niced child and writes its exit code: the pid echoed is the subshell's, alive while the job runs
|
|
57
|
+
const LAUNCH = 'set -m; ( nice -n "$2" "${@:4}"; echo $? >"$3" ) >>"$1" 2>&1 </dev/null & echo $!'
|
|
58
|
+
|
|
59
|
+
export interface JobsDeps {
|
|
60
|
+
/** the cli the child runs (`src/cli.ts`) */
|
|
61
|
+
cli: string
|
|
62
|
+
/** where the child runs: the house repo */
|
|
63
|
+
cwd: string
|
|
64
|
+
/** pid and exit files */
|
|
65
|
+
dir: string
|
|
66
|
+
/** the daemon's log: the child appends its own stamped lines */
|
|
67
|
+
log: string
|
|
68
|
+
printErr: (l: string) => void
|
|
69
|
+
env?: Record<string, string>
|
|
70
|
+
now?: () => number
|
|
71
|
+
alive?: (pid: number) => boolean
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const aliveReal = (pid: number): boolean => {
|
|
75
|
+
try {
|
|
76
|
+
process.kill(pid, 0)
|
|
77
|
+
return true
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return (e as { code?: string }).code === 'EPERM'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface Jobs {
|
|
84
|
+
stop(): void
|
|
85
|
+
/** one look at a job now: starts its child when none runs and it is due; resolves once that child is gone */
|
|
86
|
+
run(id: JobId, o?: { force?: boolean }): Promise<number | null>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function startJobs(d: JobsDeps, jobs: readonly DaemonJob[] = DAEMON_JOBS, o: { timers?: boolean } = {}): Jobs {
|
|
90
|
+
const now = d.now ?? Date.now
|
|
91
|
+
const alive = d.alive ?? aliveReal
|
|
92
|
+
mkdirSync(d.dir, { recursive: true })
|
|
93
|
+
const pidFile = (id: JobId): string => join(d.dir, `${slug(id)}.pid`)
|
|
94
|
+
const exitFile = (id: JobId): string => join(d.dir, `${slug(id)}.exit`)
|
|
95
|
+
const startedAt = new Map<JobId, number>()
|
|
96
|
+
|
|
97
|
+
/** the pid of the job's child that still runs, else null; a finished child's failure said once */
|
|
98
|
+
const running = (id: JobId): number | null => {
|
|
99
|
+
const f = pidFile(id)
|
|
100
|
+
if (!existsSync(f)) return null
|
|
101
|
+
const pid = Number(readFileSync(f, 'utf8').trim())
|
|
102
|
+
if (pid > 0 && alive(pid)) {
|
|
103
|
+
const at = startedAt.get(id)
|
|
104
|
+
if (at != null && now() - at > JOB_MAX_MS) {
|
|
105
|
+
try { process.kill(-pid, 'SIGKILL') } catch { try { process.kill(pid, 'SIGKILL') } catch { /* gone */ } }
|
|
106
|
+
d.printErr(`WARN daemon job ${id}: still running after ${JOB_MAX_MS / 60_000} min, killed`)
|
|
107
|
+
} else return pid
|
|
108
|
+
}
|
|
109
|
+
rmSync(f, { force: true })
|
|
110
|
+
const code = existsSync(exitFile(id)) ? Number(readFileSync(exitFile(id), 'utf8').trim()) : null
|
|
111
|
+
rmSync(exitFile(id), { force: true })
|
|
112
|
+
if (code != null && code !== 0) d.printErr(`WARN daemon job ${id}: its child exited ${code}, its lines above say why`)
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const launch = async (job: DaemonJob): Promise<number | null> => {
|
|
117
|
+
const end = loopWatch.span(`${job.id} (start)`)
|
|
118
|
+
try {
|
|
119
|
+
const cmd = [process.execPath, d.cli, 'daemon', 'job', job.id]
|
|
120
|
+
const p = Bun.spawn(['/bin/bash', '-c', LAUNCH, 'launch', d.log, String(JOB_NICE), exitFile(job.id), ...cmd], { cwd: d.cwd, env: { ...process.env, ...d.env }, stdout: 'pipe', stderr: 'pipe' })
|
|
121
|
+
const [out, err] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text()])
|
|
122
|
+
const pid = Number(out.trim())
|
|
123
|
+
if ((await p.exited) !== 0 || !Number.isInteger(pid) || pid <= 0) {
|
|
124
|
+
d.printErr(`WARN daemon job ${job.id}: the launch shell failed: ${err.trim()}`)
|
|
125
|
+
return null
|
|
126
|
+
}
|
|
127
|
+
await Bun.write(pidFile(job.id), String(pid))
|
|
128
|
+
startedAt.set(job.id, now())
|
|
129
|
+
return pid
|
|
130
|
+
} finally {
|
|
131
|
+
end()
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const look = async (job: DaemonJob, force: boolean): Promise<number | null> => {
|
|
136
|
+
if (running(job.id) != null) return null
|
|
137
|
+
const due = job.due
|
|
138
|
+
if (!force && due != null && !(await loopWatch.spanned(`${job.id} (due)`, () => due(now(), d.cwd)))) return null
|
|
139
|
+
return launch(job)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const timers: ReturnType<typeof setTimeout>[] = []
|
|
143
|
+
if (o.timers !== false)
|
|
144
|
+
for (const job of jobs) {
|
|
145
|
+
const tick = (): void => void look(job, false).catch((e) => d.printErr(`WARN daemon job ${job.id}: ${(e as Error).message}`))
|
|
146
|
+
const first = setTimeout(() => {
|
|
147
|
+
tick()
|
|
148
|
+
const every = setInterval(tick, job.everyMs)
|
|
149
|
+
every.unref()
|
|
150
|
+
timers.push(every)
|
|
151
|
+
}, job.firstMs)
|
|
152
|
+
first.unref()
|
|
153
|
+
timers.push(first)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
stop: () => {
|
|
158
|
+
for (const t of timers) clearTimeout(t)
|
|
159
|
+
},
|
|
160
|
+
async run(id, ro = {}) {
|
|
161
|
+
const job = jobs.find((j) => j.id === id)
|
|
162
|
+
if (job == null) throw new Error(`no daemon job ${id}`)
|
|
163
|
+
const pid = await look(job, ro.force === true)
|
|
164
|
+
if (pid == null) return null
|
|
165
|
+
while (running(id) != null) await Bun.sleep(50)
|
|
166
|
+
return pid
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** what a job does, in the child: `sk daemon job <id>` runs it. Each body imports its modules here, never at the top */
|
|
172
|
+
export async function runJobBody(id: JobId, o: { root: string; home: string; print: (l: string) => void; printErr: (l: string) => void }): Promise<void> {
|
|
173
|
+
const { houseRepos } = await import('../serve/project-gutter.ts')
|
|
174
|
+
const house = houseRepos(o.root, o.home)
|
|
175
|
+
if (house.index == null) throw new Error(`${o.root} includes no house wiki index: no repos to work on`)
|
|
176
|
+
const repos = house.repos.map((r) => r.path)
|
|
177
|
+
if (id === 'backup') {
|
|
178
|
+
const { backupTick } = await import('../media-store/backup/daemon.ts')
|
|
179
|
+
const { machineSpace } = await import('../media-store/space.ts')
|
|
180
|
+
return backupTick({ home: o.home, repos: [...repos, ...house.archived.map((r) => r.path)], space: machineSpace, print: o.print, printErr: o.printErr })
|
|
181
|
+
}
|
|
182
|
+
if (id === 'media store') {
|
|
183
|
+
const { mediaTick } = await import('../media-store/daemon.ts')
|
|
184
|
+
const { mediaKinds } = await import('../media-kinds.ts')
|
|
185
|
+
return mediaTick({ roots: repos, kinds: mediaKinds, print: o.print, printErr: o.printErr })
|
|
186
|
+
}
|
|
187
|
+
if (id === 'global context') {
|
|
188
|
+
const { contextSourcesStamp, houseContext, writeIfChanged } = await import('./global-context.ts')
|
|
189
|
+
const { machineSet } = await import('../core/machine-db.ts')
|
|
190
|
+
// the stamp before the read: a source that moves during it moves the stamp again, and the next look writes
|
|
191
|
+
const stamp = await contextSourcesStamp(o.root, o.home)
|
|
192
|
+
const c = await houseContext(o.root, o.home)
|
|
193
|
+
if (c != null && writeIfChanged(c.path, c.text)) o.print(`ok: wrote ${c.path}`)
|
|
194
|
+
machineSet(GLOBAL_CONTEXT_DONE, { stamp, at: Date.now() })
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
const { sweepTick } = await import('./machine-stores.ts')
|
|
198
|
+
const { homeDir } = await import('./home-paths.ts')
|
|
199
|
+
const { landMotherhome } = await import('../core/motherhome.ts')
|
|
200
|
+
return sweepTick({ roots: repos, dir: homeDir(), printErr: o.printErr, also: (now) => { for (const n of landMotherhome({ now })) o.printErr(n) } })
|
|
201
|
+
}
|
|
@@ -6,19 +6,24 @@
|
|
|
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'
|
|
13
|
+
import { contributionFileAt } from '../core/agent-dir-at.ts'
|
|
12
14
|
import { CONTRIBUTION_FILE, CONTRIBUTION_MAX_BYTES, CONTRIBUTION_MAX_LINES, contributionBody, contributionOver, loadsContext } from '../core/global-contribution.ts'
|
|
13
15
|
import { KEYWORD_FILE } from '../core/layout.ts'
|
|
14
|
-
import {
|
|
16
|
+
import { yieldLoop } from '../core/loop-watch.ts'
|
|
17
|
+
import { repoUnitFiles } from '../core/discover-checks.ts'
|
|
18
|
+
import { evaluateLeak, globalKeywordFile, maskPattern, parsePatterns, withBuiltinRows } from '../hooks/leak-guard.ts'
|
|
15
19
|
import { homeRepo, houseRepos } from '../serve/project-gutter.ts'
|
|
16
20
|
import { scanGlobalUnits, type GlobalProcessDecl } from './global-units.ts'
|
|
17
21
|
|
|
18
22
|
/** how often the daemon looks whether a source moved */
|
|
19
23
|
export const GLOBAL_CONTEXT_EVERY_MS = 60_000
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
/** `file`: the contribution file, repo relative, in the agent folder its CLAUDE.md names */
|
|
26
|
+
export type ContextRepo = { name: string; path: string; description: string | null; contribution: string; file: string }
|
|
22
27
|
export type ContextProcess = Pick<GlobalProcessDecl, 'id' | 'label' | 'repo' | 'url' | 'description'>
|
|
23
28
|
|
|
24
29
|
/** the banned keyword a text matches, masked, or null: every item is
|
|
@@ -38,7 +43,7 @@ function capped(r: ContextRepo, body: string): string {
|
|
|
38
43
|
// a heading above #### would outrank the `### <repo>` it sits under
|
|
39
44
|
let cut = body.replace(/^#{1,3}(?=\s)/gm, '####').split('\n').slice(0, CONTRIBUTION_MAX_LINES).join('\n')
|
|
40
45
|
while (Buffer.byteLength(cut) > CONTRIBUTION_MAX_BYTES) cut = cut.slice(0, cut.lastIndexOf('\n'))
|
|
41
|
-
return `${cut}\n\n(cut: ${r.name}/${
|
|
46
|
+
return `${cut}\n\n(cut: ${r.name}/${r.file} is ${over}, and SK033 fails there until it fits)`
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
/** a description's first line, at most DESCRIPTION_MAX characters */
|
|
@@ -91,7 +96,7 @@ export function globalContextText(o: { repos: ContextRepo[]; processes: ContextP
|
|
|
91
96
|
}
|
|
92
97
|
const given = o.repos
|
|
93
98
|
.map((r) => ({ r, body: contributionBody(r.contribution) }))
|
|
94
|
-
.filter((x) => x.body !== '' && clean(`${x.r.name}/${
|
|
99
|
+
.filter((x) => x.body !== '' && clean(`${x.r.name}/${x.r.file}`, x.body) != null)
|
|
95
100
|
out.push('', '## What each repo offers', '')
|
|
96
101
|
if (given.length === 0) out.push(`No repo contributes yet: each writes its own \`${CONTRIBUTION_FILE}\`.`)
|
|
97
102
|
for (const { r, body } of given) out.push(`### ${r.name}`, '', capped(r, body), '')
|
|
@@ -107,8 +112,9 @@ export function contextRepo(r: { name: string; path: string }, home: string = ho
|
|
|
107
112
|
const d = (JSON.parse(readFileSync(join(r.path, 'package.json'), 'utf8')) as { description?: unknown }).description
|
|
108
113
|
if (typeof d === 'string' && d.trim() !== '') description = d.trim()
|
|
109
114
|
} catch { /* no package.json, or one that does not parse: no line */ }
|
|
110
|
-
const
|
|
111
|
-
|
|
115
|
+
const file = contributionFileAt(r.path)
|
|
116
|
+
const f = join(r.path, file)
|
|
117
|
+
return { name: r.name, path: r.path.startsWith(`${home}/`) ? `~${r.path.slice(home.length)}` : r.path, description, contribution: existsSync(f) ? readFileSync(f, 'utf8') : '', file }
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
/** writes the text when it differs from what the file holds; true when it wrote */
|
|
@@ -124,13 +130,43 @@ export function writeIfChanged(path: string, text: string): boolean {
|
|
|
124
130
|
export function houseLeak(houseRoot: string): Leak | null {
|
|
125
131
|
const files = [globalKeywordFile(), join(houseRoot, KEYWORD_FILE)].filter((f): f is string => f != null && existsSync(f))
|
|
126
132
|
if (files.length === 0) return null
|
|
127
|
-
const patterns = parsePatterns(files.map((f) => readFileSync(f, 'utf8'))
|
|
133
|
+
const patterns = parsePatterns(withBuiltinRows(files.map((f) => readFileSync(f, 'utf8'))))
|
|
128
134
|
return (text) => {
|
|
129
135
|
const hit = evaluateLeak([{ where: 'global context', content: text }], patterns, []).hits[0]
|
|
130
136
|
return hit == null ? null : maskPattern(hit.pattern)
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
|
|
140
|
+
const stampOf = (f: string): string => {
|
|
141
|
+
try {
|
|
142
|
+
const st = statSync(f)
|
|
143
|
+
return `${st.mtimeMs}:${st.size}`
|
|
144
|
+
} catch {
|
|
145
|
+
return '-'
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** the outside of every source the file is made of, one repo at a time with the loop given back between two: the
|
|
150
|
+
* house index, the keyword lists, the file itself, and each repo's package.json, contribution and unit files. A stat
|
|
151
|
+
* each (the unit list is the walk the hubs keep), so the daemon looks every minute and starts the writer only when it
|
|
152
|
+
* moved. What a unit module imports is not in it: GLOBAL_CONTEXT_MAX_MS bounds that */
|
|
153
|
+
export async function contextSourcesStamp(root: string, home: string = homedir()): Promise<string | null> {
|
|
154
|
+
const h = houseRepos(homeRepo(root), home)
|
|
155
|
+
if (h.index == null) return null
|
|
156
|
+
const parts = [h.index, stampOf(h.index), stampOf(globalContextPath(h.index)), ...[globalKeywordFile(), join(h.home, KEYWORD_FILE)].map((f) => (f == null ? '-' : stampOf(f)))]
|
|
157
|
+
for (const r of h.repos) {
|
|
158
|
+
await yieldLoop()
|
|
159
|
+
parts.push(r.path, stampOf(join(r.path, 'package.json')), stampOf(join(r.path, contributionFileAt(r.path))), stampOf(join(r.path, 'CLAUDE.md')))
|
|
160
|
+
for (const f of repoUnitFiles(r.path)) parts.push(f, stampOf(f))
|
|
161
|
+
}
|
|
162
|
+
return createHash('sha256').update(parts.join('\n')).digest('hex').slice(0, 16)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** the sources' stamp the last write was made from (machine db), and when */
|
|
166
|
+
export const GLOBAL_CONTEXT_DONE = 'global-context-done'
|
|
167
|
+
/** a write at least this often, whatever the stamp says: a unit module's own imports are not in it */
|
|
168
|
+
export const GLOBAL_CONTEXT_MAX_MS = 6 * 3600_000
|
|
169
|
+
|
|
134
170
|
/** THE computation, for the house the repo at `root` belongs to: where the
|
|
135
171
|
* file goes and what it holds. The cli and the daemon both call it. Null
|
|
136
172
|
* when `root` includes no house index, or one that does not load the file */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// project): the bundle's Info.plist names the app (CFBundleName) and the url
|
|
5
5
|
// a bare launch opens (ShipkitStartURL). One WKWebView per window; every
|
|
6
6
|
// `open -a <app> <url>` opens one more window, cmd-n too. A link to another
|
|
7
|
-
// site opens in the default browser.
|
|
7
|
+
// site opens in the default browser, and a download lands in ~/Downloads.
|
|
8
8
|
import AppKit
|
|
9
9
|
import WebKit
|
|
10
10
|
|
|
@@ -124,13 +124,14 @@ final class Pane: NSView, NSSearchFieldDelegate {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, NSWindowDelegate, NSMenuItemValidation {
|
|
127
|
+
final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, WKDownloadDelegate, NSWindowDelegate, NSMenuItemValidation {
|
|
128
128
|
var windows: [NSWindow] = []
|
|
129
129
|
var opened = false
|
|
130
130
|
|
|
131
131
|
func applicationDidFinishLaunching(_ note: Notification) {
|
|
132
132
|
if CommandLine.arguments.contains("--self-test-find") { return selfTestFind() }
|
|
133
133
|
if CommandLine.arguments.contains("--self-test-panels") { return selfTestPanels() }
|
|
134
|
+
if CommandLine.arguments.contains("--self-test-download") { return selfTestDownload() }
|
|
134
135
|
buildMenu()
|
|
135
136
|
// esc closes the find bar of the key window, and reaches the page otherwise
|
|
136
137
|
NSEvent.addLocalMonitorForEvents(matching: .keyDown) { e in
|
|
@@ -335,12 +336,100 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
335
336
|
|
|
336
337
|
// the app's own host: stay in the window; anything else: the default browser
|
|
337
338
|
func webView(_ web: WKWebView, decidePolicyFor action: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
|
339
|
+
// a link marked download saves the file, as a browser does, instead of showing it in the window
|
|
340
|
+
if action.shouldPerformDownload { return decisionHandler(.download) }
|
|
338
341
|
guard let url = action.request.url, action.navigationType == .linkActivated else { return decisionHandler(.allow) }
|
|
339
342
|
if stays(url) { return decisionHandler(.allow) }
|
|
340
343
|
NSWorkspace.shared.open(url)
|
|
341
344
|
decisionHandler(.cancel)
|
|
342
345
|
}
|
|
343
346
|
|
|
347
|
+
// a response the window cannot show (an archive, an attachment) is saved too
|
|
348
|
+
func webView(_ web: WKWebView, decidePolicyFor response: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
|
|
349
|
+
let attachment = ((response.response as? HTTPURLResponse)?.value(forHTTPHeaderField: "Content-Disposition") ?? "").lowercased().hasPrefix("attachment")
|
|
350
|
+
decisionHandler(attachment || !response.canShowMIMEType ? .download : .allow)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
func webView(_ web: WKWebView, navigationAction: WKNavigationAction, didBecome download: WKDownload) { download.delegate = self }
|
|
354
|
+
func webView(_ web: WKWebView, navigationResponse: WKNavigationResponse, didBecome download: WKDownload) { download.delegate = self }
|
|
355
|
+
|
|
356
|
+
/** where a download lands: the user's Downloads folder (SHIPKIT_GUI_DOWNLOADS for the self test) */
|
|
357
|
+
func downloadsDir() -> URL {
|
|
358
|
+
if let dir = ProcessInfo.processInfo.environment["SHIPKIT_GUI_DOWNLOADS"], !dir.isEmpty { return URL(fileURLWithPath: dir) }
|
|
359
|
+
return FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first ?? URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Downloads")
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** `name.ext`, else `name (2).ext`, `name (3).ext`: a download never overwrites a file */
|
|
363
|
+
func freeName(_ dir: URL, _ suggested: String) -> URL {
|
|
364
|
+
let name = suggested.isEmpty ? "download" : suggested
|
|
365
|
+
let base = (name as NSString).deletingPathExtension, ext = (name as NSString).pathExtension
|
|
366
|
+
var url = dir.appendingPathComponent(name)
|
|
367
|
+
var n = 2
|
|
368
|
+
while FileManager.default.fileExists(atPath: url.path) {
|
|
369
|
+
url = dir.appendingPathComponent(ext.isEmpty ? "\(base) (\(n))" : "\(base) (\(n)).\(ext)")
|
|
370
|
+
n += 1
|
|
371
|
+
}
|
|
372
|
+
return url
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
var downloads: [ObjectIdentifier: URL] = [:]
|
|
376
|
+
/** hears every finished download: the self test reads it */
|
|
377
|
+
var onDownloaded: ((URL?) -> Void)?
|
|
378
|
+
|
|
379
|
+
func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String, completionHandler: @escaping (URL?) -> Void) {
|
|
380
|
+
let dest = freeName(downloadsDir(), suggestedFilename)
|
|
381
|
+
downloads[ObjectIdentifier(download)] = dest
|
|
382
|
+
completionHandler(dest)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// the Downloads stack in the dock bounces on the file, as it does for a browser's download
|
|
386
|
+
func downloadDidFinish(_ download: WKDownload) {
|
|
387
|
+
let dest = downloads.removeValue(forKey: ObjectIdentifier(download))
|
|
388
|
+
if let dest { DistributedNotificationCenter.default().post(name: Notification.Name("com.apple.DownloadFileFinished"), object: dest.path) }
|
|
389
|
+
onDownloaded?(dest)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// a failed download says so in a panel: never silent
|
|
393
|
+
func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?) {
|
|
394
|
+
let dest = downloads.removeValue(forKey: ObjectIdentifier(download))
|
|
395
|
+
if let onDownloaded { return onDownloaded(nil) }
|
|
396
|
+
let alert = NSAlert()
|
|
397
|
+
alert.messageText = "Download failed"
|
|
398
|
+
alert.informativeText = "\(dest?.lastPathComponent ?? "the file"): \(error.localizedDescription)"
|
|
399
|
+
alert.runModal()
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// `--self-test-download`: an offscreen page clicks a link marked download, twice, into SHIPKIT_GUI_DOWNLOADS; what
|
|
403
|
+
// landed printed, exit 0 only when both files hold the bytes under a free name and the page stayed on itself
|
|
404
|
+
func selfTestDownload() {
|
|
405
|
+
let web = WKWebView(frame: .zero, configuration: WKWebViewConfiguration())
|
|
406
|
+
web.navigationDelegate = self
|
|
407
|
+
let win = NSWindow(contentRect: NSRect(x: -4000, y: -4000, width: 600, height: 400), styleMask: [.titled], backing: .buffered, defer: false)
|
|
408
|
+
win.contentView = Pane(web: web)
|
|
409
|
+
win.orderFrontRegardless()
|
|
410
|
+
windows.append(win)
|
|
411
|
+
var saved: [String] = []
|
|
412
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 15) { print("timeout"); exit(1) }
|
|
413
|
+
let click = "document.getElementById('a').click(); 'clicked'"
|
|
414
|
+
onDownloaded = { url in
|
|
415
|
+
let text = url.flatMap { try? String(contentsOf: $0, encoding: .utf8) } ?? "none"
|
|
416
|
+
saved.append("\(url?.lastPathComponent ?? "failed"):\(text)")
|
|
417
|
+
if saved.count == 1 { return web.evaluateJavaScript(click) { _, _ in } }
|
|
418
|
+
web.evaluateJavaScript("document.body.dataset.page") { page, _ in
|
|
419
|
+
print("saved=\(saved.joined(separator: ","))")
|
|
420
|
+
print("page=\((page as? String) ?? "gone")")
|
|
421
|
+
exit(saved == ["hello.txt:hello", "hello (2).txt:hello"] && (page as? String) == "here" ? 0 : 1)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
var started = false
|
|
425
|
+
onLoad = { _ in
|
|
426
|
+
if started { return }
|
|
427
|
+
started = true
|
|
428
|
+
web.evaluateJavaScript(click) { _, _ in }
|
|
429
|
+
}
|
|
430
|
+
web.loadHTMLString("<body data-page=here><a id=a href='data:text/plain,hello' download='hello.txt'>save</a></body>", baseURL: nil)
|
|
431
|
+
}
|
|
432
|
+
|
|
344
433
|
// window.open and target=_blank: one more window of this app for its own pages
|
|
345
434
|
func webView(_ web: WKWebView, createWebViewWith config: WKWebViewConfiguration, for action: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
|
|
346
435
|
if let url = action.request.url {
|
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')
|