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,81 @@
|
|
|
1
|
+
// the users' port's own folder (wiki tools/shipkit/advisors.md, Who calls): `users/` beside the owner's store,
|
|
2
|
+
// everything the port writes: password hashes, a code's claim, sessions, the page's token key, where each person is,
|
|
3
|
+
// their read cursors, the files staged and the files that wait for the owner's decision. Who may sign in is read from
|
|
4
|
+
// the owner's store at each request. The one constraint a reader breaks first: nothing here mints a login or an
|
|
5
|
+
// invite's code (an invite does, login.ts), and nothing here mails: a reset asked is parked for the daemon's job
|
|
6
|
+
import { randomBytes } from 'node:crypto'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { getJson, type Bucket, type Bytes } from './edge/bucket.ts'
|
|
9
|
+
import { KEYS, type SignInList } from './edge/types.ts'
|
|
10
|
+
import { parkReset, sha256, spend } from './login.ts'
|
|
11
|
+
import { advisorsDir, granted, isLive, readState, RESETS_KEPT, withState, type Advisor, type OwnerState } from './owner-store.ts'
|
|
12
|
+
|
|
13
|
+
/** the users' port's folder in the owner's advisors folder */
|
|
14
|
+
export const usersDir = (dir = advisorsDir()): string => join(dir, 'users')
|
|
15
|
+
|
|
16
|
+
/** the users' port, below the vault's ports (4792, 4793, 4794) */
|
|
17
|
+
export const USERS_PORT = 4791
|
|
18
|
+
|
|
19
|
+
export const usersPort = (): number => {
|
|
20
|
+
const env = Number(process.env.SHIPKIT_ADVISORS_PORT)
|
|
21
|
+
return Number.isInteger(env) && env > 0 ? env : USERS_PORT
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** each person who may sign in now, by email: a live grant, a login; the code's hash and end, the end of their last
|
|
25
|
+
* grant (the shape edge/sign-in.ts reads) */
|
|
26
|
+
export function liveLogins(s: OwnerState, now: Date): SignInList {
|
|
27
|
+
const live = granted(s, now)
|
|
28
|
+
const out: SignInList = {}
|
|
29
|
+
for (const a of s.advisors) {
|
|
30
|
+
if (!live.has(a.id) || a.login === undefined) continue
|
|
31
|
+
const until = [...s.shares, ...s.access].filter((x) => x.advisor === a.id && isLive(x, now)).map((x) => x.expires).sort().at(-1)!
|
|
32
|
+
const r = a.login.reset
|
|
33
|
+
out[a.email] = { gen: a.login.gen, code: sha256(a.login.code), codeUntil: a.login.codeUntil, until, ...(r !== undefined ? { reset: { gen: r.gen, code: sha256(r.code), codeUntil: r.codeUntil } } : {}) }
|
|
34
|
+
}
|
|
35
|
+
return out
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** a sign in that set a password with a code: the code of its generation is spent, or the reset it came from is the
|
|
39
|
+
* login now, the owner's store says so (login.ts spend: an invite then sends no code that cannot work) */
|
|
40
|
+
export async function markSpent(dir: string, users: Bucket, email: string, now = new Date()): Promise<void> {
|
|
41
|
+
const kept = await getJson<{ gen?: unknown }>(users, KEYS.password(sha256(email))).catch(() => null)
|
|
42
|
+
if (typeof kept?.gen !== 'number') return
|
|
43
|
+
const gen = kept.gen
|
|
44
|
+
withState(dir, (s) => {
|
|
45
|
+
const a = s.advisors.find((x) => x.email === email)
|
|
46
|
+
if (a !== undefined) spend(a, gen, now)
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** the resets asked over all people in an hour, past which an ask is dropped: the mails of the house's one key stay few */
|
|
51
|
+
export const RESETS_AN_HOUR = 30
|
|
52
|
+
|
|
53
|
+
/** a reset asked at the sign in for `email`: a person with a live grant gets the ask on their profile, which the
|
|
54
|
+
* daemon's job mails (invite-send.ts sendResets), with the code already parked while it lives, else the next generation
|
|
55
|
+
* parked (login.ts parkReset), so a stranger's ask never ends a code that was mailed; any other email, or past
|
|
56
|
+
* RESETS_AN_HOUR, nothing. The store is read without its lock first: only a listed person's ask writes it */
|
|
57
|
+
export function askedReset(dir: string, email: string, now: Date): void {
|
|
58
|
+
const live = (s: OwnerState): Advisor | null => {
|
|
59
|
+
const a = s.advisors.find((x) => x.email === email)
|
|
60
|
+
return a === undefined || a.login === undefined || s.host === null || !granted(s, now).has(a.id) ? null : a
|
|
61
|
+
}
|
|
62
|
+
const seen = readState(dir)
|
|
63
|
+
const hour = seen.advisors.flatMap((a) => a.resets ?? []).filter((r) => Date.parse(r.at) > now.getTime() - 3_600_000).length
|
|
64
|
+
if (live(seen) === null || hour >= RESETS_AN_HOUR) return
|
|
65
|
+
withState(dir, (s) => {
|
|
66
|
+
const a = live(s)
|
|
67
|
+
if (a === null) return
|
|
68
|
+
const parked = a.login!.reset
|
|
69
|
+
if ((parked === undefined || Date.parse(parked.codeUntil) <= now.getTime()) && parkReset(s, a, now) === null) return
|
|
70
|
+
a.resets = [...(a.resets ?? []), { at: now.toISOString() }].slice(-RESETS_KEPT)
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** the key of the page's write tokens, made once */
|
|
75
|
+
export async function tokenKey(users: Bucket): Promise<Bytes> {
|
|
76
|
+
const k = await users.get(KEYS.csrf)
|
|
77
|
+
if (k !== null) return k
|
|
78
|
+
const made = new Uint8Array(randomBytes(32)) as Bytes
|
|
79
|
+
await users.put(KEYS.csrf, made)
|
|
80
|
+
return made
|
|
81
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// the classifier's refusals, read from the agent time index the daemon already keeps (store.ts), each onto its card
|
|
2
|
+
// (review/blocked-object.ts). No new reader of the transcripts: the pass reads the index rows written since its last
|
|
3
|
+
// look, by rowid, a range of the primary key; a refusal whose result landed after its call's row was written is
|
|
4
|
+
// caught by the ids kept open from the look before.
|
|
5
|
+
// The one constraint a reader breaks first: a refusal is the classifier's verdict alone. « gave no verdict » is a
|
|
6
|
+
// failure of the check that the agent retries, a « no » of the owner on a prompt is his own answer, a hook is the
|
|
7
|
+
// repo's own guard: none of them is a card
|
|
8
|
+
import type { Database } from 'bun:sqlite'
|
|
9
|
+
import { closeSync, openSync, readFileSync, readSync, statSync } from 'fs'
|
|
10
|
+
import { refusalOf } from './refused.ts'
|
|
11
|
+
import { laneNameOf } from './lane-name.ts'
|
|
12
|
+
|
|
13
|
+
/** the one form of a classifier's refusal; the « gave no verdict » form starts otherwise */
|
|
14
|
+
export const CLASSIFIER_REFUSAL = 'Permission for this action was denied by the Claude Code auto mode classifier'
|
|
15
|
+
|
|
16
|
+
/** the refusal's reason line when this call's result is the classifier's refusal of a Bash command, else null */
|
|
17
|
+
export function classifierRefusal(c: { tool: string; outcome: string | null; why: string }): { reason: string } | null {
|
|
18
|
+
if (c.tool !== 'Bash' || c.outcome !== 'blocked' || !c.why.startsWith(CLASSIFIER_REFUSAL)) return null
|
|
19
|
+
return { reason: refusalOf('blocked', c.why).reason }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FoundRefusal {
|
|
23
|
+
call: string
|
|
24
|
+
at: number
|
|
25
|
+
command: string
|
|
26
|
+
/** the index keeps a long command's head and tail alone */
|
|
27
|
+
clipped: boolean
|
|
28
|
+
reason: string
|
|
29
|
+
project: string
|
|
30
|
+
session: string
|
|
31
|
+
/** '' for a session's own transcript, the sub-agent's file name for a lane */
|
|
32
|
+
agent: string
|
|
33
|
+
path: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const CURSOR = 'blocked cursor'
|
|
37
|
+
/** a call still open this long after it started is let go: its session ended with it in flight */
|
|
38
|
+
const OPEN_MS = 60 * 60_000
|
|
39
|
+
/** a refusal older than this when first read is history, never a card: a transcript indexed again (a rebuild, a file
|
|
40
|
+
* the index never saw) brings its old calls back under new rowids, and the first look after a restart reads this far */
|
|
41
|
+
export const LIVE_MS = 15 * 60_000
|
|
42
|
+
/** clipMiddle in reflect/transcript.ts keeps 2 × 400 characters of a longer command */
|
|
43
|
+
const CLIP_AT = 800
|
|
44
|
+
|
|
45
|
+
type Cursor = { rowid: number; open: string[] }
|
|
46
|
+
|
|
47
|
+
type Row = { rowid: number; file_id: number; id: string; start: number; end: number | null; tool: string; cmd: string; outcome: string | null; why: string; project: string; session: string; agent: string; path: string }
|
|
48
|
+
|
|
49
|
+
const SELECT = 'select c.rowid as rowid, c.file_id, c.id, c.start, c.end, c.tool, c.cmd, c.outcome, c.why, f.project, f.session, f.agent, f.path from time_calls c join time_files f on f.id = c.file_id'
|
|
50
|
+
|
|
51
|
+
/** the session moved on past a refusal: a prompt came after it in its transcript, or the same command ran since */
|
|
52
|
+
function movedOn(db: Database, r: Row, at: number): boolean {
|
|
53
|
+
if (db.query<{ n: number }, [number, number]>('select 1 as n from time_prompts where file_id = ? and at > ? limit 1').get(r.file_id, at) != null) return true
|
|
54
|
+
return db.query<{ n: number }, [number, number, string]>("select 1 as n from time_calls where file_id = ? and start > ? and tool = 'Bash' and cmd = ? and outcome = 'ok' limit 1").get(r.file_id, r.start, r.cmd) != null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** the live refusals the index holds since the last look, and the cursor moved past them: one read the first time
|
|
58
|
+
* within LIVE_MS of now, and not followed in its transcript by the session moving on */
|
|
59
|
+
export function newRefusals(db: Database, now = Date.now()): FoundRefusal[] {
|
|
60
|
+
const meta = db.query<{ value: string }, [string]>('select value from time_meta where key = ?').get(CURSOR)
|
|
61
|
+
const was: Cursor | null = meta == null ? null : (JSON.parse(meta.value) as Cursor)
|
|
62
|
+
const top = db.query<{ m: number | null }, []>('select max(rowid) as m from time_calls').get()?.m ?? 0
|
|
63
|
+
const from = was?.rowid ?? 0
|
|
64
|
+
const rows = was === null ? db.query<Row, [number, number]>(`${SELECT} where c.rowid > ? and c.tool = 'Bash' and c.start >= ?`).all(Math.max(0, top - 50_000), now - LIVE_MS) : db.query<Row, [number]>(`${SELECT} where c.rowid > ? and c.tool = 'Bash'`).all(from)
|
|
65
|
+
const again = (was?.open ?? []).length === 0 ? [] : db.query<Row, string[]>(`${SELECT} where c.id in (${was!.open.map(() => '?').join(',')})`).all(...was!.open)
|
|
66
|
+
const seen = new Set<string>()
|
|
67
|
+
const found: FoundRefusal[] = []
|
|
68
|
+
for (const r of [...again, ...rows]) {
|
|
69
|
+
if (seen.has(r.id)) continue
|
|
70
|
+
seen.add(r.id)
|
|
71
|
+
const refused = classifierRefusal(r)
|
|
72
|
+
if (refused === null) continue
|
|
73
|
+
const at = r.end ?? r.start
|
|
74
|
+
if (at < now - LIVE_MS || movedOn(db, r, at)) continue
|
|
75
|
+
found.push({ call: r.id, at: r.start, command: r.cmd, clipped: r.cmd.length >= CLIP_AT && r.cmd.includes('\n'), reason: refused.reason, project: r.project, session: r.session, agent: r.agent, path: r.path })
|
|
76
|
+
}
|
|
77
|
+
const open = [...again, ...rows].filter((r) => r.end === null && r.start >= now - OPEN_MS).map((r) => r.id)
|
|
78
|
+
const next: Cursor = { rowid: Math.max(from, top, ...rows.map((r) => r.rowid)), open: [...new Set(open)] }
|
|
79
|
+
db.query('insert into time_meta (key, value) values (?, ?) on conflict(key) do update set value = excluded.value').run(CURSOR, JSON.stringify(next))
|
|
80
|
+
return found
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** the house repo a transcript's project folder is in: its own folder, a worktree of it under `.claude/worktrees/`, or a
|
|
84
|
+
* folder inside it, the longest match winning; null for a project of no house repo */
|
|
85
|
+
export function repoOfTranscript(project: string, repos: readonly { name: string; path: string }[]): { name: string; path: string } | null {
|
|
86
|
+
const slug = (p: string): string => p.replace(/[^a-zA-Z0-9]/g, '-')
|
|
87
|
+
let best: { name: string; path: string } | null = null
|
|
88
|
+
for (const r of repos) {
|
|
89
|
+
const s = slug(r.path)
|
|
90
|
+
const hit = project === s || project.startsWith(`${s}--claude-worktrees-`) || project.startsWith(`${s}-`)
|
|
91
|
+
if (hit && (best === null || s.length > slug(best.path).length)) best = r
|
|
92
|
+
}
|
|
93
|
+
return best
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** a lane's name from the description its session gave it (its transcript's meta file), null for a session's own */
|
|
97
|
+
export function laneOfTranscript(path: string, agent: string): string | null {
|
|
98
|
+
if (agent === '') return null
|
|
99
|
+
try {
|
|
100
|
+
const meta = JSON.parse(readFileSync(path.replace(/\.jsonl$/, '.meta.json'), 'utf8')) as { description?: unknown }
|
|
101
|
+
return typeof meta.description === 'string' ? laneNameOf(meta.description) : null
|
|
102
|
+
} catch {
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** what one pass did, and its cost: `ms` the whole pass, `scanMs` the read of the index alone */
|
|
108
|
+
export type BlockedPass = { refusals: number; counted: number; opened: number; skipped: number; ms: number; scanMs: number }
|
|
109
|
+
|
|
110
|
+
/** one pass: the index rows since the last look, each refusal onto its card in the repo its session works in; `label`
|
|
111
|
+
* names a session as `sk session` prints it */
|
|
112
|
+
export async function blockedPass(db: Database, repos: readonly { name: string; path: string }[], o: { label?: (session: string) => Promise<string>; now?: Date; printErr?: (l: string) => void } = {}): Promise<BlockedPass> {
|
|
113
|
+
const t0 = performance.now()
|
|
114
|
+
const found = newRefusals(db, o.now?.getTime())
|
|
115
|
+
const scanMs = performance.now() - t0
|
|
116
|
+
const out: BlockedPass = { refusals: found.length, counted: 0, opened: 0, skipped: 0, ms: 0, scanMs }
|
|
117
|
+
if (found.length > 0) {
|
|
118
|
+
const { recordRefusal } = await import('../review/blocked-object.ts')
|
|
119
|
+
const { repoNameOf } = await import('./registry.ts')
|
|
120
|
+
for (const f of found) {
|
|
121
|
+
const repo = repoOfTranscript(f.project, repos)
|
|
122
|
+
if (repo === null) {
|
|
123
|
+
out.skipped++
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const label = (await o.label?.(f.session).catch(() => null)) ?? `${repo.name} session ${f.session.slice(0, 8)}`
|
|
128
|
+
const r = await recordRefusal(repo.path, repoNameOf(repo.path), f.command, { call: f.call, at: f.at, session: f.session, lane: laneOfTranscript(f.path, f.agent), label, reason: f.reason, clipped: f.clipped }, o.now)
|
|
129
|
+
if (r.counted) out.counted++
|
|
130
|
+
if (r.opened) out.opened++
|
|
131
|
+
} catch (e) {
|
|
132
|
+
o.printErr?.(`WARN blocked card of ${repo.name}: ${(e as Error).message}`)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
out.ms = performance.now() - t0
|
|
137
|
+
return out
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** the daemon's look between its passes: the bytes each live transcript grew by since the last look, searched for the
|
|
141
|
+
* refusal's words. A file seen the first time starts at its end; the pass reads the index, which misses nothing */
|
|
142
|
+
export class RefusalTail {
|
|
143
|
+
private offsets = new Map<string, number>()
|
|
144
|
+
|
|
145
|
+
/** whether one of these files grew with a refusal in it */
|
|
146
|
+
saw(paths: readonly string[]): boolean {
|
|
147
|
+
let hit = false
|
|
148
|
+
const keep = new Set(paths)
|
|
149
|
+
for (const p of [...this.offsets.keys()]) if (!keep.has(p)) this.offsets.delete(p)
|
|
150
|
+
for (const p of paths) {
|
|
151
|
+
let size: number
|
|
152
|
+
try {
|
|
153
|
+
size = statSync(p).size
|
|
154
|
+
} catch {
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
const at = this.offsets.get(p)
|
|
158
|
+
this.offsets.set(p, size)
|
|
159
|
+
if (at === undefined || size <= at) continue
|
|
160
|
+
if (grewWith(p, Math.max(at, size - TAIL_MAX), size, CLASSIFIER_REFUSAL)) hit = true
|
|
161
|
+
}
|
|
162
|
+
return hit
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** at most this much of a file's growth is read in one look */
|
|
167
|
+
const TAIL_MAX = 4 * 1024 * 1024
|
|
168
|
+
|
|
169
|
+
function grewWith(path: string, from: number, to: number, words: string): boolean {
|
|
170
|
+
let fd: number | null = null
|
|
171
|
+
try {
|
|
172
|
+
fd = openSync(path, 'r')
|
|
173
|
+
const buf = Buffer.alloc(to - from)
|
|
174
|
+
readSync(fd, buf, 0, buf.length, from)
|
|
175
|
+
return buf.includes(words)
|
|
176
|
+
} catch {
|
|
177
|
+
return false
|
|
178
|
+
} finally {
|
|
179
|
+
if (fd !== null) closeSync(fd)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -27,6 +27,16 @@ export interface SessionRecord {
|
|
|
27
27
|
|
|
28
28
|
export const sessionsDir = (): string => process.env.SHIPKIT_SESSIONS_DIR ?? machinePath('agent-sessions')
|
|
29
29
|
|
|
30
|
+
/** a canonical store (review/item-db.ts canonicalStore: a worktree's is its checkout's) in a scratch place (a repo's
|
|
31
|
+
* `.shipkit/tmp/`, the OS temp, a scratchpad: throwawayPath) is nobody's thread home for the machine's own registry:
|
|
32
|
+
* no record names it, no house watch joins it. A worktree of a real repo in a scratch place is its checkout's store,
|
|
33
|
+
* heard. A registry in a scratch place (a test's) keeps the stores beside it, as the store itself does
|
|
34
|
+
* (scratchStoreRefusal) */
|
|
35
|
+
export function scratchStore(store: string): boolean {
|
|
36
|
+
const { throwawayPath } = require('../review/item-db.ts') as typeof import('../review/item-db.ts')
|
|
37
|
+
return throwawayPath(store) && !throwawayPath(`${sessionsDir()}/`)
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
const fileOf = (session: string): string => join(sessionsDir(), `${session.replace(/[^\w-]/g, '_')}.json`)
|
|
31
41
|
|
|
32
42
|
function readRecord(file: string): SessionRecord | null {
|
|
@@ -38,10 +48,6 @@ function readRecord(file: string): SessionRecord | null {
|
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
|
|
41
|
-
/** a store under a repo's `.shipkit/tmp/`: a lane's experiment in the daily emptied scratch, nobody's thread home, so
|
|
42
|
-
* no record names it and no house watch joins it */
|
|
43
|
-
export const scratchStore = (store: string): boolean => /\/\.shipkit\/tmp\//.test(store)
|
|
44
|
-
|
|
45
51
|
/** the session of this process acted on `store`: its record names the store and its process. Silent and cheap: it
|
|
46
52
|
* writes only when something changed, and never fails the act that called it. A lane shares its session's ids, so
|
|
47
53
|
* its act in its worktree names the store by its canonical folder (review/item-db.ts canonicalStore), never a second
|
|
@@ -50,9 +56,10 @@ export function noteSession(at: string, o: { env?: Record<string, string | undef
|
|
|
50
56
|
const env = o.env ?? process.env
|
|
51
57
|
const session = env.CLAUDE_CODE_SESSION_ID?.trim()
|
|
52
58
|
const pid = Number(env.CLAUDE_PID)
|
|
53
|
-
if (!session || !Number.isInteger(pid) || pid <= 0
|
|
59
|
+
if (!session || !Number.isInteger(pid) || pid <= 0) return
|
|
54
60
|
try {
|
|
55
61
|
const store = (require('../review/item-db.ts') as typeof import('../review/item-db.ts')).canonicalStore(at)
|
|
62
|
+
if (scratchStore(store)) return
|
|
56
63
|
const file = fileOf(session)
|
|
57
64
|
const known = readRecord(file)
|
|
58
65
|
if (known && known.pid === pid && known.stores.includes(store)) return
|
package/src/agent-time/store.ts
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
import { Database } from 'bun:sqlite'
|
|
17
17
|
import { closeSync, openSync, readSync, readdirSync, realpathSync, statSync, watch } from 'fs'
|
|
18
18
|
import { homedir } from 'os'
|
|
19
|
-
import {
|
|
20
|
-
import { MACHINE_DB_FILE,
|
|
19
|
+
import { dirname, join } from 'path'
|
|
20
|
+
import { MACHINE_DB_FILE, machineDbPath, openMachineFile } from '../core/machine-db.ts'
|
|
21
21
|
import { machinePath } from '../core/machine-layout.ts'
|
|
22
22
|
import { type ConfigRoot, discoverConfigRoots } from '../reflect/prompt-corpus.ts'
|
|
23
23
|
import { type TranscriptEvent, readTranscriptLine } from '../reflect/transcript.ts'
|
|
@@ -34,7 +34,7 @@ export const INDEX_VERSION = 17
|
|
|
34
34
|
export function agentTimeDbPath(home = homedir()): string {
|
|
35
35
|
const env = process.env[AGENT_TIME_DB_ENV]
|
|
36
36
|
if (env != null && env !== '') return env
|
|
37
|
-
return home === homedir() ?
|
|
37
|
+
return home === homedir() ? machineDbPath() : machinePath(MACHINE_DB_FILE, home)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** the cached answers of `sk time`, a folder of the machine's own */
|
|
@@ -82,6 +82,7 @@ create table if not exists time_calls (
|
|
|
82
82
|
cmd_sum integer
|
|
83
83
|
);
|
|
84
84
|
create index if not exists time_calls_file on time_calls (file_id, start);
|
|
85
|
+
create unique index if not exists time_calls_id on time_calls (id);
|
|
85
86
|
create table if not exists time_marks (
|
|
86
87
|
file_id integer not null,
|
|
87
88
|
at integer not null,
|
|
@@ -118,71 +119,20 @@ create table if not exists time_bg_ends (
|
|
|
118
119
|
);
|
|
119
120
|
`
|
|
120
121
|
|
|
121
|
-
/** the index's tables, made where they are not:
|
|
122
|
-
|
|
123
|
-
* old file's rows in, so no open builds an index over real rows */
|
|
124
|
-
export const createIndexTables = (db: Database): void => void db.exec(`${SCHEMA}\n${UNIQUE}`)
|
|
125
|
-
|
|
126
|
-
/** the unique index of a call's id, apart from SCHEMA: a file of before it may hold a call twice, so it comes after
|
|
127
|
-
* their dedupe (migrate) */
|
|
128
|
-
const UNIQUE = 'create unique index if not exists time_calls_id on time_calls (id)'
|
|
129
|
-
|
|
130
|
-
/** the columns added after the first build, with their type: added in place, a row of a pruned transcript cannot be
|
|
131
|
-
* read again */
|
|
132
|
-
const ADDED: readonly [string, string][] = [
|
|
133
|
-
['approval', 'integer not null default 0'],
|
|
134
|
-
['perm', "text not null default ''"],
|
|
135
|
-
['read', 'integer not null default 0'],
|
|
136
|
-
['bg', 'integer not null default 0'],
|
|
137
|
-
['msg', "text not null default ''"],
|
|
138
|
-
['model', "text not null default ''"],
|
|
139
|
-
['ctx', 'integer not null default 0'],
|
|
140
|
-
['out', 'integer not null default 0'],
|
|
141
|
-
['why', "text not null default ''"],
|
|
142
|
-
['cmd_sum', 'integer'],
|
|
143
|
-
]
|
|
122
|
+
/** the index's tables and every index they need, made where they are not: a repair makes a table again with them */
|
|
123
|
+
export const createIndexTables = (db: Database): void => void db.exec(SCHEMA)
|
|
144
124
|
|
|
145
125
|
export function openIndex(path = agentTimeDbPath()): Database {
|
|
146
126
|
return openMachineFile(path, {
|
|
147
127
|
store: 'agent time index',
|
|
148
128
|
schema: (db) => {
|
|
149
|
-
db
|
|
150
|
-
|
|
129
|
+
createIndexTables(db)
|
|
130
|
+
const row = db.query("select value from time_meta where key = 'shape'").get() as { value: string } | null
|
|
131
|
+
if (row?.value !== RULES_VERSION) reshape(db)
|
|
151
132
|
},
|
|
152
133
|
})
|
|
153
134
|
}
|
|
154
135
|
|
|
155
|
-
/** columns added after the first build, added in place: the rows of pruned
|
|
156
|
-
* transcripts cannot be read again, so a migration never drops a table */
|
|
157
|
-
function migrate(db: Database): void {
|
|
158
|
-
const missing = (): { cols: string[]; unique: boolean } => {
|
|
159
|
-
const cols = (db.query('pragma table_info(time_calls)').all() as { name: string }[]).map((c) => c.name)
|
|
160
|
-
return { cols: ADDED.filter(([c]) => !cols.includes(c)).map(([c]) => c), unique: db.query("select 1 from sqlite_master where type = 'index' and name = 'time_calls_id'").get() == null }
|
|
161
|
-
}
|
|
162
|
-
// read first with no lock: a file of today's shape (a fold makes it so) takes no write at its open. Else under the
|
|
163
|
-
// write lock, read again: two first opens at once, the second finds the work done
|
|
164
|
-
const m = missing()
|
|
165
|
-
if (m.cols.length > 0 || m.unique)
|
|
166
|
-
db.transaction(() => {
|
|
167
|
-
const again = missing()
|
|
168
|
-
for (const [c, sql] of ADDED) if (again.cols.includes(c)) db.exec(`alter table time_calls add column ${c} ${sql}`)
|
|
169
|
-
// a tool use id is unique on the machine: a session copied into a second account (to resume it there)
|
|
170
|
-
// holds the same calls, written once
|
|
171
|
-
if (again.unique) {
|
|
172
|
-
db.exec('drop index if exists time_calls_open')
|
|
173
|
-
db.exec('delete from time_calls where rowid not in (select min(rowid) from time_calls group by id)')
|
|
174
|
-
db.exec(UNIQUE)
|
|
175
|
-
}
|
|
176
|
-
}).immediate()
|
|
177
|
-
if (db.query("select 1 from time_meta where key = 'aliases'").get() == null) {
|
|
178
|
-
foldAliases(db)
|
|
179
|
-
db.query("insert or replace into time_meta (key, value) values ('aliases', '1')").run()
|
|
180
|
-
}
|
|
181
|
-
const row = db.query("select value from time_meta where key = 'shape'").get() as { value: string } | null
|
|
182
|
-
if (row?.value === RULES_VERSION) return
|
|
183
|
-
reshape(db)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
136
|
const realOf = (path: string): string => {
|
|
187
137
|
try {
|
|
188
138
|
return realpathSync(path)
|
|
@@ -191,54 +141,6 @@ const realOf = (path: string): string => {
|
|
|
191
141
|
}
|
|
192
142
|
}
|
|
193
143
|
|
|
194
|
-
/** the neighbour a project folder is a link to, as a path beside it; null for a folder of its own, and for a link
|
|
195
|
-
* to somewhere else (that folder has no other name here) */
|
|
196
|
-
function neighbourOf(dir: string): string | null {
|
|
197
|
-
try {
|
|
198
|
-
const parent = realpathSync(dirname(dir))
|
|
199
|
-
const real = realpathSync(dir)
|
|
200
|
-
return real !== join(parent, basename(dir)) && dirname(real) === parent ? join(dirname(dir), basename(real)) : null
|
|
201
|
-
} catch {
|
|
202
|
-
return null
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** the rows a lister read under a project folder that is a link to its neighbour (a renamed repo keeps its old
|
|
207
|
-
* name as a link) go to the real folder: a call is kept once on the machine, so the linked name held calls its
|
|
208
|
-
* real folder then missed, and showed as a repo of its own. Run once per index (migrate): the lister no longer
|
|
209
|
-
* lists a linked name. Returns the file rows folded */
|
|
210
|
-
export function foldAliases(db: Database): number {
|
|
211
|
-
const rows = db.query('select id, path, project from time_files').all() as { id: number; path: string; project: string }[]
|
|
212
|
-
const idOf = new Map(rows.map((r) => [r.path, r.id]))
|
|
213
|
-
const targets = new Map<string, string | null>()
|
|
214
|
-
let folded = 0
|
|
215
|
-
db.transaction(() => {
|
|
216
|
-
for (const r of rows) {
|
|
217
|
-
const at = r.path.indexOf(`/${r.project}/`)
|
|
218
|
-
if (at < 0) continue
|
|
219
|
-
const dir = r.path.slice(0, at + 1 + r.project.length)
|
|
220
|
-
if (!targets.has(dir)) targets.set(dir, neighbourOf(dir))
|
|
221
|
-
const target = targets.get(dir)
|
|
222
|
-
if (target == null) continue
|
|
223
|
-
const path = target + r.path.slice(dir.length)
|
|
224
|
-
const real = idOf.get(path)
|
|
225
|
-
if (real == null) {
|
|
226
|
-
db.query('update time_files set path = ?, project = ? where id = ?').run(path, basename(target), r.id)
|
|
227
|
-
idOf.set(path, r.id)
|
|
228
|
-
} else {
|
|
229
|
-
// the real row holds the same marks and prompts (the same file): only what is kept once moves
|
|
230
|
-
db.query('update time_calls set file_id = ? where file_id = ?').run(real, r.id)
|
|
231
|
-
db.query('update time_hooks set file_id = ? where file_id = ?').run(real, r.id)
|
|
232
|
-
db.query('delete from time_marks where file_id = ?').run(r.id)
|
|
233
|
-
db.query('delete from time_prompts where file_id = ?').run(r.id)
|
|
234
|
-
db.query('delete from time_files where id = ?').run(r.id)
|
|
235
|
-
}
|
|
236
|
-
folded++
|
|
237
|
-
}
|
|
238
|
-
})()
|
|
239
|
-
return folded
|
|
240
|
-
}
|
|
241
|
-
|
|
242
144
|
/** the shape rules and the read rules, one stamp: either changing reshapes */
|
|
243
145
|
const RULES_VERSION = `${SHAPE_VERSION}.${READ_VERSION}`
|
|
244
146
|
|
|
@@ -829,5 +731,3 @@ export function repoOfProject(project: string, home = homedir()): string {
|
|
|
829
731
|
return bare.startsWith(`${devSlug}-`) ? bare.slice(devSlug.length + 1) : bare
|
|
830
732
|
}
|
|
831
733
|
|
|
832
|
-
export const fileLabel = (path: string): string => basename(path).replace(/\.jsonl$/, '')
|
|
833
|
-
|
package/src/asks/ask-bar-fold.ts
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
5
5
|
import { partyOf, type Message } from '../review/model.ts'
|
|
6
6
|
import { appendMessage, readAll, storeDir } from '../review/store.ts'
|
|
7
|
-
import {
|
|
7
|
+
import { membersOf, type Thread } from '../review/threads.ts'
|
|
8
8
|
import { barOwnOf } from '../review/supersede.ts'
|
|
9
9
|
import { askOfThread, isClosed } from './ask-store.ts'
|
|
10
|
+
import { askStateOf, orderedThreads } from '../review/thread-state.ts'
|
|
10
11
|
|
|
11
12
|
/** the agent's confirms of an ask's thread whose words are « Done: » and a title the ask held, not yet the bar's own */
|
|
12
13
|
function doneConfirmsOf(t: Thread): { home: string; m: Message }[] {
|
package/src/asks/ask-close.ts
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
7
7
|
import type { ReviewItem } from '../review/model.ts'
|
|
8
8
|
import { appendMessage, readAll, storeDir } from '../review/store.ts'
|
|
9
|
-
import {
|
|
9
|
+
import { type Thread } from '../review/threads.ts'
|
|
10
10
|
import { answerWords, carryAnswers, hisAnswers, type HisAnswer } from './ask-carry.ts'
|
|
11
11
|
import { findAsk, isClosed, setAskState, type Ask } from './ask-store.ts'
|
|
12
|
+
import { orderedThreads } from '../review/thread-state.ts'
|
|
12
13
|
|
|
13
14
|
export { answerWords, hisAnswers, type HisAnswer }
|
|
14
15
|
|
package/src/asks/ask-doc.ts
CHANGED
|
@@ -7,9 +7,10 @@ import { docChangeLine } from '../review/doc-model.ts'
|
|
|
7
7
|
import { instructionsRefusal, parseInstructions } from '../review/instructions.ts'
|
|
8
8
|
import { readAll, storeDir } from '../review/store.ts'
|
|
9
9
|
import { currentInstructions } from '../review/supersede.ts'
|
|
10
|
-
import { membersOf
|
|
10
|
+
import { membersOf } from '../review/threads.ts'
|
|
11
11
|
import type { DocHome } from '../review/unit.ts'
|
|
12
12
|
import { findAsk, isClosed, saveAskText } from './ask-store.ts'
|
|
13
|
+
import { orderedThreads } from '../review/thread-state.ts'
|
|
13
14
|
|
|
14
15
|
/** the open asks as one kind of document: their words in the database, his answers beside them */
|
|
15
16
|
export function askDoc(root: string): DocHome<{ text: string; steps: string[] }> {
|
package/src/asks/ask-migrate.ts
CHANGED
|
@@ -8,10 +8,11 @@ import { ASK_FILES_DIR } from '../core/layout.ts'
|
|
|
8
8
|
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
9
9
|
import { askKindOf, type AskHead, type ReviewItem } from '../review/model.ts'
|
|
10
10
|
import { appendMessage, openThread, readAll, storeDir, updateHead } from '../review/store.ts'
|
|
11
|
-
import {
|
|
11
|
+
import { membersOf, threadOfAddress, type Thread } from '../review/threads.ts'
|
|
12
12
|
import { afterMs } from './ask-after.ts'
|
|
13
13
|
import { askAddress, askOfThread, isClosed, parseWaits, postQuestions, questionsOf, type Ask, type AskStatus } from './ask-store.ts'
|
|
14
14
|
import { realGit } from '../core/git.ts'
|
|
15
|
+
import { askStateOf, threadState } from '../review/thread-state.ts'
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
/** one ask file as it reads: `rel` its path under the folder (`done/003-x.md`), `closedFrom` where its closed day came
|
|
@@ -193,7 +194,7 @@ async function migrateBody(root: string, o: { go: boolean; lane?: string; now?:
|
|
|
193
194
|
if (o.go) appendMessage(store, h.id, { who: f.status === 'declined' ? 'owner' : who, askState: { state: f.status, why: f.why ?? `its record in git said ${f.status}${guessed(f)}` } }, { now: closeAt(t, f, now) })
|
|
194
195
|
}
|
|
195
196
|
const until = f.status === 'open' && f.after != null ? afterMs(f.after) : null
|
|
196
|
-
if (until != null && until > now.getTime() &&
|
|
197
|
+
if (until != null && until > now.getTime() && (threadState(t, now).aside?.until ?? null) === null) {
|
|
197
198
|
what.push(`set aside until ${f.after}`)
|
|
198
199
|
if (o.go) appendMessage(store, h.id, { who, snooze: { until: new Date(until).toISOString() } }, { now })
|
|
199
200
|
}
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
11
11
|
import { partyOf, type AskHead, type Message } from '../review/model.ts'
|
|
12
12
|
import { appendMessage, readAll, storeDir } from '../review/store.ts'
|
|
13
|
-
import { membersOf,
|
|
13
|
+
import { membersOf, type Thread } from '../review/threads.ts'
|
|
14
14
|
import { currentInstructions, replacersOf } from '../review/supersede.ts'
|
|
15
15
|
import { answersTo, askOpen } from '../review/answer-kinds.ts'
|
|
16
16
|
import { parseInstructions } from '../review/instructions.ts'
|
|
17
17
|
import { askOfThread, fieldKey, instructionsMessage, isClosed, postFields, stepKey, stepsAskOf, tickedTitles } from './ask-store.ts'
|
|
18
18
|
import { refoldWords, type Loose, type Refold } from './ask-words-fold.ts'
|
|
19
|
+
import { orderedThreads } from '../review/thread-state.ts'
|
|
19
20
|
|
|
20
21
|
/** the old checklists of an ask's thread that its steps were: an agent's « The steps », not superseded */
|
|
21
22
|
const oldChecklists = (t: Thread): Message[] => {
|
package/src/asks/ask-store.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { SECRET_NAME } from '../secrets/name.ts'
|
|
|
8
8
|
import { answersTo, kindOfAsk, ticksOf } from '../review/answer-kinds.ts'
|
|
9
9
|
import { askKindOf, ASK_KINDS, CLOSED_ASK_STATES, isAskItem, isClosedAskState, partyOf, type AskHead, type AskKind, type AskState, type AskWait, type ClosedAskState, type Message, type MessageAsk, type ReviewItem } from '../review/model.ts'
|
|
10
10
|
import { addMessage, appendMessage, hasStore, openThread, postAsk, readAll, storeDir, updateHead } from '../review/store.ts'
|
|
11
|
-
import {
|
|
11
|
+
import { membersOf, type Thread } from '../review/threads.ts'
|
|
12
12
|
import { currentInstructions, foldsOf, replacersOf } from '../review/supersede.ts'
|
|
13
13
|
import { instructionsRefusal, parseInstructions, stepSections } from '../review/instructions.ts'
|
|
14
14
|
import { AFTER_FORMS, afterMs, afterWords } from './ask-after.ts'
|
|
@@ -16,6 +16,7 @@ import { answerWords, carryAnswers, hisAnswers, stepKey, type HisAnswer } from '
|
|
|
16
16
|
import { askedAgain, nameSince } from './ask-since.ts'
|
|
17
17
|
import { slugOf } from '../core/slug.ts'
|
|
18
18
|
import { dayStamp } from '../core/day-stamp.ts'
|
|
19
|
+
import { askStateOf, orderedThreads, threadState } from '../review/thread-state.ts'
|
|
19
20
|
|
|
20
21
|
export type { AskWait } from '../review/model.ts'
|
|
21
22
|
|
|
@@ -117,7 +118,7 @@ export function askOfThread(t: Thread, now = new Date()): Ask | null {
|
|
|
117
118
|
const f: AskHead = newer ? { ...newer.instructions.ask, created: h.ask.created, ...(h.ask.pinged ? { pinged: h.ask.pinged } : {}) } : h.ask
|
|
118
119
|
const s = stateOf(t)
|
|
119
120
|
const body = newer ? (newer.text ?? '') : (h.what ?? '')
|
|
120
|
-
const until = s.status === 'open' ?
|
|
121
|
+
const until = s.status === 'open' ? (threadState(t, now).aside?.until ?? null) : null
|
|
121
122
|
const secrets = f.secrets ?? []
|
|
122
123
|
return {
|
|
123
124
|
id: on.slice('ask:'.length),
|
|
@@ -648,7 +649,7 @@ export async function followAskThread(root: string, id: string, o: CloseOpts = {
|
|
|
648
649
|
const t = orderedThreads(items).find((x) => membersOf(x).some((y) => y.item.id === id))
|
|
649
650
|
if (t == null) return null
|
|
650
651
|
const a = askOfThread(t)
|
|
651
|
-
if (a == null || isClosed(a.status) ||
|
|
652
|
+
if (a == null || isClosed(a.status) || threadState(t).waitsOwner.some((w) => w.what === 'question' || w.what === 'change' || w.what === 'steps')) return null
|
|
652
653
|
const gone = replacersOf(membersOf(t))
|
|
653
654
|
const asks = membersOf(t).flatMap((y) => y.thread.filter((m) => m.ask !== undefined && !gone.has(m.id)).map((m) => ({ m, thread: y.thread })))
|
|
654
655
|
if (asks.length === 0) return null
|
package/src/check.ts
CHANGED
|
@@ -142,6 +142,8 @@ export type CheckDef = {
|
|
|
142
142
|
|
|
143
143
|
/** the longest description a row can show whole */
|
|
144
144
|
export const DESCRIPTION_MAX = 90
|
|
145
|
+
/** the shortest one that states anything a reader can use */
|
|
146
|
+
export const DESCRIPTION_MIN = 15
|
|
145
147
|
|
|
146
148
|
/** what is wrong with a description, or null when it states an invariant
|
|
147
149
|
* the way every surface expects: one line, short, the fact that must hold.
|
|
@@ -151,6 +153,7 @@ export function descriptionProblem(description: unknown): string | null {
|
|
|
151
153
|
return 'description is required: ONE line stating what must be true'
|
|
152
154
|
const d = description.trim()
|
|
153
155
|
if (/[\r\n]/.test(d)) return 'description must be ONE line'
|
|
156
|
+
if (d.length < DESCRIPTION_MIN) return `description is ${d.length} characters, too short to state anything: ${DESCRIPTION_MIN} at least`
|
|
154
157
|
if (d.length > DESCRIPTION_MAX) return `description is ${d.length} characters, the limit is ${DESCRIPTION_MAX}: state only what must be true`
|
|
155
158
|
if (/^this checks\b/i.test(d)) return `description states what must be true, with no 'this checks' opener`
|
|
156
159
|
if (/\b(red|yellow|green|a warning|warn)( one)? means\b|\ba red one\b/i.test(d))
|
|
@@ -269,49 +272,6 @@ export type TaskDef = {
|
|
|
269
272
|
* add it here. */
|
|
270
273
|
export const TASK_DEF_KEYS = ['id', 'cmd', 'logic', 'deps', 'env', 'cwd', 'group', 'optIn', 'timeoutMs', 'inputs', 'ttl', 'never'] as const
|
|
271
274
|
|
|
272
|
-
// ── the legacy rule shape, for the compatibility window ──────────────────
|
|
273
|
-
// A repo still registering through `repo.config.ts rules: []` writes this
|
|
274
|
-
// one. It is read as a check whose body is `lint`, and it dies with that key
|
|
275
|
-
// once `shipkit fleet` shows no repo below 0.40.
|
|
276
|
-
|
|
277
|
-
export type RuleEnv = CheckEnv
|
|
278
|
-
|
|
279
|
-
export type Rule = {
|
|
280
|
-
/** stable PREFIX + 3 digits, never reused or renumbered. `SK###` is
|
|
281
|
-
* reserved for the toolkit, so a repo picks its own (`RV###`). A check
|
|
282
|
-
* FILE takes its id from its name and may use plain words instead. */
|
|
283
|
-
id: string
|
|
284
|
-
/** display name, stable: the row in STATUS.md, the TUI, the suite cache */
|
|
285
|
-
title: string
|
|
286
|
-
/** can this stop you? REQUIRED, no default, exactly as a check declares it */
|
|
287
|
-
blocking: boolean
|
|
288
|
-
/** wiki page owning the invariant — the body runner appends
|
|
289
|
-
* `docsBase + owner` as the fix: pointer whenever a failing lint
|
|
290
|
-
* attached none. A check file defaults this to its own path. */
|
|
291
|
-
owner: string
|
|
292
|
-
/** WORLD population: clean-pass cache duration for a rule that probes the
|
|
293
|
-
* network, as in '24h'. A skip, a WARN and a FAIL are never cached. */
|
|
294
|
-
ttl?: string
|
|
295
|
-
/** CONTENT population: the repo-relative paths this rule reads. Neither
|
|
296
|
-
* `inputs` nor `ttl` means never cached, which is the safe default, and
|
|
297
|
-
* declaring both is a registration failure. */
|
|
298
|
-
inputs?: string[]
|
|
299
|
-
/** repo-relative entry file(s) of this rule's OWN code, so fixing a bug in
|
|
300
|
-
* the rule moves its key. A check FILE needs none: its own path is its
|
|
301
|
-
* closure, which is the field this shape exists without. */
|
|
302
|
-
code?: string[]
|
|
303
|
-
/** a DECIDED never-cacheable, with the reason: it reads git history, a
|
|
304
|
-
* path outside the repo, or the wall clock, so no key can describe it. */
|
|
305
|
-
never?: string
|
|
306
|
-
/** cache-identity contribution for a TTL'd rule whose verdict depends on
|
|
307
|
-
* config: a changed key busts the answer instead of serving it cached */
|
|
308
|
-
cacheKey?: (env: RuleEnv) => string
|
|
309
|
-
/** the invariant itself, the legacy spelling of a check's `run` */
|
|
310
|
-
lint: (t: CheckCtx, env: RuleEnv) => void | Promise<void>
|
|
311
|
-
/** idempotent auto-repair, never interactive. `check --fix` applies it */
|
|
312
|
-
fix?: (env: RuleEnv) => FixResult | Promise<FixResult>
|
|
313
|
-
}
|
|
314
|
-
|
|
315
275
|
// ── running a body, and what every line it prints carries ────────────────
|
|
316
276
|
|
|
317
277
|
/** the config part of a check's cache identity: its declared key, and the
|