rvlib-shipkit 2.31.0 → 2.33.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 +51 -0
- package/package.json +1 -1
- package/src/advisors/acts.ts +16 -15
- package/src/advisors/advice.ts +56 -102
- package/src/advisors/advisor-view.ts +122 -76
- package/src/advisors/app-graph.ts +1 -1
- package/src/advisors/app.ts +3 -11
- package/src/advisors/cf-api.ts +1 -1
- package/src/advisors/dir-bucket.ts +4 -3
- package/src/advisors/edge/api.ts +20 -221
- package/src/advisors/edge/bucket.ts +2 -2
- package/src/advisors/edge/handler.ts +13 -155
- package/src/advisors/edge/here.ts +5 -5
- package/src/advisors/edge/pages.ts +12 -9
- package/src/advisors/edge/shell.ts +6 -5
- package/src/advisors/edge/sign-in.ts +101 -36
- package/src/advisors/edge/status.ts +19 -6
- package/src/advisors/edge/types.ts +36 -60
- package/src/advisors/expose.ts +29 -29
- package/src/advisors/here.ts +12 -12
- package/src/advisors/invite-send.ts +79 -35
- package/src/advisors/invite.ts +31 -8
- package/src/advisors/job.ts +24 -16
- package/src/advisors/login.ts +40 -15
- package/src/advisors/owner-store.ts +46 -22
- package/src/advisors/photos.ts +3 -3
- package/src/advisors/project.ts +27 -25
- package/src/advisors/reach.ts +89 -0
- package/src/advisors/rights.ts +1 -1
- package/src/advisors/routes.ts +55 -74
- package/src/advisors/scan.ts +0 -4
- package/src/advisors/setup-run.ts +14 -14
- package/src/advisors/share-trace.ts +3 -3
- package/src/advisors/{door-probe.ts → sign-in-probe.ts} +7 -6
- package/src/advisors/speaks.ts +29 -0
- package/src/advisors/sync.ts +97 -183
- package/src/advisors/tunnel.ts +6 -5
- package/src/advisors/users-listen.ts +92 -0
- package/src/advisors/users-router.ts +261 -87
- package/src/advisors/users-store.ts +81 -0
- package/src/agent-time/blocked-scan.ts +181 -0
- package/src/agent-time/registry.ts +12 -5
- package/src/agent-time/store.ts +9 -109
- package/src/asks/ask-bar-fold.ts +2 -1
- package/src/asks/ask-close.ts +2 -1
- package/src/asks/ask-doc.ts +2 -1
- package/src/asks/ask-migrate.ts +3 -2
- package/src/asks/ask-steps-fold.ts +2 -1
- package/src/asks/ask-store.ts +4 -3
- package/src/check.ts +3 -43
- package/src/checks/SK001-package-json-shape.check.ts +4 -55
- package/src/checks/SK004-gitignore-policy.check.ts +24 -69
- package/src/checks/SK013-one-way-in-policy.check.ts +3 -7
- package/src/checks/SK017-vscode-hub-task.check.ts +4 -4
- package/src/checks/SK019-tests-run-in-units.check.ts +3 -14
- package/src/checks/SK020-self-spawning-check.check.ts +5 -7
- package/src/checks/SK035-public-clean.check.ts +1 -1
- package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +5 -14
- package/src/checks/SK054-agent-allow-list.check.ts +5 -74
- package/src/checks/SK055-retired-config-keys.check.ts +45 -0
- package/src/cli/cmd_Advisors.ts +11 -45
- package/src/cli/cmd_Asks.ts +3 -10
- package/src/cli/cmd_Backup.ts +25 -127
- package/src/cli/cmd_BackupTargets.ts +1 -1
- package/src/cli/cmd_Capacity.ts +6 -2
- package/src/cli/cmd_Checks.ts +0 -14
- package/src/cli/cmd_Ci.ts +2 -1
- package/src/cli/cmd_Db.ts +3 -82
- package/src/cli/cmd_Home.ts +4 -32
- package/src/cli/cmd_Hq.ts +0 -17
- package/src/cli/cmd_Releases.ts +57 -4
- package/src/cli/cmd_Review.ts +333 -354
- package/src/cli/cmd_Shot.ts +26 -4
- package/src/cli/cmd_SocialDrafts.ts +6 -13
- package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +1 -1
- package/src/cli/inbox-hook-run.ts +5 -23
- package/src/cli/registry-heads.ts +5 -55
- package/src/cli/registry.ts +1 -5
- package/src/cli/review-here.ts +1 -1
- package/src/cli.ts +15 -4
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +5 -4
- package/src/core/admission.ts +268 -0
- package/src/core/agent-allow-policy.ts +32 -2
- package/src/core/agent-env.ts +8 -0
- package/src/core/allow-rows.ts +74 -0
- package/src/core/check-file-names.ts +19 -106
- package/src/core/code-lines.ts +36 -21
- package/src/core/footprint.ts +17 -13
- package/src/core/identities-root.ts +1 -4
- package/src/core/layout.ts +1 -2
- package/src/core/machine-db.ts +33 -208
- package/src/core/machine-layout.ts +14 -127
- package/src/core/machine-read.ts +5 -2
- package/src/core/mask-source.ts +60 -0
- package/src/core/memory-watch.ts +17 -14
- package/src/core/motherhome.ts +8 -35
- package/src/core/one-way-in-policy.ts +0 -3
- package/src/core/peer-sk.ts +8 -0
- package/src/core/repo-walk.ts +0 -9
- package/src/core/retention.ts +1 -9
- package/src/core/retired-checks.ts +2 -0
- package/src/core/tmux-policy.ts +1 -1
- package/src/core/tree-watch.ts +2 -2
- package/src/core/when.ts +7 -45
- package/src/gate/admit-heavy.ts +150 -0
- package/src/gate/check-runner.ts +6 -0
- package/src/gate/discover-checks.ts +42 -32
- package/src/gate/gate-checks.ts +21 -131
- package/src/gate/head-gate.ts +1 -1
- package/src/gate/job-run.ts +2 -1
- package/src/gate/pre-commit-discovery.ts +22 -28
- package/src/gate/run-check.ts +3 -4
- package/src/gate/run-ci.ts +4 -0
- package/src/gate/run-fix.ts +5 -17
- package/src/gate/run-fixers.ts +6 -42
- package/src/home/app-sign.ts +2 -2
- package/src/home/backup-status.ts +52 -92
- package/src/home/backup-verdict.ts +2 -2
- package/src/home/daemon-jobs.ts +51 -95
- package/src/home/database-words.ts +1 -2
- package/src/home/databases.ts +9 -25
- package/src/home/home-launchd.ts +0 -6
- package/src/home/home-paths.ts +8 -4
- package/src/home/home-routes.ts +3 -10
- package/src/home/home-state.ts +2 -14
- package/src/home/inbox-shape.ts +14 -15
- package/src/home/inbox.ts +1 -1
- package/src/home/machine-repair.ts +102 -103
- package/src/home/resume.ts +1 -15
- package/src/home/run-daemon.ts +7 -12
- package/src/home/space-page.ts +3 -2
- package/src/home/supervise.ts +3 -7
- package/src/hooks/commit-msg-run.ts +61 -0
- package/src/hooks/commit-run.ts +16 -166
- package/src/hooks/gate-outcome.ts +108 -0
- package/src/hooks/git-hook.ts +9 -9
- package/src/hooks/hook-config.ts +8 -8
- package/src/hooks/leak-guard.ts +1 -1
- package/src/hooks/pre-commit-checks.ts +1 -1
- package/src/hooks/run-hooks.ts +2 -6
- package/src/hooks/shared-file.ts +3 -2
- package/src/hq/daemon-db.ts +8 -8
- package/src/hq/door.ts +3 -16
- package/src/hq/hq-db.ts +4 -3
- package/src/hq/hq-local.ts +1 -2
- package/src/hq/hq-store.ts +0 -15
- package/src/hq/item-direct.ts +8 -10
- package/src/hq/item-fill.ts +37 -0
- package/src/hq/kinds/item-gone.ts +7 -10
- package/src/hq/kinds/item-msg.ts +12 -18
- package/src/hq/kinds/item.ts +13 -19
- package/src/hq/kinds/report.ts +3 -4
- package/src/hq/owner-switch.ts +3 -3
- package/src/hq/report.ts +5 -9
- package/src/hq/switch.ts +2 -11
- package/src/hq/thread-sync.ts +5 -17
- package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
- package/src/http/owner-word.ts +1 -1
- package/src/identities/machine.ts +16 -0
- package/src/init-repo.ts +0 -1
- package/src/ledger/check-stats.ts +6 -5
- package/src/ledger/db.ts +2 -4
- package/src/ledger/record-kept.ts +117 -48
- package/src/ledger/run-log.ts +21 -2
- package/src/ledger/slow-tests.ts +96 -0
- package/src/ledger/store.ts +3 -86
- package/src/ledger/suite-log.ts +8 -2
- package/src/media-store/backup/facts.ts +3 -37
- package/src/media-store/backup/keys.ts +1 -8
- package/src/media-store/backup/manifest.ts +6 -67
- package/src/media-store/backup/restore.ts +4 -13
- package/src/media-store/backup/retention.ts +13 -1
- package/src/media-store/backup/run.ts +6 -267
- package/src/media-store/backup/snapshot.ts +2 -38
- package/src/media-store/backup/sources.ts +3 -113
- package/src/media-store/backup/target-send.ts +5 -29
- package/src/media-store/db.ts +8 -7
- package/src/media-store/forget-one.ts +1 -1
- package/src/media-store/forget.ts +1 -80
- package/src/orchestrator/guards.ts +0 -1
- package/src/orchestrator/presence.ts +2 -2
- package/src/orchestrator/routes.ts +1 -1
- package/src/orchestrator/started.ts +0 -9
- package/src/orchestrator/talk-key.ts +3 -4
- package/src/orchestrator/unheard.ts +1 -1
- package/src/plan/planner.ts +3 -2
- package/src/recordings/edit.ts +3 -3
- package/src/recordings/marks-draw.ts +17 -6
- package/src/recordings/marks.ts +120 -9
- package/src/reflections/reflections-queue.ts +3 -10
- package/src/release/notes.ts +1 -1
- package/src/release/public-clean.ts +66 -6
- package/src/release/run-bump.ts +11 -0
- package/src/release/run-release.ts +4 -0
- package/src/releases/from-thread.ts +3 -3
- package/src/releases/model.ts +186 -36
- package/src/releases/store.ts +13 -3
- package/src/releases/validate.ts +83 -0
- package/src/repo-config.ts +36 -64
- package/src/review/answer-kinds.ts +63 -4
- package/src/review/blocked-guard.ts +11 -0
- package/src/review/blocked-object.ts +298 -0
- package/src/review/cells.ts +144 -230
- package/src/review/close.ts +39 -1
- package/src/review/doc-save.ts +3 -2
- package/src/review/draft-item.ts +1 -1
- package/src/review/events.ts +3 -7
- package/src/review/expect.ts +23 -39
- package/src/review/format.ts +79 -46
- package/src/review/glyphs.ts +1 -0
- package/src/review/hand-over.ts +3 -3
- package/src/review/heard.ts +1 -1
- package/src/review/holds-sync.ts +2 -1
- package/src/review/inbox-hook.ts +2 -2
- package/src/review/inbox-read.ts +39 -33
- package/src/review/instruction-guards.ts +12 -0
- package/src/review/instructions.ts +0 -1
- package/src/review/item-db.ts +13 -43
- package/src/review/item-hq.ts +2 -2
- package/src/review/item-rows.ts +3 -14
- package/src/review/kind-catalog.ts +3 -1
- package/src/review/kinds.ts +18 -8
- package/src/review/live-view.ts +3 -0
- package/src/review/media-kind.ts +1 -1
- package/src/review/mentions.ts +1 -2
- package/src/review/model.ts +158 -114
- package/src/review/move.ts +149 -0
- package/src/review/need-threads.ts +3 -2
- package/src/review/object-card.ts +11 -0
- package/src/review/object-read.ts +6 -1
- package/src/review/one-block.ts +1 -1
- package/src/review/owner-read.ts +1 -1
- package/src/review/phone-push.ts +10 -9
- package/src/review/previews.ts +32 -4
- package/src/review/push.ts +2 -2
- package/src/review/recap.ts +129 -0
- package/src/review/referring.ts +6 -3
- package/src/review/reflection-object.ts +4 -3
- package/src/review/routes.ts +51 -47
- package/src/review/secret-route.ts +3 -2
- package/src/review/settle.ts +0 -6
- package/src/review/snooze.ts +5 -3
- package/src/review/speaker.ts +68 -0
- package/src/review/start-title.ts +19 -0
- package/src/review/store-parties.ts +28 -0
- package/src/review/store.ts +94 -59
- package/src/review/{wakes.ts → thread-events.ts} +92 -7
- package/src/review/thread-md.ts +35 -14
- package/src/review/thread-state.ts +804 -0
- package/src/review/threads.ts +29 -347
- package/src/review/traces.ts +104 -7
- package/src/review/trailer-item.ts +1 -1
- package/src/review/unit.ts +7 -9
- package/src/review/verdict-items.ts +12 -10
- package/src/review/view-layout.ts +25 -1
- package/src/review/watch-feed.ts +1 -2
- package/src/review/working-guards.ts +2 -3
- package/src/rules/untrack-generated.ts +1 -15
- package/src/secrets/copy.ts +4 -4
- package/src/secrets/lapse.ts +2 -1
- package/src/serve/hub-app/advisor-app.tsx +4 -4
- package/src/serve/hub-app/advisor-face.tsx +9 -3
- package/src/serve/hub-app/advisor-host.ts +27 -27
- package/src/serve/hub-app/advisors-model.ts +17 -8
- package/src/serve/hub-app/advisors-rights.tsx +1 -1
- package/src/serve/hub-app/advisors-st.ts +15 -14
- package/src/serve/hub-app/advisors-view.tsx +13 -11
- package/src/serve/hub-app/app-bridge.ts +23 -3
- package/src/serve/hub-app/asks-page.tsx +1 -1
- package/src/serve/hub-app/auto-text.tsx +71 -16
- package/src/serve/hub-app/check-view.tsx +0 -8
- package/src/serve/hub-app/controls.css +14 -3
- package/src/serve/hub-app/database-view.tsx +1 -2
- package/src/serve/hub-app/dock-st.ts +1 -1
- package/src/serve/hub-app/git-view.tsx +3 -1
- package/src/serve/hub-app/hub.css +12 -5
- package/src/serve/hub-app/icons.tsx +1 -1
- package/src/serve/hub-app/inbox-view.tsx +1 -2
- package/src/serve/hub-app/live-sources.ts +2 -2
- package/src/serve/hub-app/main-panel.tsx +2 -1
- package/src/serve/hub-app/panel-repo.ts +0 -9
- package/src/serve/hub-app/pic.tsx +29 -12
- package/src/serve/hub-app/polled.ts +16 -2
- package/src/serve/hub-app/recordings-st.ts +23 -2
- package/src/serve/hub-app/recordings-view.tsx +68 -10
- package/src/serve/hub-app/ref-pill.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -2
- package/src/serve/hub-app/review/advisor-add.tsx +1 -1
- package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
- package/src/serve/hub-app/review/draft-body.tsx +2 -2
- package/src/serve/hub-app/review/heard-line.tsx +1 -1
- package/src/serve/hub-app/review/instructions-view.tsx +1 -8
- package/src/serve/hub-app/review/kind-states.tsx +14 -9
- package/src/serve/hub-app/review/kit.tsx +4 -11
- package/src/serve/hub-app/review/lane-bar.tsx +3 -3
- package/src/serve/hub-app/review/lightbox.tsx +15 -11
- package/src/serve/hub-app/review/line-window.ts +4 -1
- package/src/serve/hub-app/review/live-bar-st.ts +2 -2
- package/src/serve/hub-app/review/live-view.tsx +57 -1
- package/src/serve/hub-app/review/object-panel.tsx +20 -8
- package/src/serve/hub-app/review/question-views.tsx +191 -53
- package/src/serve/hub-app/review/recap-bar.tsx +40 -0
- package/src/serve/hub-app/review/request-cell.tsx +48 -0
- package/src/serve/hub-app/review/review-cells.tsx +154 -96
- package/src/serve/hub-app/review/review-host.ts +8 -4
- package/src/serve/hub-app/review/review-kit.ts +17 -11
- package/src/serve/hub-app/review/review-list.tsx +30 -35
- package/src/serve/hub-app/review/review-st.ts +32 -42
- package/src/serve/hub-app/review/review-thread.tsx +139 -85
- package/src/serve/hub-app/review/review-views.tsx +127 -68
- package/src/serve/hub-app/review/share-lines.tsx +4 -4
- package/src/serve/hub-app/review/start-st.ts +2 -5
- package/src/serve/hub-app/review/superseded-runs.ts +4 -3
- package/src/serve/hub-app/review/thread-close.tsx +10 -7
- package/src/serve/hub-app/review/thread-st.ts +381 -202
- package/src/serve/hub-app/review/tone-bar.tsx +129 -0
- package/src/serve/hub-app/review/tones.ts +53 -0
- package/src/serve/hub-app/review/trailer-body.tsx +2 -2
- package/src/serve/hub-app/review/trailer-st.ts +3 -2
- package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
- package/src/serve/hub-app/review.css +189 -106
- package/src/serve/hub-app/search-view.tsx +1 -1
- package/src/serve/hub-app/social/social-model.ts +0 -4
- package/src/serve/hub-app/source-acts.ts +2 -1
- package/src/serve/hub-app/stores/stores-page.tsx +2 -2
- package/src/serve/hub-app/terminal-sources.tsx +2 -1
- package/src/serve/hub-app/thread-row.tsx +3 -4
- package/src/serve/hub-app/tree-build.ts +0 -4
- package/src/serve/hub-app/urls-view.tsx +2 -1
- package/src/serve/hub-app/view-layout.css +13 -3
- package/src/serve/hub-app/wikis-view.tsx +5 -2
- package/src/serve/hub-runtime.ts +7 -37
- package/src/serve/project-gutter-route.ts +6 -2
- package/src/serve/read-thread.ts +20 -2
- package/src/serve/read-worker.ts +9 -1
- package/src/serve/record-pages.ts +46 -0
- package/src/serve/serve-hub.ts +2 -2
- package/src/serve/terminal-host.ts +1 -1
- package/src/serve/terminal-route.ts +1 -3
- package/src/serve/tracked-watch.ts +1 -3
- package/src/setup-house.ts +2 -2
- package/src/shipkit-files.ts +1 -1
- package/src/shipkit.ts +1 -6
- package/src/shot/client.ts +2 -1
- package/src/shot/film-box.ts +0 -20
- package/src/shot/on-place.ts +141 -0
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +6 -29
- package/src/social/load.ts +2 -2
- package/src/social/post-object.ts +3 -2
- package/src/social/release-stage.ts +1 -1
- package/src/social/stage.ts +2 -2
- package/src/stores/model.ts +4 -0
- package/src/stores/routes.ts +11 -3
- package/src/suite/judge-suites.ts +58 -0
- package/src/suite/red-alone.ts +54 -18
- package/src/suite/runner-shapes.ts +2 -2
- package/src/suite/suite-cli.ts +67 -14
- package/src/suite/test-units.ts +2 -1
- package/src/urls/fill.ts +1 -1
- package/src/urls/places.ts +1 -2
- package/src/vault/vault-config.ts +2 -2
- package/src/vault/vault-init.ts +1 -5
- package/src/wiki/graph-page.ts +14 -2
- package/src/advisors/copy-truth.ts +0 -49
- package/src/advisors/door-child.ts +0 -112
- package/src/advisors/door-serve.ts +0 -52
- package/src/advisors/door.ts +0 -118
- package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
- package/src/checks/SK029-explicit-check-files.check.ts +0 -112
- package/src/checks/SK048-one-local-file.check.ts +0 -36
- package/src/core/config-rewrite.ts +0 -111
- package/src/core/daemon-port.ts +0 -10
- package/src/core/legacy-shapes.ts +0 -263
- package/src/core/migrate-layout.ts +0 -638
- package/src/core/port-check-cli.ts +0 -52
- package/src/core/port-check-file.ts +0 -295
- package/src/core/port-check-files.ts +0 -31
- package/src/gate/discover-legacy-checks.ts +0 -26
- package/src/home/home-move.ts +0 -527
- package/src/home/machine-fold.ts +0 -810
- package/src/hq/item-shapes.ts +0 -54
- package/src/hq/kinds/items-read.ts +0 -4
- package/src/media-store/backup/daemon.ts +0 -220
- package/src/media-store/backup/kept.ts +0 -241
- package/src/media-store/backup/prune.ts +0 -359
- package/src/media-store/backup/secret.ts +0 -88
- package/src/media-store/backup/ssh-space.ts +0 -202
- package/src/media-store/backup/watch.ts +0 -117
- package/src/review/band.ts +0 -182
- package/src/review/folders.ts +0 -216
- package/src/review/hook-ask.ts +0 -58
- package/src/review/role.ts +0 -48
- package/src/review/thread-fold.ts +0 -64
- package/src/review/wait.ts +0 -91
- package/src/rules/rule.ts +0 -43
- package/src/serve/hook-thread.ts +0 -37
- package/src/serve/hook-work.ts +0 -92
- package/src/serve/hook-worker.ts +0 -57
- package/src/serve/hub-app/review/dock.tsx +0 -147
- package/src/serve/hub-app/review/faces.tsx +0 -18
- package/src/serve/hub-app/review/item-verdict.tsx +0 -112
- package/src/serve/hub-app/review/review-board.tsx +0 -48
- /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
package/src/hooks/commit-run.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
// the commit gates
|
|
2
|
-
//
|
|
1
|
+
// the pre-commit gates, run by the hook in ONE process: what the commit stages is read once (hooks/staged.ts) and
|
|
2
|
+
// every gate reads that, the built-ins and the repo's own module gates alike. The commit-msg gates are
|
|
3
|
+
// hooks/commit-msg-run.ts, what both share hooks/gate-outcome.ts.
|
|
3
4
|
// the one constraint a reader breaks first: the hook has 20 ms from bun's start (hooks/hook-gates.ts), so this
|
|
4
5
|
// module loads only what every commit needs; a gate that needs more imports it inside its own branch
|
|
5
|
-
import {
|
|
6
|
+
import { existsSync } from 'fs'
|
|
6
7
|
import { join } from 'path'
|
|
7
|
-
import {
|
|
8
|
-
import { maskPattern, patternFingerprint, runLeakGuard, type LeakHit, type LeakWaiver } from './leak-guard.ts'
|
|
8
|
+
import { runLeakGuard } from './leak-guard.ts'
|
|
9
9
|
import { runRootIdentity } from './root-identity.ts'
|
|
10
10
|
import { BlobReader, patchesByFile, readStagedAsync, type StagedCommit } from './staged.ts'
|
|
11
11
|
import { ALLOW_MASS_DELETE, runTreeShrink } from './tree-shrink.ts'
|
|
12
|
-
import {
|
|
12
|
+
import { hookGateOff, type HookGateId } from './hook-gates.ts'
|
|
13
|
+
import { commandGate, hitLine, importGate, moduleGate, startTimes, timeRow, waivedLines, type GateOutcome, type Timed } from './gate-outcome.ts'
|
|
13
14
|
import { heavyInCommit } from '../social/media-limit.ts'
|
|
14
15
|
import { LAYOUT } from '../core/layout.ts'
|
|
15
16
|
import { gitRoot } from '../core/git-root.ts'
|
|
16
17
|
import type { HookConfig } from './hook-config.ts'
|
|
17
18
|
import type { RepoConfig } from '../repo-config.ts'
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
export type GateOutcome = { id: string; ok: boolean; lines: string[]; ms?: number }
|
|
21
|
-
|
|
22
|
-
/** what a repo's module gate answers: `ok` false refuses the commit, and `lines` are printed when it fails or say
|
|
23
|
-
* something other than `ok:` */
|
|
24
|
-
export type GateVerdict = { ok: boolean; lines: string[] }
|
|
20
|
+
export { report, type GateOutcome, type GateVerdict, type Timed } from './gate-outcome.ts'
|
|
25
21
|
|
|
26
22
|
/** what a repo's pre-commit module gate is given: the commit's one staged read, and reads of it that cost no spawn or
|
|
27
23
|
* one for all their blobs */
|
|
@@ -39,35 +35,6 @@ export type PreCommitCtx = {
|
|
|
39
35
|
config: HookConfig
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
/** what a repo's commit-msg module gate is given */
|
|
43
|
-
export type CommitMsgCtx = { root: string; message: string; messageFile: string; config: HookConfig }
|
|
44
|
-
|
|
45
|
-
/** a repo module gate: `module` names a file relative to the repo root that exports `preCommit` (or `commitMsg`) */
|
|
46
|
-
type ModuleGate = { id: string; module: string }
|
|
47
|
-
|
|
48
|
-
/** a hit line: the masked pattern plus its FINGERPRINT, which is the token a
|
|
49
|
-
* waiver is written against, so nobody has to type the private word to
|
|
50
|
-
* exempt it. The file rides along for a content hit; a staged-PATH hit adds
|
|
51
|
-
* nothing, because there the path IS what matched. */
|
|
52
|
-
const hitLine = (x: LeakHit): string =>
|
|
53
|
-
` ${x.where}${x.where === 'staged content' && x.file != null ? ` ${x.file}` : ''}: ${maskPattern(x.pattern)} [${patternFingerprint(x.pattern)}]${x.over == null ? '' : `, ${x.over.found} added where ${x.over.source} allows ${x.over.count}`}`
|
|
54
|
-
|
|
55
|
-
/** what the allowlist let through, one line per waiver. An allowlist that
|
|
56
|
-
* fires invisibly is a silent weakening, so a waived match is as loud as a
|
|
57
|
-
* blocked one and carries the reason its author wrote. */
|
|
58
|
-
function waivedLines(waived: LeakWaiver[]): string[] {
|
|
59
|
-
const rows = new Map<string, { pattern: string; reason: string; source: string; targets: Set<string> }>()
|
|
60
|
-
for (const w of waived) {
|
|
61
|
-
const key = `${w.pattern} ${w.source}`
|
|
62
|
-
const row = rows.get(key) ?? { pattern: w.pattern, reason: w.reason, source: w.source, targets: new Set<string>() }
|
|
63
|
-
row.targets.add(w.file ?? w.where)
|
|
64
|
-
rows.set(key, row)
|
|
65
|
-
}
|
|
66
|
-
return [...rows.values()].map(
|
|
67
|
-
(r) => ` waived ${maskPattern(r.pattern)} [${patternFingerprint(r.pattern)}] in ${r.targets.size} target(s) — ${r.reason} (${r.source})`,
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
38
|
export const COMFY_DRAFTS = '.comfy-ts/drafts/'
|
|
72
39
|
|
|
73
40
|
/** the staged files the `blocked-paths` gate refuses. A repo DECLARED private
|
|
@@ -84,65 +51,6 @@ export const draftsOpen = (c: Pick<HookConfig, 'visibility'>): boolean => c.visi
|
|
|
84
51
|
|
|
85
52
|
const REPLAY_MARKERS = ['MERGE_HEAD', 'CHERRY_PICK_HEAD', 'rebase-merge', 'rebase-apply']
|
|
86
53
|
|
|
87
|
-
/** a gate's time, in ms. `owner`: who may make it cheaper or move it out of the hook: the repo (its own gate, a
|
|
88
|
-
* check that declares onPreCommit), `once` for what is read again once after its file changed (the check table,
|
|
89
|
-
* the config), or no one (a built-in commit gate, the process start, the staged read) */
|
|
90
|
-
export type Timed = { id: string; ms: number; owner?: 'repo' | 'once' }
|
|
91
|
-
|
|
92
|
-
/** what ran before the gates, named where the caller timed it (the imports, the config read), the rest as `start` */
|
|
93
|
-
function startTimes(since: number, before: Timed[] = []): Timed[] {
|
|
94
|
-
const rest = performance.now() - since - before.reduce((a, t) => a + t.ms, 0)
|
|
95
|
-
return [...before, ...(rest >= 1 ? [{ id: 'start', ms: rest }] : [])]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** what to do about a hook over its budget, from its slowest items. Only a gate the repo owns is ever sent out of the
|
|
99
|
-
* hook: a built-in (the leak guard first) never leaves it, whatever it costs */
|
|
100
|
-
function overBudget(slowest: readonly Timed[]): string {
|
|
101
|
-
const repo = slowest.find((t) => t.owner === 'repo')
|
|
102
|
-
if (repo != null) return `make ${repo.id} cheaper, or move it to a ci task`
|
|
103
|
-
if (slowest[0]?.owner === 'once') return `${slowest[0].id} was read again after its file changed: once, the next commit is back under it`
|
|
104
|
-
return 'built-in gates never leave the hook: a large commit or a busy machine costs this, nothing is to move'
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** set it to print every gate's time on each commit */
|
|
108
|
-
export const HOOK_TIMES = 'SHIPKIT_HOOK_TIMES'
|
|
109
|
-
|
|
110
|
-
/** the hook's own time row: over the budget it WARNs naming the slowest gates, and `SHIPKIT_HOOK_TIMES=1` prints them
|
|
111
|
-
* all. `start` is what ran before the gates: the process start, the imports, the config read */
|
|
112
|
-
function timeRow(hook: string, elapsed: number, times: Timed[]): GateOutcome {
|
|
113
|
-
const words = (ts: Timed[]): string => ts.map((t) => `${t.id} ${Math.round(t.ms)}ms`).join(', ')
|
|
114
|
-
const lines: string[] = []
|
|
115
|
-
if (elapsed > HOOK_BUDGET_MS) {
|
|
116
|
-
const slowest = [...times].sort((a, b) => b.ms - a.ms).slice(0, 3)
|
|
117
|
-
lines.push(`WARN ${hook} took ${Math.round(elapsed)}ms (budget ${HOOK_BUDGET_MS}ms), slowest: ${words(slowest)}: ${overBudget(slowest)} (tools/shipkit/commit-gates.md)`)
|
|
118
|
-
}
|
|
119
|
-
if (process.env[HOOK_TIMES] === '1') lines.push(` ${hook} times: ${words(times)}`)
|
|
120
|
-
return { id: 'hook-time', ok: true, lines, ms: elapsed }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const failLines = (e: unknown): string[] => [` ${String(e instanceof Error ? e.message : e).split('\n')[0]!.slice(0, 300)}`]
|
|
124
|
-
|
|
125
|
-
/** a module gate's file, imported; `loading`: its import already started (the hook starts it while git reads) */
|
|
126
|
-
const importGate = (root: string, g: ModuleGate): Promise<Record<string, unknown>> => import(join(root, g.module)) as Promise<Record<string, unknown>>
|
|
127
|
-
|
|
128
|
-
async function moduleGate<C>(root: string, g: ModuleGate, name: 'preCommit' | 'commitMsg', ctx: C, loading = importGate(root, g)): Promise<GateOutcome> {
|
|
129
|
-
try {
|
|
130
|
-
const mod = await loading
|
|
131
|
-
const run = mod[name]
|
|
132
|
-
if (typeof run !== 'function') return { id: g.id, ok: false, lines: [`FAIL: ${g.id}: ${g.module} exports no \`${name}\` function`] }
|
|
133
|
-
const v = (await (run as (c: C) => GateVerdict | Promise<GateVerdict>)(ctx)) as GateVerdict
|
|
134
|
-
return { id: g.id, ok: v.ok, lines: v.ok ? (v.lines.length === 0 ? [`ok: ${g.id}`] : v.lines) : [`FAIL: ${g.id}`, ...v.lines] }
|
|
135
|
-
} catch (e) {
|
|
136
|
-
return { id: g.id, ok: false, lines: [`FAIL: ${g.id} threw, so it judged nothing`, ...failLines(e)] }
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function commandGate(root: string, g: { id: string; cmd: string[] }, extra: string[], timeoutMs: number): Promise<GateOutcome> {
|
|
141
|
-
const { spawnWithTimeout } = await import('../core/spawn-timeout.ts')
|
|
142
|
-
const r = await spawnWithTimeout([...g.cmd, ...extra], { cwd: root, timeoutMs })
|
|
143
|
-
return { id: g.id, ok: r.code === 0, lines: r.code === 0 ? [`ok: ${g.id}`] : [`FAIL: ${g.id} (exit ${r.code})`, ...r.out.trim().split('\n').slice(-30).map((l) => ` ${l}`)] }
|
|
144
|
-
}
|
|
145
|
-
|
|
146
54
|
/** a promise whose rejection is seen where it is awaited, never as an unhandled one while other work runs first */
|
|
147
55
|
const later = <T>(p: Promise<T>): Promise<T> => {
|
|
148
56
|
p.catch(() => {})
|
|
@@ -171,7 +79,9 @@ export async function runPreCommitWith(root: string, config: HookConfig, full: (
|
|
|
171
79
|
// only an agent's shell carries CLAUDECODE, and the shared-file gate judges nothing else: its module loads only then
|
|
172
80
|
const agent = !off('shared-file') && process.env['CLAUDECODE'] === '1'
|
|
173
81
|
const sharedModule = agent ? later(import('./shared-file.ts')) : null
|
|
174
|
-
|
|
82
|
+
// the table's module loads while git reads; its answer needs the staged names, and its time is its own
|
|
83
|
+
const discovery = later(import('../gate/pre-commit-discovery.ts'))
|
|
84
|
+
const checks = later(reading.catch(() => null).then((read) => timed('checks at commit', () => runPreCommitChecks(root, config, full, discovery, read?.names))))
|
|
175
85
|
// the shared-file gate's reads that need no staged path, while git reads; an error is the gate's to report
|
|
176
86
|
const prepared = sharedModule == null ? null : await timed('shared-file read', async () => {
|
|
177
87
|
try {
|
|
@@ -339,11 +249,11 @@ export async function runPreCommitWith(root: string, config: HookConfig, full: (
|
|
|
339
249
|
/** every `onPreCommit` check, run RAW on the working tree: no ledger, no
|
|
340
250
|
* cache, no repair. A failure refuses the commit, a pass over its budget
|
|
341
251
|
* warns by name and never blocks on time. The table answers « none » with
|
|
342
|
-
* stats alone (gate/pre-commit-discovery.ts),
|
|
343
|
-
* when one runs */
|
|
344
|
-
async function runPreCommitChecks(root: string, config: HookConfig, full: () => Promise<RepoConfig
|
|
345
|
-
const { declarationsTable, preCommitFromTable } = await
|
|
346
|
-
const known = await preCommitFromTable(root)
|
|
252
|
+
* stats alone (gate/pre-commit-discovery.ts), its walk read again only when the
|
|
253
|
+
* commit stages a unit file, and the check engine loads only when one runs */
|
|
254
|
+
async function runPreCommitChecks(root: string, config: HookConfig, full: () => Promise<RepoConfig>, discovery: Promise<typeof import('../gate/pre-commit-discovery.ts')>, names?: readonly string[]): Promise<{ outcomes: GateOutcome[]; table: TableState }> {
|
|
255
|
+
const { declarationsTable, preCommitFromTable } = await discovery
|
|
256
|
+
const known = await preCommitFromTable(root, names)
|
|
347
257
|
if (known?.length === 0) return { outcomes: [], table: 'answered' }
|
|
348
258
|
const { runPreCommitChecksFull } = await import('./pre-commit-checks.ts')
|
|
349
259
|
const { outcomes, settled } = await runPreCommitChecksFull(root, config, full)
|
|
@@ -358,63 +268,3 @@ async function runPreCommitChecks(root: string, config: HookConfig, full: () =>
|
|
|
358
268
|
/** how the check table answered: from stats alone, rebuilt once and answering the next commit, or rebuilt and still
|
|
359
269
|
* unable to answer it (every commit pays the discovery) */
|
|
360
270
|
type TableState = 'answered' | 'rebuilt' | 'unsettled'
|
|
361
|
-
|
|
362
|
-
/** the commit-msg gate: the shared message predicate, then the repo's own. */
|
|
363
|
-
export async function runCommitMsgWith(root: string, config: HookConfig, messageFile: string, o: { since?: number; before?: Timed[] } = {}): Promise<GateOutcome[]> {
|
|
364
|
-
const since = o.since ?? performance.now()
|
|
365
|
-
const times = startTimes(since, o.before)
|
|
366
|
-
const h = config.hooks ?? {}
|
|
367
|
-
const out: GateOutcome[] = []
|
|
368
|
-
const message = readFileSync(messageFile, 'utf8')
|
|
369
|
-
if (hookGateOff(config, 'commit-message') == null) {
|
|
370
|
-
const languageOff = hookGateOff(config, 'commit-language') != null
|
|
371
|
-
const offenses = commitMessageOffenses(message, { languageAllow: h.languageAllow })
|
|
372
|
-
.filter((o) => o.kind !== 'language' || !languageOff)
|
|
373
|
-
out.push(offenses.length === 0
|
|
374
|
-
? { id: 'commit-message', ok: true, lines: [`ok: commit message clean (no dash punctuation${languageOff ? '' : ', English'})`] }
|
|
375
|
-
: {
|
|
376
|
-
id: 'commit-message',
|
|
377
|
-
ok: false,
|
|
378
|
-
lines: [
|
|
379
|
-
`FAIL: commit message has ${offenses.length} offense(s)`,
|
|
380
|
-
...offenses.map((o) => ` line ${o.line}: ${o.text.slice(0, 100)}\n ${o.why}`),
|
|
381
|
-
],
|
|
382
|
-
})
|
|
383
|
-
}
|
|
384
|
-
// the leak guard also reads the MESSAGE, a private name pasted into a
|
|
385
|
-
// commit body is as public as one pasted into a file
|
|
386
|
-
if (hookGateOff(config, 'leak-guard') == null) {
|
|
387
|
-
const r = runLeakGuard(root, { keywordFile: h.keywordFile, staged: false, allow: h.leakAllow, text: [{ label: 'commit message', content: message }] })
|
|
388
|
-
if (r.status === 'hit')
|
|
389
|
-
out.push({ id: 'leak-guard', ok: false, lines: [`FAIL: leak-guard matched in the commit message`, ...r.hits.map(hitLine), ...waivedLines(r.waived)] })
|
|
390
|
-
else if (r.status === 'clean' && r.waived.length > 0)
|
|
391
|
-
out.push({ id: 'leak-guard', ok: true, lines: [`ok: leak-guard clean in the commit message (${r.waived.length} waived)`, ...waivedLines(r.waived)] })
|
|
392
|
-
}
|
|
393
|
-
if (hookGateOff(config, 'reflection-trailer') == null && /^(Fixes|Declines)-reflection:/im.test(message)) {
|
|
394
|
-
const t = performance.now()
|
|
395
|
-
const { machinePlaces, trailerErrors } = await import('../reflections/reflection-close.ts')
|
|
396
|
-
const places = await machinePlaces(root)
|
|
397
|
-
const errors = places === null ? ['no house repo on this machine: a reflection closes where its house is'] : trailerErrors(stripNonMessage(message), places)
|
|
398
|
-
out.push(errors.length === 0
|
|
399
|
-
? { id: 'reflection-trailer', ok: true, lines: ['ok: reflection trailers name open reflections'] }
|
|
400
|
-
: { id: 'reflection-trailer', ok: false, lines: [`FAIL: reflection-trailer: ${errors.length} trailer(s) name no open reflection`, ...errors.map((e) => ` ${e}`)] })
|
|
401
|
-
times.push({ id: 'reflection-trailer', ms: performance.now() - t })
|
|
402
|
-
}
|
|
403
|
-
for (const g of h.commitMsg ?? []) {
|
|
404
|
-
const t = performance.now()
|
|
405
|
-
out.push('module' in g ? await moduleGate<CommitMsgCtx>(root, g, 'commitMsg', { root, message, messageFile, config }) : await commandGate(root, g, [messageFile], 60_000))
|
|
406
|
-
times.push({ id: g.id, ms: performance.now() - t, owner: 'repo' })
|
|
407
|
-
}
|
|
408
|
-
out.push(timeRow('commit-msg', performance.now() - since, times))
|
|
409
|
-
return out
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/** a gate that passed prints only what still needs a reader (a WARN, a waived
|
|
413
|
-
* hit), so a clean commit costs one line, not one per gate */
|
|
414
|
-
export const report = (out: GateOutcome[], write: (s: string) => void): number => {
|
|
415
|
-
for (const g of out) for (const l of g.lines) if (!g.ok || !l.startsWith('ok: ')) write(`${l}\n`)
|
|
416
|
-
const ok = out.every((g) => g.ok)
|
|
417
|
-
const time = out.find((g) => g.id === 'hook-time')?.ms
|
|
418
|
-
if (ok) write(`ok: ${out.filter((g) => g.id !== 'hook-time').length} commit gate(s) clean${time == null ? '' : ` in ${Math.round(time)}ms`}\n`)
|
|
419
|
-
return ok ? 0 : 1
|
|
420
|
-
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// what both commit hooks share: a gate's outcome and its lines, the hook's time row, a repo's own gate run, and the
|
|
2
|
+
// report. Its own module so the commit-msg hook loads none of the pre-commit gates (hooks/commit-msg-run.ts).
|
|
3
|
+
// the one constraint a reader breaks first: every import here is paid by both hooks on every commit
|
|
4
|
+
import { join } from 'path'
|
|
5
|
+
import { maskPattern, patternFingerprint, type LeakHit, type LeakWaiver } from './leak-guard.ts'
|
|
6
|
+
import { HOOK_BUDGET_MS } from './hook-gates.ts'
|
|
7
|
+
|
|
8
|
+
/** `ms`: set on the hook's own time row (`hook-time`), which `report` folds into its last line */
|
|
9
|
+
export type GateOutcome = { id: string; ok: boolean; lines: string[]; ms?: number }
|
|
10
|
+
|
|
11
|
+
/** what a repo's module gate answers: `ok` false refuses the commit, and `lines` are printed when it fails or say
|
|
12
|
+
* something other than `ok:` */
|
|
13
|
+
export type GateVerdict = { ok: boolean; lines: string[] }
|
|
14
|
+
|
|
15
|
+
/** a repo module gate: `module` names a file relative to the repo root that exports `preCommit` (or `commitMsg`) */
|
|
16
|
+
export type ModuleGate = { id: string; module: string }
|
|
17
|
+
|
|
18
|
+
/** a gate's time, in ms. `owner`: who may make it cheaper or move it out of the hook: the repo (its own gate, a
|
|
19
|
+
* check that declares onPreCommit), `once` for what is read again once after its file changed (the check table,
|
|
20
|
+
* the config), or no one (a built-in commit gate, the process start, the staged read) */
|
|
21
|
+
export type Timed = { id: string; ms: number; owner?: 'repo' | 'once' }
|
|
22
|
+
|
|
23
|
+
/** a hit line: the masked pattern plus its FINGERPRINT, which is the token a
|
|
24
|
+
* waiver is written against, so nobody has to type the private word to
|
|
25
|
+
* exempt it. The file rides along for a content hit; a staged-PATH hit adds
|
|
26
|
+
* nothing, because there the path IS what matched. */
|
|
27
|
+
export const hitLine = (x: LeakHit): string =>
|
|
28
|
+
` ${x.where}${x.where === 'staged content' && x.file != null ? ` ${x.file}` : ''}: ${maskPattern(x.pattern)} [${patternFingerprint(x.pattern)}]${x.over == null ? '' : `, ${x.over.found} added where ${x.over.source} allows ${x.over.count}`}`
|
|
29
|
+
|
|
30
|
+
/** what the allowlist let through, one line per waiver. An allowlist that
|
|
31
|
+
* fires invisibly is a silent weakening, so a waived match is as loud as a
|
|
32
|
+
* blocked one and carries the reason its author wrote. */
|
|
33
|
+
export function waivedLines(waived: LeakWaiver[]): string[] {
|
|
34
|
+
const rows = new Map<string, { pattern: string; reason: string; source: string; targets: Set<string> }>()
|
|
35
|
+
for (const w of waived) {
|
|
36
|
+
const key = `${w.pattern} ${w.source}`
|
|
37
|
+
const row = rows.get(key) ?? { pattern: w.pattern, reason: w.reason, source: w.source, targets: new Set<string>() }
|
|
38
|
+
row.targets.add(w.file ?? w.where)
|
|
39
|
+
rows.set(key, row)
|
|
40
|
+
}
|
|
41
|
+
return [...rows.values()].map(
|
|
42
|
+
(r) => ` waived ${maskPattern(r.pattern)} [${patternFingerprint(r.pattern)}] in ${r.targets.size} target(s) — ${r.reason} (${r.source})`,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** what ran before the gates, named where the caller timed it (the imports, the config read), the rest as `start` */
|
|
47
|
+
export function startTimes(since: number, before: Timed[] = []): Timed[] {
|
|
48
|
+
const rest = performance.now() - since - before.reduce((a, t) => a + t.ms, 0)
|
|
49
|
+
return [...before, ...(rest >= 1 ? [{ id: 'start', ms: rest }] : [])]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** what to do about a hook over its budget, from its slowest items. Only a gate the repo owns is ever sent out of the
|
|
53
|
+
* hook: a built-in (the leak guard first) never leaves it, whatever it costs */
|
|
54
|
+
function overBudget(slowest: readonly Timed[]): string {
|
|
55
|
+
const repo = slowest.find((t) => t.owner === 'repo')
|
|
56
|
+
if (repo != null) return `make ${repo.id} cheaper, or move it to a ci task`
|
|
57
|
+
if (slowest[0]?.owner === 'once') return `${slowest[0].id} was read again after its file changed: once, the next commit is back under it`
|
|
58
|
+
return 'built-in gates never leave the hook: a large commit or a busy machine costs this, nothing is to move'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** set it to print every gate's time on each commit */
|
|
62
|
+
export const HOOK_TIMES = 'SHIPKIT_HOOK_TIMES'
|
|
63
|
+
|
|
64
|
+
/** the hook's own time row: over the budget it WARNs naming the slowest gates, and `SHIPKIT_HOOK_TIMES=1` prints them
|
|
65
|
+
* all. `start` is what ran before the gates: the process start, the imports, the config read */
|
|
66
|
+
export function timeRow(hook: string, elapsed: number, times: Timed[]): GateOutcome {
|
|
67
|
+
const words = (ts: Timed[]): string => ts.map((t) => `${t.id} ${Math.round(t.ms)}ms`).join(', ')
|
|
68
|
+
const lines: string[] = []
|
|
69
|
+
if (elapsed > HOOK_BUDGET_MS) {
|
|
70
|
+
const slowest = [...times].sort((a, b) => b.ms - a.ms).slice(0, 3)
|
|
71
|
+
lines.push(`WARN ${hook} took ${Math.round(elapsed)}ms (budget ${HOOK_BUDGET_MS}ms), slowest: ${words(slowest)}: ${overBudget(slowest)} (tools/shipkit/commit-gates.md)`)
|
|
72
|
+
}
|
|
73
|
+
if (process.env[HOOK_TIMES] === '1') lines.push(` ${hook} times: ${words(times)}`)
|
|
74
|
+
return { id: 'hook-time', ok: true, lines, ms: elapsed }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const failLines = (e: unknown): string[] => [` ${String(e instanceof Error ? e.message : e).split('\n')[0]!.slice(0, 300)}`]
|
|
78
|
+
|
|
79
|
+
/** a module gate's file, imported; the hook starts it while git reads */
|
|
80
|
+
export const importGate = (root: string, g: ModuleGate): Promise<Record<string, unknown>> => import(join(root, g.module)) as Promise<Record<string, unknown>>
|
|
81
|
+
|
|
82
|
+
export async function moduleGate<C>(root: string, g: ModuleGate, name: 'preCommit' | 'commitMsg', ctx: C, loading = importGate(root, g)): Promise<GateOutcome> {
|
|
83
|
+
try {
|
|
84
|
+
const mod = await loading
|
|
85
|
+
const run = mod[name]
|
|
86
|
+
if (typeof run !== 'function') return { id: g.id, ok: false, lines: [`FAIL: ${g.id}: ${g.module} exports no \`${name}\` function`] }
|
|
87
|
+
const v = (await (run as (c: C) => GateVerdict | Promise<GateVerdict>)(ctx)) as GateVerdict
|
|
88
|
+
return { id: g.id, ok: v.ok, lines: v.ok ? (v.lines.length === 0 ? [`ok: ${g.id}`] : v.lines) : [`FAIL: ${g.id}`, ...v.lines] }
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return { id: g.id, ok: false, lines: [`FAIL: ${g.id} threw, so it judged nothing`, ...failLines(e)] }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function commandGate(root: string, g: { id: string; cmd: string[] }, extra: string[], timeoutMs: number): Promise<GateOutcome> {
|
|
95
|
+
const { spawnWithTimeout } = await import('../core/spawn-timeout.ts')
|
|
96
|
+
const r = await spawnWithTimeout([...g.cmd, ...extra], { cwd: root, timeoutMs })
|
|
97
|
+
return { id: g.id, ok: r.code === 0, lines: r.code === 0 ? [`ok: ${g.id}`] : [`FAIL: ${g.id} (exit ${r.code})`, ...r.out.trim().split('\n').slice(-30).map((l) => ` ${l}`)] }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** a gate that passed prints only what still needs a reader (a WARN, a waived
|
|
101
|
+
* hit), so a clean commit costs one line, not one per gate */
|
|
102
|
+
export const report = (out: GateOutcome[], write: (s: string) => void): number => {
|
|
103
|
+
for (const g of out) for (const l of g.lines) if (!g.ok || !l.startsWith('ok: ')) write(`${l}\n`)
|
|
104
|
+
const ok = out.every((g) => g.ok)
|
|
105
|
+
const time = out.find((g) => g.id === 'hook-time')?.ms
|
|
106
|
+
if (ok) write(`ok: ${out.filter((g) => g.id !== 'hook-time').length} commit gate(s) clean${time == null ? '' : ` in ${Math.round(time)}ms`}\n`)
|
|
107
|
+
return ok ? 0 : 1
|
|
108
|
+
}
|
package/src/hooks/git-hook.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { existsSync, realpathSync, writeSync } from 'fs'
|
|
7
7
|
import { join } from 'path'
|
|
8
8
|
import { readStagedAsync, STAGED_STDIN, stagedFromStdin } from './staged.ts'
|
|
9
|
-
import type { Timed } from './
|
|
9
|
+
import type { Timed } from './gate-outcome.ts'
|
|
10
10
|
|
|
11
11
|
// the process start and the static import, before the first line runs
|
|
12
12
|
const loaded = performance.now()
|
|
@@ -24,25 +24,25 @@ async function oneCopy(): Promise<void> {
|
|
|
24
24
|
;(await import('../core/one-lib.ts')).installOneLib()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
async function load() {
|
|
27
|
+
/** one hook's gates and the config fields, loaded while git runs; `before`: what that took, for the hook's time line */
|
|
28
|
+
async function load<G>(gates: () => Promise<G>) {
|
|
29
29
|
await oneCopy()
|
|
30
|
-
const [
|
|
30
|
+
const [g, { loadHookConfig }, { report }] = await Promise.all([gates(), import('./hook-config.ts'), import('./gate-outcome.ts')])
|
|
31
31
|
const imported = performance.now()
|
|
32
32
|
const c = await loadHookConfig(root)
|
|
33
33
|
const before: Timed[] = [{ id: 'boot', ms: loaded }, { id: 'imports', ms: imported - loaded }, c.fromCopy ? { id: 'config', ms: performance.now() - imported } : { id: 'config load', ms: performance.now() - imported, ...(c.wrote ? { owner: 'once' as const } : {}) }]
|
|
34
|
-
return { gates, config: c.config, full: c.full, before }
|
|
34
|
+
return { gates: g, report, config: c.config, full: c.full, before }
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (hook === 'pre-commit') {
|
|
38
38
|
// the hook body pipes git's read in (hooks/run-hooks.ts): git ran while bun started. Run by hand, it reads git itself
|
|
39
39
|
const staged = file === STAGED_STDIN ? stagedFromStdin(root) : readStagedAsync(root)
|
|
40
40
|
staged.catch(() => {})
|
|
41
|
-
const { gates, config, full, before } = await load()
|
|
42
|
-
process.exitCode =
|
|
41
|
+
const { gates, report, config, full, before } = await load(() => import('./commit-run.ts'))
|
|
42
|
+
process.exitCode = report(await gates.runPreCommitWith(root, config, full, { since: 0, before, staged }), write)
|
|
43
43
|
} else if (hook === 'commit-msg' && file != null) {
|
|
44
|
-
const { gates, config, before } = await load()
|
|
45
|
-
process.exitCode =
|
|
44
|
+
const { gates, report, config, before } = await load(() => import('./commit-msg-run.ts'))
|
|
45
|
+
process.exitCode = report(await gates.runCommitMsgWith(root, config, file, { since: 0, before }), write)
|
|
46
46
|
} else {
|
|
47
47
|
console.error(`usage: bun ${import.meta.path} pre-commit | commit-msg <message file>`)
|
|
48
48
|
process.exitCode = 2
|
package/src/hooks/hook-config.ts
CHANGED
|
@@ -8,16 +8,15 @@
|
|
|
8
8
|
// when repo.config.ts itself changes (or the copy is dropped); a field that is not plain data is never copied, and
|
|
9
9
|
// such a config is loaded whole on every commit
|
|
10
10
|
import { mkdirSync, readFileSync } from 'fs'
|
|
11
|
-
import { atomicWrite } from '../core/atomic-write.ts'
|
|
12
11
|
import { dirname, join } from 'path'
|
|
13
12
|
import { gitRoot } from '../core/git-root.ts'
|
|
14
13
|
import type { RepoConfig } from '../repo-config.ts'
|
|
15
14
|
|
|
16
|
-
/** the fields of repo.config.ts the commit hooks read
|
|
17
|
-
export type HookConfig = Pick<RepoConfig, 'hooks' | 'off' | '
|
|
15
|
+
/** the fields of repo.config.ts the commit hooks read */
|
|
16
|
+
export type HookConfig = Pick<RepoConfig, 'hooks' | 'off' | 'visibility'>
|
|
18
17
|
|
|
19
|
-
/** the fields copied as they are
|
|
20
|
-
const COPIED = ['hooks', 'off', '
|
|
18
|
+
/** the fields copied as they are: the copy's key holds this list */
|
|
19
|
+
const COPIED = ['hooks', 'off', 'visibility'] as const satisfies readonly (keyof HookConfig)[]
|
|
21
20
|
|
|
22
21
|
/** the shape of the copy file itself */
|
|
23
22
|
const COPY_VERSION = 3
|
|
@@ -29,10 +28,9 @@ const COPIES_MAX = 16
|
|
|
29
28
|
type Copies = { v: number; copies: Record<string, { config: HookConfig; root?: string }> }
|
|
30
29
|
|
|
31
30
|
export function hookSlice(c: RepoConfig): HookConfig {
|
|
32
|
-
const defaults = Object.fromEntries(Object.entries(c.defaults ?? {}).filter(([, v]) => v === false).map(([k]) => [k, false as const]))
|
|
33
31
|
const out: HookConfig = {}
|
|
34
32
|
for (const k of COPIED) if (c[k] != null) Object.assign(out, { [k]: c[k] })
|
|
35
|
-
return
|
|
33
|
+
return out
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
/** plain data all the way down: what JSON keeps as it is */
|
|
@@ -61,7 +59,7 @@ function readCopies(path: string): Copies {
|
|
|
61
59
|
/** the config file's bytes hashed (a few KB: microseconds), with the copied fields' names; null with no file */
|
|
62
60
|
const stampOf = (path: string): string | null => {
|
|
63
61
|
try {
|
|
64
|
-
return `${Bun.hash(readFileSync(path)).toString(36)}:${COPIED.join(',')}
|
|
62
|
+
return `${Bun.hash(readFileSync(path)).toString(36)}:${COPIED.join(',')}`
|
|
65
63
|
} catch {
|
|
66
64
|
return null
|
|
67
65
|
}
|
|
@@ -94,6 +92,8 @@ export async function loadHookConfig(root: string): Promise<{ config: HookConfig
|
|
|
94
92
|
const keys = Object.keys(copies.copies)
|
|
95
93
|
for (const k of keys.slice(0, Math.max(0, keys.length - COPIES_MAX))) delete copies.copies[k]
|
|
96
94
|
mkdirSync(dirname(copy), { recursive: true })
|
|
95
|
+
// loaded only here: a commit that reads the copy writes nothing
|
|
96
|
+
const { atomicWrite } = await import('../core/atomic-write.ts')
|
|
97
97
|
atomicWrite(copy, JSON.stringify(copies))
|
|
98
98
|
wrote = true
|
|
99
99
|
} catch {
|
package/src/hooks/leak-guard.ts
CHANGED
|
@@ -101,7 +101,7 @@ const escapeRegex = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$
|
|
|
101
101
|
export const SK_KEY_ROW = String.raw`re:(?<![A-Za-z0-9_-])sk-(?=[A-Za-z0-9_-]{20})(?=[A-Za-z0-9_-]*\d)[A-Za-z0-9_-]*?[A-Za-z0-9]{16}[A-Za-z0-9_-]*`
|
|
102
102
|
|
|
103
103
|
/** THE list of what a secret key looks like, for every surface that must never let one through: the commit gate and
|
|
104
|
-
* every scan (`withBuiltinRows`),
|
|
104
|
+
* every scan (`withBuiltinRows`), and the mask of every line
|
|
105
105
|
* `sk time` prints and every prompt that leaves the machine (agent-time/mask.ts, which adds the name rules). A row is
|
|
106
106
|
* a token's own shape, exact in case; never copied into a keyword file */
|
|
107
107
|
export const SECRET_ROWS: readonly string[] = [
|
|
@@ -9,7 +9,7 @@ import { runCheckBody, type CheckDef } from '../check.ts'
|
|
|
9
9
|
import { repoOff } from '../core/when.ts'
|
|
10
10
|
import { formatLine } from '../core/wire.ts'
|
|
11
11
|
import type { RepoConfig } from '../repo-config.ts'
|
|
12
|
-
import type { GateOutcome } from './
|
|
12
|
+
import type { GateOutcome } from './gate-outcome.ts'
|
|
13
13
|
import type { HookConfig } from './hook-config.ts'
|
|
14
14
|
|
|
15
15
|
/** the checks that declare `onPreCommit` and apply here, with their budget */
|
package/src/hooks/run-hooks.ts
CHANGED
|
@@ -15,7 +15,8 @@ import { FOREIGN_HOOKS, FOREIGN_WHY, isForeign } from '../core/foreign.ts'
|
|
|
15
15
|
import type { RepoConfig } from '../repo-config.ts'
|
|
16
16
|
import { gitBin } from '../core/git-bin.ts'
|
|
17
17
|
import { HOOK_BUDGET_MS, hookGateOff, type HookGateId } from './hook-gates.ts'
|
|
18
|
-
import { blockedStaged, COMFY_DRAFTS, draftsOpen,
|
|
18
|
+
import { blockedStaged, COMFY_DRAFTS, draftsOpen, runPreCommitWith, type GateOutcome } from './commit-run.ts'
|
|
19
|
+
import { runCommitMsgWith } from './commit-msg-run.ts'
|
|
19
20
|
import type { PreCommitCheck } from './pre-commit-checks.ts'
|
|
20
21
|
import { DIFF_FLAGS, STAGED_END, STAGED_STDIN } from './staged.ts'
|
|
21
22
|
|
|
@@ -67,11 +68,6 @@ export type HooksConfig = {
|
|
|
67
68
|
/** words the commit-message language gate never counts as French
|
|
68
69
|
* (proper nouns that carry accents without being a language choice) */
|
|
69
70
|
languageAllow?: string[]
|
|
70
|
-
/** RETIRED, read as `off` while SK029 ports it there: a commit gate is
|
|
71
|
-
* turned off like any check, `off: { <gate id>: '<why>' }`
|
|
72
|
-
* (tools/shipkit/runs.md). Dies once `shipkit fleet` shows no repo
|
|
73
|
-
* carrying it */
|
|
74
|
-
disable?: HookGateId[]
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
const HOOK_DIR = LAYOUT.hooks
|
package/src/hooks/shared-file.ts
CHANGED
|
@@ -10,14 +10,12 @@
|
|
|
10
10
|
import { readFileSync, realpathSync, statSync } from 'fs'
|
|
11
11
|
import { homedir } from 'os'
|
|
12
12
|
import { basename, dirname, join } from 'path'
|
|
13
|
-
import { sessionRecords } from '../agent-time/claude-sessions.ts'
|
|
14
13
|
import { laneNameOf } from '../agent-time/lane-name.ts'
|
|
15
14
|
import { gitBin } from '../core/git-bin.ts'
|
|
16
15
|
import { EDIT_MATCHER, hasEditGuard } from './edit-guard.ts'
|
|
17
16
|
import { heldNow, markJudged, type Committing } from './held-calls.ts'
|
|
18
17
|
import type { Staged } from './staged.ts'
|
|
19
18
|
import { readWrites, seenOf, writerKey, writesByName, type Write, type Writer } from './write-log.ts'
|
|
20
|
-
import { pidAlive } from '../core/pid-alive.ts'
|
|
21
19
|
|
|
22
20
|
/** the joint commit two lanes agreed on: the other writers, by the names the refusal prints */
|
|
23
21
|
export const COMMIT_WITH = 'SHIPKIT_COMMIT_WITH'
|
|
@@ -53,6 +51,9 @@ export function writerState(w: Writer, lastNote = 0): WriterState {
|
|
|
53
51
|
const transcript = w.tp == null ? null : w.a == null ? w.tp : join(w.tp.replace(/\.jsonl$/, ''), 'subagents', `agent-${w.a}.jsonl`)
|
|
54
52
|
let heard = lastNote
|
|
55
53
|
try { if (transcript != null) heard = Math.max(heard, statSync(transcript).mtimeMs) } catch { /* no transcript: its notes date it */ }
|
|
54
|
+
// loaded here, never at the module's import: only a contested file asks it, and a commit with none loads none of it
|
|
55
|
+
const { sessionRecords } = require('../agent-time/claude-sessions.ts') as typeof import('../agent-time/claude-sessions.ts')
|
|
56
|
+
const { pidAlive } = require('../core/pid-alive.ts') as typeof import('../core/pid-alive.ts')
|
|
56
57
|
const records = sessionRecords(config)
|
|
57
58
|
if (records.length === 0) return { state: 'unknown', heard }
|
|
58
59
|
const live = records.filter((r) => r.sessionId === w.s && pidAlive(r.pid))
|
package/src/hq/daemon-db.ts
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
// counts what a thread verb loads)
|
|
6
6
|
import { Database } from 'bun:sqlite'
|
|
7
7
|
import { existsSync } from 'node:fs'
|
|
8
|
-
import {
|
|
8
|
+
import { machineDbPath, openMachineFile, refusalText, storeRefusal } from '../core/machine-db.ts'
|
|
9
9
|
import { isNoCopy, migrateTo, ownerOnly } from '../ledger/db.ts'
|
|
10
10
|
import { ITEM_DB_SCHEMA } from '../review/item-db.ts'
|
|
11
11
|
import { EVENTS_SCHEMA } from '../review/events.ts'
|
|
12
12
|
|
|
13
13
|
/** moves the daemon's own database for one process (a test) */
|
|
14
14
|
export const DAEMON_DB_ENV = 'SHIPKIT_DAEMON_DB'
|
|
15
|
-
export const daemonDbPath = (): string => process.env[DAEMON_DB_ENV] ||
|
|
15
|
+
export const daemonDbPath = (): string => process.env[DAEMON_DB_ENV] || machineDbPath()
|
|
16
16
|
|
|
17
17
|
// outbox the rows bound for the hq, one outbox (`box`) a group of kinds, each numbered from 1 with no gap
|
|
18
18
|
// meta each outbox's name and the highest number it gave (`top:<box>`), and the feed's cursor (ledger.ts)
|
|
@@ -78,16 +78,16 @@ ${EVENTS_SCHEMA}`
|
|
|
78
78
|
/** the version of the daemon's own tables: a new table raises it */
|
|
79
79
|
export const DAEMON_DB_VERSION = 14
|
|
80
80
|
|
|
81
|
-
/** every table of the daemon's: the same names in
|
|
81
|
+
/** every table of the daemon's: the same names in the machine db and in a file a suite moves it to */
|
|
82
82
|
export const DAEMON_TABLES = ['outbox', 'meta', 'sent', 'pending', 'retry', 'kept', 'waiting', 'scanned', 'history_sent', 'history_forgotten', 'history_days', 'history_pending', 'files_sent', 'files_pending', 'media_pending', 'media_kept', 'review_cards', 'review_msgs', 'review_gone', 'review_replaced', 'review_repos', 'thread_events', 'thread_post_groups', 'thread_posts'] as const
|
|
83
83
|
|
|
84
84
|
/** the row of the machine db that says which version its daemon tables are (its own version is the machine db's) */
|
|
85
85
|
export const DAEMON_VERSION_ROW = 'daemon-db-version'
|
|
86
86
|
|
|
87
|
-
/** the daemon's tables, made where they are not
|
|
87
|
+
/** the daemon's tables, made where they are not */
|
|
88
88
|
export function createDaemonTables(db: Database): void {
|
|
89
89
|
db.exec(DAEMON_DB_SCHEMA)
|
|
90
|
-
// its own
|
|
90
|
+
// a file of its own by its version, the machine db by its row
|
|
91
91
|
if (db.query("select 1 from sqlite_master where type = 'table' and name = 'state'").get() != null) db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(DAEMON_VERSION_ROW, JSON.stringify(DAEMON_DB_VERSION), Date.now())
|
|
92
92
|
else db.exec(`pragma user_version = ${DAEMON_DB_VERSION}`)
|
|
93
93
|
}
|
|
@@ -107,14 +107,14 @@ let saidRefusal: string | null = null
|
|
|
107
107
|
|
|
108
108
|
/** the daemon's own database: its outbox, and its ledger of the feed */
|
|
109
109
|
export function openDaemonDb(path: string = daemonDbPath()): Database | null {
|
|
110
|
-
const refused =
|
|
110
|
+
const refused = storeRefusal('daemon file', path)
|
|
111
111
|
if (refused != null) {
|
|
112
112
|
if (refusalText(refused) !== saidRefusal) console.error(`WARN the daemon's database does not open: ${refusalText(refused)}`)
|
|
113
113
|
saidRefusal = refusalText(refused)
|
|
114
114
|
return null
|
|
115
115
|
}
|
|
116
116
|
saidRefusal = null
|
|
117
|
-
//
|
|
117
|
+
// the machine db's tables, their version its row
|
|
118
118
|
if (path === machineDbPath())
|
|
119
119
|
try {
|
|
120
120
|
return openMachineFile(path, { schema: (db) => (daemonTablesReady(db) ? undefined : createDaemonTables(db)) })
|
|
@@ -143,7 +143,7 @@ export function lookDaemonDb(path: string = daemonDbPath()): Database {
|
|
|
143
143
|
return mem
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
/** the daemon's own
|
|
146
|
+
/** the daemon's tables in a file of their own (a suite's, SHIPKIT_DAEMON_DB), migrated to this code's version */
|
|
147
147
|
export function openDaemonFile(path: string): Database | null {
|
|
148
148
|
ownerOnly(path)
|
|
149
149
|
try {
|
package/src/hq/door.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { createHash, randomBytes, timingSafeEqual } from 'crypto'
|
|
6
6
|
import { chmodSync, linkSync, mkdirSync, readFileSync, rmSync, unlinkSync, writeFileSync } from 'fs'
|
|
7
7
|
import { join } from 'path'
|
|
8
|
-
import {
|
|
8
|
+
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
9
9
|
import { daemonPort, homeDir, homePort, hqPort, pmPort, publicHome } from '../home/home-paths.ts'
|
|
10
10
|
import { DEFAULT_VAULT_CLUSTER_PORT, DEFAULT_VAULT_PORT } from '../vault/vault-config.ts'
|
|
11
11
|
import { loopbackOrigin, machineLabel, urlLabelOf } from '../http/door-forward.ts'
|
|
@@ -16,28 +16,15 @@ export const HQ_PROXY = 'hq-proxy'
|
|
|
16
16
|
/** a machine's urls to the hq's home: on, its web opens its own global processes and loopback urls to the hq's proxy,
|
|
17
17
|
* for the key the hq gave it */
|
|
18
18
|
export const MACHINE_URLS = 'machine-urls'
|
|
19
|
-
/** the switch's name before: a machine db that holds only it is read under it once, and the value moves to the new name */
|
|
20
|
-
export const MACHINE_URLS_WAS = 'machine-door'
|
|
21
19
|
export const proxyOn = (): boolean => machineGet<boolean>(HQ_PROXY) === true
|
|
22
|
-
export
|
|
23
|
-
const v = machineGet<boolean>(MACHINE_URLS)
|
|
24
|
-
if (v != null) return v === true
|
|
25
|
-
const was = machineGet<boolean>(MACHINE_URLS_WAS)
|
|
26
|
-
if (was == null) return false
|
|
27
|
-
if (machineSet(MACHINE_URLS, was)) machineDelete(MACHINE_URLS_WAS)
|
|
28
|
-
return was === true
|
|
29
|
-
}
|
|
20
|
+
export const urlsOn = (): boolean => machineGet<boolean>(MACHINE_URLS) === true
|
|
30
21
|
/** false when the machine db does not open. Off ends every proxy key at once: the hq's secret goes, and the next on makes new ones */
|
|
31
22
|
export function setProxyOn(on: boolean): boolean {
|
|
32
23
|
if (!machineSet(HQ_PROXY, on)) return false
|
|
33
24
|
if (!on) rmSync(secretFile(), { force: true })
|
|
34
25
|
return true
|
|
35
26
|
}
|
|
36
|
-
export
|
|
37
|
-
if (!machineSet(MACHINE_URLS, on)) return false
|
|
38
|
-
machineDelete(MACHINE_URLS_WAS)
|
|
39
|
-
return true
|
|
40
|
-
}
|
|
27
|
+
export const setUrlsOn = (on: boolean): boolean => machineSet(MACHINE_URLS, on)
|
|
41
28
|
|
|
42
29
|
const secretFile = (): string => join(homeDir(), 'hq-door-secret')
|
|
43
30
|
const keyFile = (): string => join(homeDir(), 'door-key')
|