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
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// THE ADMISSION GATE FOR HEAVY WORK: before a heavy sk command (a clip, a loop of
|
|
2
|
+
// shots, sk smoke, a command the repo declares in repo.config.ts `heavy`) and
|
|
3
|
+
// before the first heavy check an asked gate runs (heavyCheck), a full machine
|
|
4
|
+
// makes it wait, one line every 10 s that names who uses the CPU, grouped by repo
|
|
5
|
+
// and by Claude session (one `ps`, the session files of Claude Code). Past the
|
|
6
|
+
// bound it runs anyway, with a WARN, and a bound reached against a user outside sk
|
|
7
|
+
// lets the next ones run at once while that user leads. The readings and the
|
|
8
|
+
// entries: gate/admit-heavy.ts.
|
|
9
|
+
//
|
|
10
|
+
// the one constraint a reader breaks first: this file reads nothing, every
|
|
11
|
+
// reading comes in as an argument, so a test drives the wait on a fake clock.
|
|
12
|
+
import { basename } from 'path'
|
|
13
|
+
import { effectiveLoad, machineWords, type MachineLoad } from './machine-busy.ts'
|
|
14
|
+
|
|
15
|
+
/** the machine is full past this many times its cores of load, once its CPU is taken (effectiveLoad) */
|
|
16
|
+
export const FULL_FACTOR = 1.5
|
|
17
|
+
/** how long a heavy command waits at most, in seconds, unless SHIPKIT_ADMIT_WAIT_S says another (0: never waits):
|
|
18
|
+
* under the 120 s an agent's foreground call lives, so a wait ends in a verdict, never in a killed call */
|
|
19
|
+
export const ADMIT_BOUND_S = 80
|
|
20
|
+
export const ADMIT_WAIT_ENV = 'SHIPKIT_ADMIT_WAIT_S'
|
|
21
|
+
/** a waiter says one line this often */
|
|
22
|
+
export const SAY_EVERY_MS = 10_000
|
|
23
|
+
/** a waiter looks at the machine again about this often, give or take a quarter, so waiters never look together */
|
|
24
|
+
export const LOOK_EVERY_MS = 2_000
|
|
25
|
+
/** a still is heavy once the command that runs it (its parent process: a script, a shell loop) asked this many
|
|
26
|
+
* inside SHOT_LOOP_MS: a loop of shots. An agent's calls one by one each have their own parent */
|
|
27
|
+
export const SHOT_LOOP_COUNT = 3
|
|
28
|
+
export const SHOT_LOOP_MS = 60_000
|
|
29
|
+
|
|
30
|
+
export const isFull = (m: MachineLoad): boolean => effectiveLoad(m) > FULL_FACTOR * m.cores
|
|
31
|
+
|
|
32
|
+
export type PsRow = { pid: number; ppid: number; cpu: number; args: string }
|
|
33
|
+
|
|
34
|
+
/** `ps -Axo pid=,ppid=,%cpu=,args=` read into rows; a line that is not one is skipped */
|
|
35
|
+
export function parsePs(text: string): PsRow[] {
|
|
36
|
+
const out: PsRow[] = []
|
|
37
|
+
for (const line of text.split('\n')) {
|
|
38
|
+
const m = /^\s*(\d+)\s+(\d+)\s+([\d.]+)\s+(.*)$/.exec(line)
|
|
39
|
+
if (m != null) out.push({ pid: Number(m[1]), ppid: Number(m[2]), cpu: Number(m[3]), args: m[4]!.trim() })
|
|
40
|
+
}
|
|
41
|
+
return out
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** a Claude Code process: the folder its session runs in, and its name */
|
|
45
|
+
export type SessionProc = { cwd: string; name: string }
|
|
46
|
+
|
|
47
|
+
/** `sk`: the lead is the toolkit's own work, which ends; outside sk, waiting lowers no load */
|
|
48
|
+
export type Lead = { pid: number; what: string; cpu: number; sk: boolean }
|
|
49
|
+
/** one user of the CPU: a repo, or a program outside every repo; `cpu` in % of one core */
|
|
50
|
+
export type UseGroup = { who: string; cpu: number; leads: Lead[]; sessions: { name: string; pid: number; cpu: number }[] }
|
|
51
|
+
|
|
52
|
+
const RUNTIMES = /^(bun|node|deno|python3?|ruby|tsx)$/
|
|
53
|
+
/** a shell or a wrapper (timeout, nice): never the command that leads the work under it */
|
|
54
|
+
const SHELLS = /^-?(sh|bash|zsh|fish|dash|timeout|gtimeout|nice|env|caffeinate)$/
|
|
55
|
+
/** the program a process runs: a macOS app by its bundle (its name has spaces, its helpers sit inside it); `(bun)` is
|
|
56
|
+
* how ps names one that is exiting */
|
|
57
|
+
const prog = (args: string): string => /\/([^/]+?)\.app\//.exec(args.split(/ --?\w/)[0] ?? '')?.[1] ?? basename(args.split(/\s+/)[0] ?? '').replace(/^\((.+)\)$/, '$1')
|
|
58
|
+
const isShell = (args: string): boolean => SHELLS.test(prog(args))
|
|
59
|
+
|
|
60
|
+
/** what a process runs, in a few words: `bun cli.ts shoot`, `chrome-headless-shell`, `WindowServer` */
|
|
61
|
+
export function describe(args: string): string {
|
|
62
|
+
const t = args.split(/\s+/).filter((x) => x !== '')
|
|
63
|
+
const head = prog(args)
|
|
64
|
+
const words = [head]
|
|
65
|
+
let i = 1
|
|
66
|
+
if (RUNTIMES.test(head)) {
|
|
67
|
+
while (i < t.length && t[i]!.startsWith('-')) i++
|
|
68
|
+
if (i < t.length) words.push(basename(t[i++]!))
|
|
69
|
+
}
|
|
70
|
+
const next = t[i]
|
|
71
|
+
if (next != null && /^[a-z][\w:-]{0,19}$/.test(next)) words.push(next)
|
|
72
|
+
return words.join(' ').slice(0, 48)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** the repo a path of the command names: a folder under `<home>/dev/`. A path into a published lib of the house
|
|
76
|
+
* (`packages/rvlib-…`) is the toolkit running for someone else, so it names `shipkit` only when nothing else does */
|
|
77
|
+
export function repoInArgs(args: string, home: string): string | null {
|
|
78
|
+
const re = new RegExp(`${home.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/dev/([\\w.-]+)(/[^\\s'"]*)?`, 'g')
|
|
79
|
+
let lib: string | null = null
|
|
80
|
+
for (const m of args.matchAll(re)) {
|
|
81
|
+
if (/^\/packages\/rvlib-/.test(m[2] ?? '')) lib ??= 'shipkit'
|
|
82
|
+
else return m[1]!
|
|
83
|
+
}
|
|
84
|
+
return lib
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** the repo a folder is in: its name under `<home>/dev/`, a worktree of it included, else the folder's own name */
|
|
88
|
+
export const repoOfDir = (cwd: string, home: string): string => {
|
|
89
|
+
const m = new RegExp(`^${home.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/dev/([\\w.-]+)`).exec(cwd)
|
|
90
|
+
return m?.[1] ?? basename(cwd)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** every process's CPU grouped by who it works for: the Claude session above it (its folder's repo), else the repo
|
|
94
|
+
* a path of its command or of a parent's names, else its program. `lead`: the command that started the work, the
|
|
95
|
+
* highest one under the session that is no shell, or the process that names the repo */
|
|
96
|
+
export function whoUses(rows: readonly PsRow[], sessions: ReadonlyMap<number, SessionProc>, o: { home: string; self?: number }): UseGroup[] {
|
|
97
|
+
const by = new Map(rows.map((r) => [r.pid, r]))
|
|
98
|
+
const groups = new Map<string, { cpu: number; leads: Map<number, Lead>; sessions: Map<number, { name: string; pid: number; cpu: number }> }>()
|
|
99
|
+
for (const row of rows) {
|
|
100
|
+
if (!(row.cpu > 0) || row.pid === o.self || /^\/?(bin\/)?ps -Axo/.test(row.args)) continue
|
|
101
|
+
let session: number | null = null
|
|
102
|
+
let named: { repo: string; at: PsRow } | null = null
|
|
103
|
+
let lead = row
|
|
104
|
+
let cur: PsRow | undefined = row
|
|
105
|
+
for (let depth = 0; cur != null && depth < 64; depth++) {
|
|
106
|
+
if (sessions.has(cur.pid)) {
|
|
107
|
+
session = cur.pid
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
if (named == null || named.repo === 'shipkit') {
|
|
111
|
+
const r = repoInArgs(cur.args, o.home)
|
|
112
|
+
if (r != null && (named == null || r !== 'shipkit')) named = { repo: r, at: cur }
|
|
113
|
+
}
|
|
114
|
+
if (!isShell(cur.args)) lead = cur
|
|
115
|
+
if (cur.ppid <= 1) break
|
|
116
|
+
cur = by.get(cur.ppid)
|
|
117
|
+
}
|
|
118
|
+
const s = session == null ? null : sessions.get(session)!
|
|
119
|
+
const who = s != null ? repoOfDir(s.cwd, o.home) : named?.repo ?? prog(row.args)
|
|
120
|
+
if (s == null) lead = named?.at ?? row
|
|
121
|
+
let g = groups.get(who)
|
|
122
|
+
if (g == null) groups.set(who, (g = { cpu: 0, leads: new Map(), sessions: new Map() }))
|
|
123
|
+
g.cpu += row.cpu
|
|
124
|
+
const l = g.leads.get(lead.pid) ?? { pid: lead.pid, what: describe(lead.args), cpu: 0, sk: lead.args.includes('/packages/rvlib-shipkit/') }
|
|
125
|
+
l.cpu += row.cpu
|
|
126
|
+
g.leads.set(lead.pid, l)
|
|
127
|
+
if (s != null && session != null) {
|
|
128
|
+
const e = g.sessions.get(session) ?? { name: s.name, pid: session, cpu: 0 }
|
|
129
|
+
e.cpu += row.cpu
|
|
130
|
+
g.sessions.set(session, e)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const desc = <T extends { cpu: number }>(a: T, b: T): number => b.cpu - a.cpu
|
|
134
|
+
return [...groups].map(([who, g]) => ({ who, cpu: g.cpu, leads: [...g.leads.values()].sort(desc), sessions: [...g.sessions.values()].sort(desc) })).sort(desc)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const pct = (n: number): string => `${Math.round(n)} %`
|
|
138
|
+
|
|
139
|
+
/** the users a waiting line names: the biggest few, the command that leads each big one */
|
|
140
|
+
export function whoWords(groups: readonly UseGroup[], n = 3): string {
|
|
141
|
+
const shown = groups.filter((g) => g.cpu >= 10).slice(0, n)
|
|
142
|
+
if (shown.length === 0) return 'no process holds 10 % of a core'
|
|
143
|
+
return shown.map((g) => `${g.who} ${pct(g.cpu)}${g.cpu >= 50 && g.leads[0] != null ? ` (${g.leads[0].what}, pid ${g.leads[0].pid})` : ''}`).join(', ')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** the table `sk capacity` prints: a line a user, its leading commands and its sessions */
|
|
147
|
+
export function whoLines(groups: readonly UseGroup[]): string[] {
|
|
148
|
+
const shown = groups.filter((g) => g.cpu >= 10).slice(0, 6)
|
|
149
|
+
if (shown.length === 0) return ['who uses the CPU: no process holds 10 % of a core']
|
|
150
|
+
return [
|
|
151
|
+
'who uses the CPU (ps, 100 % is one core):',
|
|
152
|
+
...shown.map((g) => {
|
|
153
|
+
const leads = g.leads.slice(0, 3).map((l) => `${l.what} (pid ${l.pid}) ${pct(l.cpu)}`).join(', ')
|
|
154
|
+
const ses = g.sessions.slice(0, 3).map((s) => `${s.name} ${pct(s.cpu)}`).join(', ')
|
|
155
|
+
return ` ${g.who} ${pct(g.cpu)}: ${leads}${ses === '' ? '' : `; session ${ses}`}`
|
|
156
|
+
}),
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export type Look = { m: MachineLoad; groups: UseGroup[] | null }
|
|
161
|
+
|
|
162
|
+
/** what remembers that a wait reached its bound, and who held the CPU then (a small file of the home dir) */
|
|
163
|
+
export type AdmitMemo = { read: () => string | null; write: (key: string | null) => void }
|
|
164
|
+
|
|
165
|
+
export type AdmitDeps = { look: () => Promise<Look>; now: () => number; sleep: (ms: number) => Promise<void>; say: (line: string) => void; boundMs: number; memo?: AdmitMemo; random?: () => number }
|
|
166
|
+
|
|
167
|
+
const secs = (ms: number): string => (ms >= 60_000 && ms % 60_000 === 0 ? `${ms / 60_000} min` : `${Math.round(ms / 1000)} s`)
|
|
168
|
+
|
|
169
|
+
/** the top user outside sk, as the memo keeps it, or null when sk's own work leads (it ends, so a wait helps) */
|
|
170
|
+
export function outsideTop(groups: readonly UseGroup[] | null): string | null {
|
|
171
|
+
const g = groups?.[0]
|
|
172
|
+
const lead = g?.leads[0]
|
|
173
|
+
return g == null || lead == null || lead.sk || g.cpu < 100 ? null : `${g.who}/${lead.pid}`
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** wait while the machine is full, a line every SAY_EVERY_MS naming who uses it; past `boundMs`, a WARN and run.
|
|
177
|
+
* A wait that reached its bound is remembered with the top user outside sk: while that user still leads, the next
|
|
178
|
+
* heavy command runs at once with the WARN, since waiting lowers no load sk does not own.
|
|
179
|
+
* `free`: it ran at once, silent; `waited`: the machine made room; `over`: it runs on a full machine */
|
|
180
|
+
export async function admit(what: string, d: AdmitDeps): Promise<'free' | 'waited' | 'over'> {
|
|
181
|
+
let l = await d.look()
|
|
182
|
+
if (!isFull(l.m)) {
|
|
183
|
+
d.memo?.write(null)
|
|
184
|
+
return 'free'
|
|
185
|
+
}
|
|
186
|
+
const top = outsideTop(l.groups)
|
|
187
|
+
const kept = d.memo?.read() ?? null
|
|
188
|
+
if (kept != null && kept !== top) d.memo?.write(null)
|
|
189
|
+
if (top != null && kept === top) {
|
|
190
|
+
d.say(`WARN the machine is full (${machineWords(l.m)}): ${whoWords(l.groups ?? [])}, who held it through the last wait's bound too; ${what} runs now, since waiting lowers no load sk does not own`)
|
|
191
|
+
return 'over'
|
|
192
|
+
}
|
|
193
|
+
const start = d.now()
|
|
194
|
+
let said = -Infinity
|
|
195
|
+
for (;;) {
|
|
196
|
+
const waited = d.now() - start
|
|
197
|
+
const who = l.groups == null ? '' : `: ${whoWords(l.groups)}`
|
|
198
|
+
if (waited >= d.boundMs) {
|
|
199
|
+
d.say(`WARN the machine stayed full for ${secs(d.boundMs)} (${machineWords(l.m)})${who}; ${what} runs anyway`)
|
|
200
|
+
d.memo?.write(outsideTop(l.groups))
|
|
201
|
+
return 'over'
|
|
202
|
+
}
|
|
203
|
+
if (waited - said >= SAY_EVERY_MS) {
|
|
204
|
+
said = waited
|
|
205
|
+
d.say(`waiting: the machine is full (${machineWords(l.m)})${who}; ${what} starts when it has room, ${secs(d.boundMs)} at most${waited > 0 ? `, ${secs(waited)} so far` : ' (run it in the background, never in a loop)'}`)
|
|
206
|
+
}
|
|
207
|
+
await d.sleep(Math.min(LOOK_EVERY_MS * (0.75 + (d.random ?? Math.random)() / 2), d.boundMs - waited))
|
|
208
|
+
l = await d.look()
|
|
209
|
+
if (!isFull(l.m)) {
|
|
210
|
+
d.memo?.write(null)
|
|
211
|
+
d.say(`ok: the machine has room again (${machineWords(l.m)}) after ${secs(d.now() - start)}: ${what} starts`)
|
|
212
|
+
return 'waited'
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** the bound a waiter takes: SHIPKIT_ADMIT_WAIT_S, else ADMIT_BOUND_S */
|
|
218
|
+
export function boundMs(env: Record<string, string | undefined> = process.env): number {
|
|
219
|
+
const v = env[ADMIT_WAIT_ENV]
|
|
220
|
+
const n = v == null || v === '' ? NaN : Number(v)
|
|
221
|
+
return (Number.isFinite(n) && n >= 0 ? n : ADMIT_BOUND_S) * 1000
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** a check that waits on a full machine before it runs (gate/check-runner.ts): a test tier, a browser check, the
|
|
225
|
+
* local PocketBase bench */
|
|
226
|
+
const HEAVY_CHECK = /^(test|smoke|e2e|shot)(:|$)|browser|^pb-playground(:|$)/
|
|
227
|
+
export const heavyCheck = (id: string): boolean => HEAVY_CHECK.test(id)
|
|
228
|
+
|
|
229
|
+
/** what a built in heavy line is called, `shot-still` for a still (heavy in a loop only), or null when it is light: a
|
|
230
|
+
* clip, sk smoke. `sk ci` waits inside the gate, before its first heavy check that misses the cache (heavyCheck) */
|
|
231
|
+
export function builtInHeavy(argv: readonly string[]): string | null {
|
|
232
|
+
const [cmd] = argv
|
|
233
|
+
if (cmd === 'shot') return argv.includes('--video') ? 'sk shot --video' : 'shot-still'
|
|
234
|
+
if (cmd === 'smoke') return 'sk smoke'
|
|
235
|
+
return null
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** the line `heavy` declares that this argv starts with: `trailer` matches `sk trailer …`, `assets gen` its own */
|
|
239
|
+
export function declaredHeavy(argv: readonly string[], heavy: readonly string[]): string | null {
|
|
240
|
+
for (const h of heavy) {
|
|
241
|
+
const words = h.trim().split(/\s+/)
|
|
242
|
+
if (words.length > 0 && words[0] !== '' && words.every((w, i) => argv[i] === w)) return `sk ${words.join(' ')}`
|
|
243
|
+
}
|
|
244
|
+
return null
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** why `heavy` in repo.config.ts is refused, or null when it holds */
|
|
248
|
+
export function heavyProblem(v: unknown): string | null {
|
|
249
|
+
if (v === undefined) return null
|
|
250
|
+
if (!Array.isArray(v) || v.some((x) => typeof x !== 'string' || x.trim() === '')) return `heavy is a list of sk command lines that wait while the machine is full, like ['trailer', 'assets gen'], got ${JSON.stringify(v)}`
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** the biggest user of the CPU in a few words, read again at most every 10 s in the background: what the hub's held
|
|
255
|
+
* line names. Never waits: the first call starts a read and answers null */
|
|
256
|
+
export function topUserWatch(read: () => Promise<UseGroup[]>, now: () => number = Date.now): () => string | null {
|
|
257
|
+
let value: string | null = null
|
|
258
|
+
let at = -Infinity
|
|
259
|
+
let reading = false
|
|
260
|
+
return () => {
|
|
261
|
+
if (!reading && now() - at >= 10_000) {
|
|
262
|
+
reading = true
|
|
263
|
+
at = now()
|
|
264
|
+
void read().then((g) => { value = g.some((x) => x.cpu >= 10) ? whoWords(g, 1) : null }, () => { value = null }).finally(() => { reading = false })
|
|
265
|
+
}
|
|
266
|
+
return value
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -12,7 +12,7 @@ export type AllowRow = { row: string; why: string }
|
|
|
12
12
|
|
|
13
13
|
const r = (row: string, why: string): AllowRow => ({ row, why })
|
|
14
14
|
|
|
15
|
-
const THREAD_VERBS = ['post', 'ask', 'propose', 'reply', 'update', 'fixed', 'working', 'seen', 'show', 'inbox', 'watch', 'take', 'add-view', 'withdraw', 'kinds', 'tag', 'reflect'] as const
|
|
15
|
+
const THREAD_VERBS = ['post', 'ask', 'propose', 'reply', 'update', 'fixed', 'working', 'seen', 'show', 'inbox', 'watch', 'take', 'add-view', 'withdraw', 'kinds', 'tag', 'reflect', 'rename', 'close'] as const
|
|
16
16
|
|
|
17
17
|
export const AGENT_ALLOW: readonly AllowRow[] = [
|
|
18
18
|
r('Bash(sk ci *)', 'the gate, every form: repairs and checks this repo only'),
|
|
@@ -62,10 +62,40 @@ export const OUT_SAMPLES: readonly { command: string; why: string }[] = [
|
|
|
62
62
|
// revoke ends a person's access too, more than a share: the owner's act, or his explicit order
|
|
63
63
|
...['advisors revoke Ada', 'advisors revoke --all', 'advisors people --remove Ada'].map((c) => ({ command: `sk ${c}`, why: "ends a person's access, the owner's act" })),
|
|
64
64
|
...['secret get x', 'secret account x', 'secret env x', 'secret set x', 'secret copy m', 'secret rm x', 'secret clip x', 'vault', 'vault status', 'vault destroy x', 'urls code x'].map((c) => ({ command: `sk ${c}`, why: 'prints or moves a secret' })),
|
|
65
|
-
...['db drop', 'media purge', 'media forget x', 'annex forget x', '
|
|
65
|
+
...['db drop', 'media purge', 'media forget x', 'annex forget x', 'tmp sweep', 'worktrees tidy', 'asks decline 1', 'time diet on'].map((c) => ({ command: `sk ${c}`, why: 'deletes or settles for the owner' })),
|
|
66
66
|
...['pm restart', 'pm uninstall', 'daemon', 'gp start x', 'gp stop x', 'gp restart x', 'global-processes start x', 'session start', 'session stop', 'session default L1'].map((c) => ({ command: `sk ${c}`, why: 'drives the machine' })),
|
|
67
67
|
]
|
|
68
68
|
|
|
69
|
+
/** commands past the sk ones that publish, rewrite a remote, delete or overwrite edits: a rule the owner allows for one
|
|
70
|
+
* of them warns on its card (review/blocked-object.ts), as OUT_SAMPLES does for sk */
|
|
71
|
+
const WIDE_RISKS: readonly { re: RegExp; why: string }[] = [
|
|
72
|
+
{ re: /^(?:npm|bun|pnpm|yarn) publish\b/, why: 'publishes' },
|
|
73
|
+
{ re: /^(?:bunx |npx )?wrangler (?:deploy|publish|pages deploy)\b/, why: 'publishes' },
|
|
74
|
+
{ re: /^gh (?:release create|pr merge)\b/, why: 'publishes' },
|
|
75
|
+
{ re: /^git push\b.*(?:\s--force\b|\s-f\b|\s--force-with-lease\b|\s\+\S)/, why: 'rewrites a remote' },
|
|
76
|
+
// the flag as -{2}hard: a rule that recognises the command is not one that runs it (core/hard-reset.ts reads this file)
|
|
77
|
+
{ re: /^git (?:reset -{2}hard|clean -\w*f|checkout -f|checkout -- \.|restore \.|switch --discard-changes)/, why: 'overwrites edits it did not make' },
|
|
78
|
+
{ re: /^(?:sudo )?rm\s/, why: 'deletes' },
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
/** the sample's words before its first placeholder argument: `sk secret get x` → `sk secret get` */
|
|
82
|
+
const stemOf = (command: string): { stem: string; cut: boolean } => {
|
|
83
|
+
const words = command.split(' ')
|
|
84
|
+
const at = words.findIndex((w, i) => i >= 2 && (/^(?:x|Ada|1|m|s1|L1|asset:logo)$/.test(w) || w.startsWith('--')))
|
|
85
|
+
return at === -1 ? { stem: command, cut: false } : { stem: words.slice(0, at).join(' '), cut: true }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** why one exact command is one no agent should run with no prompt, null when none says so: an sk command of
|
|
89
|
+
* OUT_SAMPLES (the cli answers to `shipkit` too), or a publish, a force push, a delete of any tool */
|
|
90
|
+
export function riskOf(command: string): string | null {
|
|
91
|
+
const c = command.trim().replace(/^shipkit /, 'sk ')
|
|
92
|
+
for (const s of OUT_SAMPLES) {
|
|
93
|
+
const { stem, cut } = stemOf(s.command)
|
|
94
|
+
if (c === s.command || c.startsWith(`${stem} `) || (!cut && c === stem)) return s.why
|
|
95
|
+
}
|
|
96
|
+
return WIDE_RISKS.find((r) => r.re.test(c))?.why ?? null
|
|
97
|
+
}
|
|
98
|
+
|
|
69
99
|
/** does a permission row of Claude Code allow this exact command, read the way its permissions page says.
|
|
70
100
|
* `Bash` alone allows every command, a legacy `x:*` reads as `x *` */
|
|
71
101
|
export function rowAllows(row: string, command: string): boolean {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// the marks a coding agent's session leaves in the shell it runs commands in, and ssh's own: a leaf, so any module may
|
|
2
|
+
// tell an agent's shell from the owner's without importing what reads secrets
|
|
3
|
+
|
|
4
|
+
/** variables a coding agent's session sets in the shell it runs commands in. CLAUDE_CONFIG_DIR is not one: an
|
|
5
|
+
* owner's own terminal may set it to pick an account */
|
|
6
|
+
export const AGENT_ENV = ['CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_PID', 'AI_AGENT', 'CODEX_SANDBOX', 'CODEX_THREAD_ID', 'GEMINI_CLI', 'CURSOR_AGENT']
|
|
7
|
+
/** variables ssh sets in the shell of a session it opened: none of an agent's marks travels through it */
|
|
8
|
+
export const SSH_ENV = ['SSH_TTY', 'SSH_CONNECTION', 'SSH_CLIENT']
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// the one writer of a Claude Code settings file's `permissions.allow`: SK054's repair and the owner's allow on a blocked
|
|
2
|
+
// card (review/blocked-object.ts) both go through it. It appends the missing rows in the file's own layout, takes out
|
|
3
|
+
// the retired ones, and leaves every other byte: a row a human added, its order, the deny list and the hooks stay
|
|
4
|
+
import { AGENT_ALLOW, RETIRED_ALLOW } from './agent-allow-policy.ts'
|
|
5
|
+
import { appendEdits, indentAt, insertPoint, parseSpans, removalSpans, splice, type Node } from './jsonc-spans.ts'
|
|
6
|
+
|
|
7
|
+
type Obj = Extract<Node, { kind: 'object' }>
|
|
8
|
+
|
|
9
|
+
/** the allow array of a settings tree, null when it has none; 'broken' when a key holds another kind */
|
|
10
|
+
function allowArray(root: Node): Extract<Node, { kind: 'array' }> | null | 'broken' {
|
|
11
|
+
if (root.kind !== 'object') return 'broken'
|
|
12
|
+
const perms = root.props.find((p) => p.key === 'permissions')
|
|
13
|
+
if (perms == null) return null
|
|
14
|
+
if (perms.value.kind !== 'object') return 'broken'
|
|
15
|
+
const allow = perms.value.props.find((p) => p.key === 'allow')
|
|
16
|
+
if (allow == null) return null
|
|
17
|
+
return allow.value.kind === 'array' ? allow.value : 'broken'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** the rows the settings text lacks, the retired rows it still holds, and the text with the retired ones taken out and
|
|
21
|
+
* the missing ones appended to `permissions.allow` in the file's own layout, every other byte kept; a file that is no
|
|
22
|
+
* object, or whose permissions or allow is of another kind, is 'broken' */
|
|
23
|
+
export function agentAllowRowsOf(
|
|
24
|
+
text: string | null,
|
|
25
|
+
rows: readonly string[] = AGENT_ALLOW.map((x) => x.row),
|
|
26
|
+
retired: readonly string[] = RETIRED_ALLOW,
|
|
27
|
+
): { missing: string[]; stale: string[]; text: string } | 'broken' {
|
|
28
|
+
let out = text
|
|
29
|
+
let stale: string[] = []
|
|
30
|
+
if (text != null && text.trim() !== '') {
|
|
31
|
+
let root: Node
|
|
32
|
+
try { root = parseSpans(text) } catch { return 'broken' }
|
|
33
|
+
const arr = allowArray(root)
|
|
34
|
+
if (arr === 'broken') return 'broken'
|
|
35
|
+
const gone = arr == null ? [] : arr.items.flatMap((n, i) => (n.kind === 'scalar' && retired.includes(n.value as string) ? [i] : []))
|
|
36
|
+
if (arr != null && gone.length > 0) {
|
|
37
|
+
stale = gone.map((i) => (arr.items[i] as { value: string }).value)
|
|
38
|
+
out = removalSpans(text, arr, gone).sort((a, b) => b[0] - a[0]).reduce((t, [s, e]) => t.slice(0, s) + t.slice(e), text)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const r = appendRows(out, rows)
|
|
42
|
+
return r === 'broken' ? r : { ...r, stale }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function appendRows(text: string | null, rows: readonly string[]): { missing: string[]; text: string } | 'broken' {
|
|
46
|
+
if (text == null || text.trim() === '') {
|
|
47
|
+
const body = rows.map((x) => ` ${JSON.stringify(x)}`).join(',\n')
|
|
48
|
+
return { missing: [...rows], text: `{\n "permissions": {\n "allow": [\n${body}\n ]\n }\n}\n` }
|
|
49
|
+
}
|
|
50
|
+
let root: Node
|
|
51
|
+
try { root = parseSpans(text) } catch { return 'broken' }
|
|
52
|
+
if (root.kind !== 'object') return 'broken'
|
|
53
|
+
const perms = root.props.find((p) => p.key === 'permissions')
|
|
54
|
+
if (perms != null && perms.value.kind !== 'object') return 'broken'
|
|
55
|
+
const allow = perms == null ? undefined : (perms.value as Obj).props.find((p) => p.key === 'allow')
|
|
56
|
+
if (allow != null && allow.value.kind !== 'array') return 'broken'
|
|
57
|
+
const have = new Set(allow == null || allow.value.kind !== 'array' ? [] : allow.value.items.map((n) => (n.kind === 'scalar' ? n.value : null)))
|
|
58
|
+
const missing = rows.filter((x) => !have.has(x))
|
|
59
|
+
if (missing.length === 0) return { missing, text }
|
|
60
|
+
const values = missing.map((x) => JSON.stringify(x))
|
|
61
|
+
// the indent step the file uses, read from its first key: two spaces where it has none
|
|
62
|
+
const unit = root.props[0] == null ? ' ' : indentAt(text, root.props[0].keyStart) || ' '
|
|
63
|
+
if (allow != null && allow.value.kind === 'array') {
|
|
64
|
+
return { missing, text: splice(text, appendEdits(text, allow.value, values, `${indentAt(text, allow.keyStart)}${unit}`)) }
|
|
65
|
+
}
|
|
66
|
+
const into = perms == null ? root : (perms.value as Obj)
|
|
67
|
+
const outer = perms == null ? '' : indentAt(text, perms.keyStart)
|
|
68
|
+
const p = insertPoint(text, into, `${outer}${unit}`)
|
|
69
|
+
const list = (at: string): string => `[\n${values.map((v) => `${at}${unit}${v}`).join(',\n')}\n${at}]`
|
|
70
|
+
const block = perms == null ? `"permissions": {\n${p.indent}${unit}"allow": ${list(`${p.indent}${unit}`)}\n${p.indent}}` : `"allow": ${list(p.indent)}`
|
|
71
|
+
const close = into.props.length === 0 ? `\n${outer}` : ''
|
|
72
|
+
const edits = [{ at: p.at, put: `\n${p.indent}${block}${close}` }, ...(p.comma != null ? [{ at: p.comma, put: ',' }] : [])]
|
|
73
|
+
return { missing, text: splice(text, edits) }
|
|
74
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
// WHICH files are check files, and what they are called, from paths
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
// WHICH files are check files, and what they are called, from paths alone. A check that must know the repo's check
|
|
2
|
+
// files (SK019, SK020) reads them through its context and stays cached on what it read; gate/discover-checks.ts walks
|
|
3
|
+
// the disk with the same rules.
|
|
4
|
+
import { basename, join } from 'path'
|
|
5
|
+
import type { ScanCtx } from './check-ctx.ts'
|
|
6
|
+
|
|
7
|
+
/** the toolkit's own built-in check files, under its `src/checks/`. In a repo the suffix is a retired shape that
|
|
8
|
+
* discovery refuses: a repo check is a unit file */
|
|
7
9
|
export const CHECK_SUFFIX = '.check.ts'
|
|
8
|
-
/** the unit file: a check, a global process or a widget, by its default
|
|
9
|
-
* export (shipkit-files.ts). Discovery reads both suffixes, and will later
|
|
10
|
-
* read this one alone */
|
|
10
|
+
/** the unit file: a check, a global process or a widget, by its default export (shipkit-files.ts) */
|
|
11
11
|
export const UNIT_SUFFIX = '.shipkit.ts'
|
|
12
|
+
/** a unit file named for the check it holds */
|
|
13
|
+
export const CHECK_UNIT_SUFFIX = `.check${UNIT_SUFFIX}`
|
|
12
14
|
|
|
13
15
|
/** the name a unit file answers to when it declares no id: its basename,
|
|
14
16
|
* `.check` dropped too, so `x.check.shipkit.ts` is `x` */
|
|
@@ -18,102 +20,13 @@ export const unitBase = (file: string): string => basename(file).slice(0, -UNIT_
|
|
|
18
20
|
* output, scratch, and templates meant for other repos */
|
|
19
21
|
export const SKIPPED_DIRS: ReadonlySet<string> = new Set(['node_modules', 'dist', 'tmp', 'references'])
|
|
20
22
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
export function isCheckFilePath(rel: string): boolean {
|
|
24
|
-
if (!rel.endsWith(CHECK_SUFFIX)) return false
|
|
25
|
-
const dirs = rel.split('/').slice(0, -1)
|
|
26
|
-
return dirs.every((d) => !SKIPPED_DIRS.has(d) && !d.startsWith('.'))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// a declaration only the legacy script shape writes, at the top level. A
|
|
30
|
-
// comment or an indented line never matches, so a check file that MENTIONS
|
|
31
|
-
// the old shape stays a check file
|
|
32
|
-
const LEGACY_DECL_RE = /^[ \t]*export\s+const\s+(blocking|inputs|ttl|never|gate)\b/m
|
|
33
|
-
// a default export that can be the check object: a call, a literal or a
|
|
34
|
-
// name. A function or a class is a script's own business, never a check
|
|
35
|
-
const DEFAULT_OBJECT_RE = /^[ \t]*export\s+default\s+(?!(async\s+)?function\b|class\b)\S/m
|
|
36
|
-
|
|
37
|
-
/** is this `*.check.ts` source a legacy check SCRIPT rather than a check
|
|
38
|
-
* file? Read, never imported: a script runs its whole body on import. It is
|
|
39
|
-
* legacy when it carries a legacy declaration, or when nothing it exports by
|
|
40
|
-
* default could be a check object. */
|
|
41
|
-
export function isLegacyCheckSource(src: string): boolean {
|
|
42
|
-
return LEGACY_DECL_RE.test(src) || !DEFAULT_OBJECT_RE.test(src)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** the name a repo file answers to when it declares no id: its basename, or
|
|
46
|
-
* its repo-relative path when another `*.check.ts` shares that basename.
|
|
47
|
-
* Counted over EVERY file with the suffix, legacy scripts included, so both
|
|
48
|
-
* readers give one file one name. */
|
|
49
|
-
export function fallbackNames(root: string, files: string[]): Map<string, string> {
|
|
50
|
-
const base = (f: string): string => basename(f).slice(0, -CHECK_SUFFIX.length)
|
|
51
|
-
const seen = new Map<string, number>()
|
|
52
|
-
for (const f of files) seen.set(base(f), (seen.get(base(f)) ?? 0) + 1)
|
|
53
|
-
return new Map(files.map((f) => [f, (seen.get(base(f)) ?? 0) > 1 ? relative(root, f).replace(/\\/g, '/').slice(0, -CHECK_SUFFIX.length) : base(f)]))
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type LegacyCheck = {
|
|
57
|
-
/** absolute path to the script */
|
|
58
|
-
path: string
|
|
59
|
-
/** display + cache name — file base, disambiguated by relative path on collision */
|
|
60
|
-
name: string
|
|
61
|
-
/** `export const blocking = true | false`, read statically. null = the file
|
|
62
|
-
* never said, which is an error: a check that silently does not block is
|
|
63
|
-
* the failure nobody sees. */
|
|
64
|
-
blocking: boolean | null
|
|
65
|
-
/** `export const inputs = ['a', 'b']`, read statically — the repo-relative
|
|
66
|
-
* paths this check reads. Declares the CONTENT population for the ledger
|
|
67
|
-
* key layer (ledger/git-key.ts). null = never cached, which is the safe
|
|
68
|
-
* default and the whole point of default deny. */
|
|
69
|
-
inputs: string[] | null
|
|
70
|
-
/** `export const ttl = '24h'`, read statically — declares the WORLD
|
|
71
|
-
* population: this check probes something no file on disk describes. */
|
|
72
|
-
ttl: string | null
|
|
73
|
-
/** `export const never = 'why'`, read statically — a DECIDED never
|
|
74
|
-
* cacheable, which takes the check off the burn-down list. */
|
|
75
|
-
never: string | null
|
|
76
|
-
/** `export const gate = false`, read statically — this check is NOT part of
|
|
77
|
-
* `shipkit ci`. `ci` answers "is my change good"; a check that answers
|
|
78
|
-
* something else, and that can sit red for months without anything being
|
|
79
|
-
* wrong, does not belong in the answer. `shipkit check` still runs it.
|
|
80
|
-
* Default true: a check is in the gate unless it opts out by name. */
|
|
81
|
-
gate: boolean
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// read without importing: checks run as subprocesses, and discovery must stay
|
|
85
|
-
// pure-fs. `export const blocking = true` (or false), nothing cleverer.
|
|
86
|
-
// the tail takes what a formatter on its defaults writes: it terminates every
|
|
87
|
-
// statement, so a reader that refuses a semicolon refuses a formatted file.
|
|
88
|
-
const TAIL = String.raw`(?:\s+as\s+const)?\s*;?\s*$`
|
|
89
|
-
const BLOCKING_RE = new RegExp(String.raw`^\s*export\s+const\s+blocking\s*(?::\s*boolean\s*)?=\s*(true|false)` + TAIL, 'm')
|
|
90
|
-
// `export const inputs = ['a', 'b']`, single or multi line. Anything cleverer
|
|
91
|
-
// (a computed list, a spread) is deliberately unreadable here and lands as no
|
|
92
|
-
// declaration, which means never cached: a scanner guessing at a program is
|
|
93
|
-
// how a key comes to describe files the check does not read.
|
|
94
|
-
const INPUTS_RE = /^\s*export\s+const\s+inputs\s*(?::[^=]*)?=\s*\[([^\]]*)\]/m
|
|
95
|
-
const TTL_RE = /^\s*export\s+const\s+ttl\s*(?::\s*string\s*)?=\s*['"]([^'"]+)['"]/m
|
|
96
|
-
const NEVER_RE = /^\s*export\s+const\s+never\s*(?::\s*string\s*)?=\s*['"]([^'"]+)['"]/m
|
|
97
|
-
// `export const gate = false` takes a check out of `shipkit ci`. Only the
|
|
98
|
-
// literal false opts out: anything unreadable stays in the gate, because a
|
|
99
|
-
// scanner that guesses its way to SKIPPING a check is how coverage disappears
|
|
100
|
-
const GATE_RE = new RegExp(String.raw`^\s*export\s+const\s+gate\s*(?::\s*boolean\s*)?=\s*false` + TAIL, 'm')
|
|
101
|
-
const STRING_ITEM_RE = /['"]([^'"]+)['"]/g
|
|
23
|
+
/** no dir on the way that the walk skips */
|
|
24
|
+
const walkedPath = (rel: string): boolean => rel.split('/').slice(0, -1).every((d) => !SKIPPED_DIRS.has(d) && !d.startsWith('.'))
|
|
102
25
|
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
export function
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const items = im == null ? [] : [...im[1]!.matchAll(STRING_ITEM_RE)].map((x) => x[1]!)
|
|
110
|
-
return {
|
|
111
|
-
path,
|
|
112
|
-
name,
|
|
113
|
-
blocking: m == null ? null : m[1] === 'true',
|
|
114
|
-
inputs: items.length > 0 ? items : null,
|
|
115
|
-
ttl: src.match(TTL_RE)?.[1] ?? null,
|
|
116
|
-
never: src.match(NEVER_RE)?.[1] ?? null,
|
|
117
|
-
gate: src.match(GATE_RE) == null,
|
|
118
|
-
}
|
|
26
|
+
/** every check unit file the repo carries, as discovery would find it, with its source. Listed through `c.list`,
|
|
27
|
+
* so it is what git sees: a gitignored file is no declaration of this repo */
|
|
28
|
+
export function repoCheckUnits(d: Pick<ScanCtx, 'root' | 'list' | 'read'>): { rel: string; abs: string; src: string | null }[] {
|
|
29
|
+
return d.list(`**/*${CHECK_UNIT_SUFFIX}`)
|
|
30
|
+
.filter(walkedPath)
|
|
31
|
+
.map((rel) => ({ rel, abs: join(d.root, rel), src: d.read(rel) }))
|
|
119
32
|
}
|
package/src/core/code-lines.ts
CHANGED
|
@@ -6,8 +6,21 @@
|
|
|
6
6
|
// punctuator or a keyword like `return`); a miss can open a false comment, so
|
|
7
7
|
// a guard that must never go blind also reads the raw line (core/hard-reset.ts).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const
|
|
9
|
+
const PUNCT = new Set('(,=:[!&|?{};+-*%<>~^')
|
|
10
|
+
const KEYWORDS = new Set(['return', 'typeof', 'case', 'in', 'of', 'yield', 'await', 'void', 'delete', 'throw', 'else', 'do', 'instanceof', 'new'])
|
|
11
|
+
const isWord = (c: number): boolean => (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c === 95
|
|
12
|
+
const isSpace = (c: number): boolean => c === 32 || c === 9 || c === 13 || c === 11 || c === 12 || c === 160 || c === 0xfeff || (c >= 0x2000 && c <= 0x200a) || c === 0x2028 || c === 0x2029 || c === 0x202f || c === 0x205f || c === 0x3000 || c === 0x1680
|
|
13
|
+
|
|
14
|
+
/** whether the code before a `/` (`head` then `line` up to `end`) ends where a regex literal starts rather than a division */
|
|
15
|
+
function regexBefore(head: string, line: string, from: number, end: number): boolean {
|
|
16
|
+
const s = head + line.slice(from, end)
|
|
17
|
+
let j = s.length - 1
|
|
18
|
+
while (j >= 0 && isSpace(s.charCodeAt(j))) j--
|
|
19
|
+
if (j < 0 || PUNCT.has(s[j]!)) return true
|
|
20
|
+
let k = j
|
|
21
|
+
while (k >= 0 && isWord(s.charCodeAt(k))) k--
|
|
22
|
+
return k < j && KEYWORDS.has(s.slice(k + 1, j + 1))
|
|
23
|
+
}
|
|
11
24
|
|
|
12
25
|
export function codeLines(src: string): string[] {
|
|
13
26
|
const out: string[] = []
|
|
@@ -15,35 +28,37 @@ export function codeLines(src: string): string[] {
|
|
|
15
28
|
let inClass = false
|
|
16
29
|
for (const line of src.split('\n')) {
|
|
17
30
|
if (state === "'" || state === '"' || state === 'regex') state = 'code'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
// kept = head + line.slice(from, i): runs of the line outside block comments
|
|
32
|
+
let head = ''
|
|
33
|
+
let from = 0
|
|
34
|
+
let i = 0
|
|
35
|
+
const n = line.length
|
|
36
|
+
for (; i < n; i++) {
|
|
37
|
+
const c = line.charCodeAt(i)
|
|
22
38
|
if (state === 'block') {
|
|
23
|
-
if (c ===
|
|
39
|
+
if (c === 42 && line.charCodeAt(i + 1) === 47) { state = 'code'; i++; from = i + 1 }
|
|
24
40
|
continue
|
|
25
41
|
}
|
|
26
42
|
if (state === 'regex') {
|
|
27
|
-
|
|
28
|
-
if (c ===
|
|
29
|
-
else if (c ===
|
|
30
|
-
else if (c ===
|
|
31
|
-
else if (c === '/' && !inClass) state = 'code'
|
|
43
|
+
if (c === 92) i++
|
|
44
|
+
else if (c === 91) inClass = true
|
|
45
|
+
else if (c === 93) inClass = false
|
|
46
|
+
else if (c === 47 && !inClass) state = 'code'
|
|
32
47
|
continue
|
|
33
48
|
}
|
|
34
49
|
if (state !== 'code') {
|
|
35
|
-
|
|
36
|
-
if (c ===
|
|
37
|
-
else if (c === state) state = 'code'
|
|
50
|
+
if (c === 92) i++
|
|
51
|
+
else if (c === state.charCodeAt(0)) state = 'code'
|
|
38
52
|
continue
|
|
39
53
|
}
|
|
40
|
-
if (c ===
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
if (c === 47) {
|
|
55
|
+
const next = line.charCodeAt(i + 1)
|
|
56
|
+
if (next === 47) break
|
|
57
|
+
if (next === 42) { head += line.slice(from, i); state = 'block'; i++; continue }
|
|
58
|
+
if (regexBefore(head, line, from, i)) { state = 'regex'; inClass = false; continue }
|
|
59
|
+
} else if (c === 39 || c === 34 || c === 96) state = c === 39 ? "'" : c === 34 ? '"' : '`'
|
|
45
60
|
}
|
|
46
|
-
out.push(
|
|
61
|
+
out.push(state === 'block' ? head : head + line.slice(from, Math.min(i, n)))
|
|
47
62
|
}
|
|
48
63
|
return out
|
|
49
64
|
}
|