rvlib-shipkit 2.31.0 → 2.32.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 +31 -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 +98 -73
- 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 +26 -198
- 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 +25 -23
- 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 +92 -182
- package/src/advisors/tunnel.ts +6 -5
- package/src/advisors/users-listen.ts +92 -0
- package/src/advisors/users-router.ts +257 -85
- 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_Checks.ts +0 -14
- 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_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 +2 -2
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +5 -4
- 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/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/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/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/discover-checks.ts +42 -32
- package/src/gate/gate-checks.ts +21 -131
- package/src/gate/pre-commit-discovery.ts +16 -25
- package/src/gate/run-check.ts +0 -4
- 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 +4 -11
- package/src/home/space-page.ts +3 -2
- package/src/home/supervise.ts +3 -7
- package/src/hooks/hook-config.ts +6 -7
- package/src/hooks/leak-guard.ts +1 -1
- package/src/hooks/run-hooks.ts +0 -5
- 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/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 +29 -64
- package/src/review/answer-kinds.ts +61 -4
- package/src/review/blocked-guard.ts +11 -0
- package/src/review/blocked-object.ts +298 -0
- package/src/review/cells.ts +116 -229
- 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 +49 -19
- 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.ts +86 -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 +798 -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/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/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 +181 -54
- 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 +2 -2
- package/src/serve/hub-app/review/review-kit.ts +17 -11
- package/src/serve/hub-app/review/review-list.tsx +23 -31
- package/src/serve/hub-app/review/review-st.ts +30 -40
- package/src/serve/hub-app/review/review-thread.tsx +139 -85
- package/src/serve/hub-app/review/review-views.tsx +124 -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 +372 -201
- package/src/serve/hub-app/review/tone-bar.tsx +126 -0
- package/src/serve/hub-app/review/tones.ts +35 -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 +180 -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/film-box.ts +0 -20
- 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
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
// the daemon's watch of the backup's sources: a path it hears that could be a source (`watchRoots`) is noted, and the
|
|
2
|
-
// next look reads only the noted paths again. The callback only notes: the loop answers every page. A clean stop hands
|
|
3
|
-
// what it heard to the next daemon (a reload in place); a daemon that did not stop cleanly starts with a full walk
|
|
4
|
-
import { watch } from 'node:fs'
|
|
5
|
-
import { basename, join } from 'node:path'
|
|
6
|
-
import { watchTree } from '../../core/tree-watch.ts'
|
|
7
|
-
import { machineDelete, machineGet, machineSet, machineUpdate } from '../../core/machine-db.ts'
|
|
8
|
-
import { backupDue, BATCH, NAMED, type Batch } from './daemon.ts'
|
|
9
|
-
import { isTransient, watchRoots } from './sources.ts'
|
|
10
|
-
|
|
11
|
-
/** what a stopping daemon heard and no look took yet, for the next one */
|
|
12
|
-
const HELD = 'backup-heard'
|
|
13
|
-
/** a stop this recent is a hand over (a reload in place): the next daemon takes what it heard, else it walks */
|
|
14
|
-
export const HANDOVER_MS = 60_000
|
|
15
|
-
/** past this many paths, the next look walks every source */
|
|
16
|
-
export const MAX_PATHS = 2_000
|
|
17
|
-
|
|
18
|
-
type Held = { at: number; paths: string[]; all: boolean }
|
|
19
|
-
|
|
20
|
-
export interface BackupWatchOptions {
|
|
21
|
-
home: string
|
|
22
|
-
/** the house repos, archived ones included */
|
|
23
|
-
repos: readonly string[]
|
|
24
|
-
now?: () => number
|
|
25
|
-
printErr?: (l: string) => void
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class BackupWatch {
|
|
29
|
-
private readonly heard = new Set<string>()
|
|
30
|
-
/** the next look walks every source */
|
|
31
|
-
private all = false
|
|
32
|
-
/** a watch stopped: every look walks, as with no watch */
|
|
33
|
-
private blind = false
|
|
34
|
-
private named: Record<string, string[]> = {}
|
|
35
|
-
private readonly watchers: { close: () => void }[] = []
|
|
36
|
-
private readonly now: () => number
|
|
37
|
-
|
|
38
|
-
constructor(private readonly o: BackupWatchOptions) {
|
|
39
|
-
this.now = o.now ?? Date.now
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** no watch at all: every look walks every source, as before there was one */
|
|
43
|
-
blindly(): this {
|
|
44
|
-
this.blind = true
|
|
45
|
-
return this
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async start(): Promise<this> {
|
|
49
|
-
const held = machineGet<Held>(HELD)
|
|
50
|
-
machineDelete(HELD)
|
|
51
|
-
if (held != null && this.now() - held.at <= HANDOVER_MS) {
|
|
52
|
-
for (const p of held.paths) this.heard.add(p)
|
|
53
|
-
this.all = held.all
|
|
54
|
-
} else this.all = true
|
|
55
|
-
this.named = machineGet<Record<string, string[]>>(NAMED) ?? {}
|
|
56
|
-
for (const root of await watchRoots(this.o.home, this.o.repos, (r) => this.named[r] ?? [])) {
|
|
57
|
-
const heard = (name: string | null): void => {
|
|
58
|
-
if (this.all) return
|
|
59
|
-
// no name, or the root itself: the system says its tree changed in ways it did not list
|
|
60
|
-
const rel = name ?? ''
|
|
61
|
-
if (rel === '') return void (this.all = true)
|
|
62
|
-
if (isTransient(basename(rel)) || root.heard(rel) == null) return
|
|
63
|
-
if (this.heard.size >= MAX_PATHS) {
|
|
64
|
-
this.all = true
|
|
65
|
-
this.heard.clear()
|
|
66
|
-
} else this.heard.add(join(root.dir, rel))
|
|
67
|
-
}
|
|
68
|
-
const stopped = (e: Error): void => {
|
|
69
|
-
if (!this.blind) this.o.printErr?.(`WARN backup: the watch of ${root.dir} stopped (${e.message}): each look walks every source until the daemon reloads`)
|
|
70
|
-
this.blind = true
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
if (root.recursive) {
|
|
74
|
-
// a repo's tree is the save watch's one watch too (core/tree-watch.ts)
|
|
75
|
-
this.watchers.push(watchTree(root.dir, heard, { onError: stopped }))
|
|
76
|
-
} else {
|
|
77
|
-
const w = watch(root.dir, { recursive: false }, (_event, name) => heard(name == null ? null : String(name)))
|
|
78
|
-
w.on('error', (e) => stopped(e as Error))
|
|
79
|
-
this.watchers.push(w)
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
// a root not on the disk yet: the safety walk finds what lands there
|
|
83
|
-
continue
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return this
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** the paths heard since the last look, for a test or a probe */
|
|
90
|
-
pending(): { paths: string[]; all: boolean } {
|
|
91
|
-
return { paths: [...this.heard].sort(), all: this.all || this.blind }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** the daemon's look: a few reads of the machine db, never a walk. When due, the paths heard go to the look it
|
|
95
|
-
* starts, with those of a look that did not finish */
|
|
96
|
-
due(now: number): boolean {
|
|
97
|
-
this.named = machineGet<Record<string, string[]>>(NAMED) ?? this.named
|
|
98
|
-
if (!backupDue(now, this.all || this.blind || this.heard.size > 0)) return false
|
|
99
|
-
const heard = [...this.heard]
|
|
100
|
-
const heardAll = this.all || this.blind
|
|
101
|
-
// merged into the batch as it is now: a look that ends meanwhile marks done only the batch it took
|
|
102
|
-
machineUpdate<Batch>(BATCH, (was) => {
|
|
103
|
-
const undone = was?.done === false ? was : null
|
|
104
|
-
const paths = [...new Set([...(undone?.paths ?? []), ...heard])]
|
|
105
|
-
const all = heardAll || (undone?.all ?? false) || paths.length > MAX_PATHS
|
|
106
|
-
return { paths: all ? [] : paths.sort(), all, done: false }
|
|
107
|
-
})
|
|
108
|
-
this.heard.clear()
|
|
109
|
-
this.all = false
|
|
110
|
-
return true
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
stop(): void {
|
|
114
|
-
for (const w of this.watchers.splice(0)) w.close()
|
|
115
|
-
machineSet(HELD, { at: this.now(), paths: [...this.heard], all: this.all || this.blind } satisfies Held)
|
|
116
|
-
}
|
|
117
|
-
}
|
package/src/review/band.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
// the band a thread reads in (wiki tools/shipkit/threads-how-it-fits.md, The bands): who acts now (threads.ts turnOf),
|
|
2
|
-
// and on an agent's move whether a live agent works it now or it waits for one. Pure and browser safe: the hub reads it
|
|
3
|
-
// with the parties it polls, so a lane's end moves its threads to « waiting for an agent » with no reload
|
|
4
|
-
// the one constraint a reader breaks first: « an agent works on it » is a fact of the registry, never of the store alone
|
|
5
|
-
import { laneAskOwed, type LaneAsk } from './lane-ask.ts'
|
|
6
|
-
import { handedOver, isAskItem, partyOf, WORKING_FRESH_MS, type AskState, type Message, type ReviewItem } from './model.ts'
|
|
7
|
-
import type { Parties } from './parties.ts'
|
|
8
|
-
import { eventOf, type WakeEvent } from './wakes.ts'
|
|
9
|
-
|
|
10
|
-
/** who acts now on a thread (wiki tools/shipkit/threads-how-it-fits.md, The model): his turn, his turn set aside, an
|
|
11
|
-
* agent's move (whether one works it now is the band's, below), nothing owed */
|
|
12
|
-
export type Turn = 'yours' | 'aside' | 'agents' | 'done'
|
|
13
|
-
|
|
14
|
-
/** what the newest move of a thread does to the owner's turn while something waits on the owner (a version, a question):
|
|
15
|
-
* whoever spoke last does not hold the turn. `agents` the ball is theirs until one answers, what still waits on him stays
|
|
16
|
-
* owed as a quiet mark (wait.ts owedOf); `stands` the owner's turn stands; `none` no move, the move before it decides.
|
|
17
|
-
* Any other turn never changes here (owesWork reads the owner's words) */
|
|
18
|
-
export const AFTER_MOVE = {
|
|
19
|
-
/** his reply, a note, a picture, rectangles: an agent answers them */
|
|
20
|
-
'his-words': 'agents',
|
|
21
|
-
/** his request for a lane: the orchestrator gives it one */
|
|
22
|
-
'his-request': 'agents',
|
|
23
|
-
/** the owner's verdict, or one taken back: what it settles decides */
|
|
24
|
-
'his-verdict': 'stands',
|
|
25
|
-
/** his answer to an agent's question, apply, an action on an object an agent linked, a list he finished: an agent acts on it */
|
|
26
|
-
'his-answer': 'agents',
|
|
27
|
-
/** his answer or a list he finished on an ask's own steps: the act is his until it is done, its bar waits on him */
|
|
28
|
-
'his-step': 'stands',
|
|
29
|
-
/** his save of the object in the hub's editor: what waited on him still waits (a draft's places, a version's verdict,
|
|
30
|
-
* an ask's steps); with nothing waiting, the agents owe it a look (owesWork reads it as his unseen words) */
|
|
31
|
-
'his-edit': 'stands',
|
|
32
|
-
/** his close or reopen (an ask, a list he opened again), an act on a spot of a version */
|
|
33
|
-
'his-close': 'stands',
|
|
34
|
-
/** a tick inside an unfinished list, a rating, set aside, his read mark */
|
|
35
|
-
'his-trace': 'none',
|
|
36
|
-
/** an agent's version, reply, update, question, proposed change, fix: it answers him */
|
|
37
|
-
'agent-answer': 'stands',
|
|
38
|
-
/** an agent's working line: the agent is on it, the ball stays where it is */
|
|
39
|
-
'agent-working': 'none',
|
|
40
|
-
/** an agent's read mark, take, assign, claim, a hand-over; a hold flipped, an object attached, a machine line: no answer */
|
|
41
|
-
'agent-mark': 'none',
|
|
42
|
-
} as const satisfies Record<string, 'agents' | 'stands' | 'none'>
|
|
43
|
-
export type Move = keyof typeof AFTER_MOVE
|
|
44
|
-
|
|
45
|
-
const HIS: Partial<Record<WakeEvent, Move>> = {
|
|
46
|
-
words: 'his-words',
|
|
47
|
-
mention: 'his-words',
|
|
48
|
-
edit: 'his-edit',
|
|
49
|
-
verdict: 'his-verdict',
|
|
50
|
-
approval: 'his-verdict',
|
|
51
|
-
'take-back': 'his-verdict',
|
|
52
|
-
answer: 'his-answer',
|
|
53
|
-
apply: 'his-answer',
|
|
54
|
-
action: 'his-answer',
|
|
55
|
-
'list-done': 'his-answer',
|
|
56
|
-
'list-reopened': 'his-close',
|
|
57
|
-
'ask-closed': 'his-close',
|
|
58
|
-
close: 'his-close',
|
|
59
|
-
act: 'his-close',
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// `ready` is no mark: it asks the owner's verdict, an answer
|
|
63
|
-
const AGENT_MARKS = new Set<Message['op']>(['seen', 'take', 'claim', 'release', 'dispatch', 'reassign'])
|
|
64
|
-
|
|
65
|
-
/** an agent's act that answers nothing: a mark, a hold the machine flipped, an object attached, a line the machine wrote */
|
|
66
|
-
const agentMark = (m: Message): boolean => AGENT_MARKS.has(m.op) || handedOver(m) || m.hold !== undefined || (m.about !== undefined && m.text === `attached ${m.about[0] ?? ''}`) || m.who === 'machine'
|
|
67
|
-
|
|
68
|
-
/** which row of AFTER_MOVE one message of a thread is */
|
|
69
|
-
export function moveOf(x: ReviewItem, m: Message): Move {
|
|
70
|
-
if (partyOf(m.who) === 'agent') return m.op === 'working' ? 'agent-working' : agentMark(m) ? 'agent-mark' : 'agent-answer'
|
|
71
|
-
if (m.op === 'seen' || m.carried !== undefined) return 'his-trace'
|
|
72
|
-
if (m.laneAsk !== undefined) return 'his-request'
|
|
73
|
-
const move = HIS[eventOf(x, m)] ?? 'his-trace'
|
|
74
|
-
return move === 'his-answer' && isAskItem(x.item) ? 'his-step' : move
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** the turn once the thread's newest move is read: the owner's turn passes to the agents while the owner's words or lane
|
|
78
|
-
* request are the newest move; a version an agent sends is a move of its own */
|
|
79
|
-
export function turnAfterMoves(base: Turn, members: readonly ReviewItem[]): Turn {
|
|
80
|
-
if (base !== 'yours') return base
|
|
81
|
-
let newest: { at: string; move: Move } | null = null
|
|
82
|
-
for (const x of members) {
|
|
83
|
-
if (x.item.origin.by === 'agent' && (newest === null || x.item.created >= newest.at)) newest = { at: x.item.created, move: 'agent-answer' }
|
|
84
|
-
for (const m of x.thread) {
|
|
85
|
-
const move = moveOf(x, m)
|
|
86
|
-
if (AFTER_MOVE[move] !== 'none' && (newest === null || m.at >= newest.at)) newest = { at: m.at, move }
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return newest !== null && AFTER_MOVE[newest.move] === 'agents' ? 'agents' : base
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const BANDS = ['yours', 'aside', 'working', 'waiting', 'done'] as const
|
|
93
|
-
export type Band = (typeof BANDS)[number]
|
|
94
|
-
|
|
95
|
-
export const BAND_WORDS: Record<Band, string> = { yours: 'your turn', aside: 'set aside', working: 'an agent works on it', waiting: 'waiting for an agent', done: 'done' }
|
|
96
|
-
|
|
97
|
-
/** what the band reads of a thread: its turn, its holder, and the agent of its `working` not ended (traces.ts
|
|
98
|
-
* workingsOf), `agent` for a session's own */
|
|
99
|
-
export interface BandFacts {
|
|
100
|
-
turn: Turn
|
|
101
|
-
/** `handed`: it holds it by a hand-over (review/hand-over.ts), not by an act of its own */
|
|
102
|
-
holder?: { lane?: string; session?: string; handed?: true }
|
|
103
|
-
working?: string
|
|
104
|
-
/** when that `working` was said: it counts WORKING_FRESH_MS (absent, counted as said now) */
|
|
105
|
-
workingAt?: string
|
|
106
|
-
/** his request for a lane (review/lane-ask.ts): owed to the orchestrator, the thread waits for an agent */
|
|
107
|
-
laneAsk?: LaneAsk
|
|
108
|
-
/** an agent's promise of the next version (review/threads.ts nextVersionOf): who, by when, its number */
|
|
109
|
-
next?: { who: string; at: string; until: string; n: number }
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const laneOf = (p: Parties, name: string, session: string | undefined) => p.lanes.find((l) => l.name === name && (session === undefined || l.session === session))
|
|
113
|
-
|
|
114
|
-
/** a live agent works the thread now: its `working` not ended, of a session or a lane still live; a live lane that holds
|
|
115
|
-
* it. A lane the registry cannot find has ended unless its watch lives (wiki tools/shipkit/threads-how-it-fits.md, The
|
|
116
|
-
* parties). A session that only holds it hears, by its watch or at its next prompt, and works nothing: a session's
|
|
117
|
-
* watch lives for days */
|
|
118
|
-
export function worksNow(f: Omit<BandFacts, 'turn'>, p: Parties, now = new Date()): boolean {
|
|
119
|
-
const h = f.holder
|
|
120
|
-
if (f.working !== undefined && workingAge(f, now) <= WORKING_FRESH_MS) {
|
|
121
|
-
if (f.working === 'agent') {
|
|
122
|
-
if (h?.session !== undefined && p.sessions.some((s) => s.id === h.session && s.live)) return true
|
|
123
|
-
} else {
|
|
124
|
-
const l = laneOf(p, f.working, h?.lane === f.working ? h.session : undefined)
|
|
125
|
-
if (l !== undefined && (l.live || l.watch)) return true
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (h?.lane === undefined) return false
|
|
129
|
-
const l = laneOf(p, h.lane, h.session)
|
|
130
|
-
return l !== undefined && (l.live || l.watch)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** the band: the turn, an agent's move split by whether a live agent works it now */
|
|
134
|
-
export const bandOf = (f: BandFacts, p: Parties, now = new Date()): Band =>
|
|
135
|
-
f.turn !== 'agents' ? f.turn : (f.laneAsk !== undefined && laneAskOwed(f.laneAsk, p)) || !worksNow(f, p, now) ? 'waiting' : 'working'
|
|
136
|
-
|
|
137
|
-
const workingAge = (f: Pick<BandFacts, 'workingAt'>, now: Date): number => (f.workingAt === undefined ? 0 : now.getTime() - Date.parse(f.workingAt))
|
|
138
|
-
|
|
139
|
-
/** an age as a row says it: « 12 min », « 14 h », « 3 days » */
|
|
140
|
-
export const ageWords = (ms: number): string => {
|
|
141
|
-
const min = Math.max(1, Math.round(ms / 60_000))
|
|
142
|
-
if (min < 60) return `${min} min`
|
|
143
|
-
const h = Math.round(min / 60)
|
|
144
|
-
return h < 48 ? `${h} h` : `${Math.round(h / 24)} days`
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** a `working` line past its time on the agents' move, as his row says it (« said working 14 h ago, nothing since »;
|
|
148
|
-
* a lane by its name), null while it counts or on any other turn */
|
|
149
|
-
export function staleWorkingOf(f: Pick<BandFacts, 'turn' | 'working' | 'workingAt' | 'next'>, now = new Date()): string | null {
|
|
150
|
-
if (f.turn !== 'agents') return null
|
|
151
|
-
// a promised version counts its own time, never the working line's
|
|
152
|
-
if (f.next !== undefined) return lateOf(f.next, now)
|
|
153
|
-
if (f.working === undefined || f.workingAt === undefined) return null
|
|
154
|
-
const age = workingAge(f, now)
|
|
155
|
-
return age > WORKING_FRESH_MS ? `${f.working === 'agent' ? '' : `${f.working} `}said working ${ageWords(age)} ago, nothing since` : null
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** who an agent's act names, as a line says it: its lane, else « an agent » */
|
|
159
|
-
export const agentWords = (who: string): string => (who === 'agent' ? 'an agent' : who)
|
|
160
|
-
|
|
161
|
-
/** a time as a line says it: « 14:02 » today, else « Mon 30 Nov, 18:00 » */
|
|
162
|
-
export function whenWords(iso: string, now = new Date()): string {
|
|
163
|
-
const d = new Date(iso)
|
|
164
|
-
const hm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
|
|
165
|
-
if (d.toDateString() === now.toDateString()) return hm
|
|
166
|
-
return `${['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][d.getDay()]} ${d.getDate()} ${['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()]}, ${hm}`
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** a promised version past its time, as a line says it (« L382 promised v2 by 14:30, late 3 h »), null while it counts */
|
|
170
|
-
export function lateOf(n: NonNullable<BandFacts['next']>, now = new Date()): string | null {
|
|
171
|
-
const over = now.getTime() - Date.parse(n.until)
|
|
172
|
-
return over > 0 ? `${agentWords(n.who)} promised v${n.n} by ${whenWords(n.until, now)}, late ${ageWords(over)}` : null
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** everything in the thread validated, the row's quiet green: nothing is owed by anyone (its turn done) and he said yes
|
|
176
|
-
* to it: an OK, an « ok with a fix » whose fix is done, or the ask done. A no, a « not doing it », a withdrawn or
|
|
177
|
-
* replaced head, a thread closed by an agent alone is done, never validated */
|
|
178
|
-
export const validatedOf = (f: { turn: Turn; status: string; ask?: AskState }): boolean =>
|
|
179
|
-
f.turn === 'done' && (f.ask !== undefined ? f.ask === 'done' : f.status === 'approved' || f.status === 'approved-with-fix')
|
|
180
|
-
|
|
181
|
-
/** the words a « waiting for an agent » head says: who takes one */
|
|
182
|
-
export const waitingWords = (repo: string): string => `nobody works on these now: a session in ${repo} takes one with sk thread take <address>`
|
package/src/review/folders.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// the folder layout of a thread store (wiki tools/shipkit/threads-store.md, Folders): one folder an item, its
|
|
2
|
-
// `item.json`, `thread/<message>.json` and its media beside them, `.gone/<entry>/` the items set aside. A shipkit older
|
|
3
|
-
// than the rows kept a repo's store so, in `.shipkit/review/`; `sk thread export` writes it for a person to read.
|
|
4
|
-
// The import reads it into the rows, one way, and never writes a folder: it keeps the later of two heads and every
|
|
5
|
-
// message by its id, so a run stopped half way runs again and does what is left
|
|
6
|
-
import { copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, statSync, utimesSync, writeFileSync } from 'node:fs'
|
|
7
|
-
import { dirname, join, relative } from 'node:path'
|
|
8
|
-
import { rowsGone, rowsGoneCreated, rowsIO, rowsKeepGone, type ItemBackend } from './item-rows.ts'
|
|
9
|
-
import { GONE } from './item-db.ts'
|
|
10
|
-
import { ID_RE, itemProblems, mediaFilesOf, MESSAGE_RE, messageProblems, type Message } from './model.ts'
|
|
11
|
-
import { jsonText, revOf } from './rev.ts'
|
|
12
|
-
import { isLockFile } from '../core/locked-write.ts'
|
|
13
|
-
|
|
14
|
-
/** what one pass did for one store: heads and messages written, items set aside carried, items both sides hold alike,
|
|
15
|
-
* a line for each one left as it was, a line for each file that does not read */
|
|
16
|
-
export type Imported = { dir: string; items: number; heads: number; msgs: number; gone: number; same: number; files: number; kept: string[]; broken: string[]; media?: { copied: number; missing: string[] }; read: { id: string; msgs: string[] }[] }
|
|
17
|
-
|
|
18
|
-
const fresh = (dir: string): Imported => ({ dir, items: 0, heads: 0, msgs: 0, gone: 0, same: 0, files: 0, kept: [], broken: [], read: [] })
|
|
19
|
-
|
|
20
|
-
/** a folder of that layout, read: its items by id, each head with its file's time, each message */
|
|
21
|
-
function folderOf(dir: string): { names: () => string[]; head: (id: string) => { head: unknown; at: number } | null; threadIds: (id: string) => string[]; message: (id: string, mid: string) => unknown; folder: (id: string) => string } {
|
|
22
|
-
return {
|
|
23
|
-
names: () => (existsSync(dir) ? readdirSync(dir).filter((n) => !n.startsWith('.') && ID_RE.test(n)).sort() : []),
|
|
24
|
-
head: (id) => {
|
|
25
|
-
const f = join(dir, id, 'item.json')
|
|
26
|
-
const s = statSync(f, { throwIfNoEntry: false })
|
|
27
|
-
return s ? { head: JSON.parse(readFileSync(f, 'utf8')) as unknown, at: Math.floor(s.mtimeMs) } : null
|
|
28
|
-
},
|
|
29
|
-
threadIds: (id) => {
|
|
30
|
-
const t = join(dir, id, 'thread')
|
|
31
|
-
if (!existsSync(t)) return []
|
|
32
|
-
return readdirSync(t)
|
|
33
|
-
.filter((n) => n.endsWith('.json'))
|
|
34
|
-
.map((n) => n.slice(0, -5))
|
|
35
|
-
.sort()
|
|
36
|
-
},
|
|
37
|
-
message: (id, mid) => JSON.parse(readFileSync(join(dir, id, 'thread', `${mid}.json`), 'utf8')) as unknown,
|
|
38
|
-
folder: (id) => join(dir, id),
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** the items a folder set aside, each one's id and its entry; none when `.gone` is no real folder */
|
|
43
|
-
function goneFolders(dir: string): { id: string; entry: string }[] {
|
|
44
|
-
const g = join(dir, GONE)
|
|
45
|
-
if (lstatSync(g, { throwIfNoEntry: false })?.isDirectory() !== true) return []
|
|
46
|
-
return readdirSync(g)
|
|
47
|
-
.flatMap((entry) => {
|
|
48
|
-
const id = /^(.+?)(?:\.(\d+))?$/.exec(entry)?.[1] ?? ''
|
|
49
|
-
return ID_RE.test(id) ? [{ id, entry }] : []
|
|
50
|
-
})
|
|
51
|
-
.sort((a, b) => (a.entry < b.entry ? -1 : 1))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** the files of an item's folder that are its media (its pictures, clips, posters, a message's image), never its head,
|
|
55
|
-
* its messages or its lock: what the rows keep in the spool */
|
|
56
|
-
function mediaOf(folder: string): string[] {
|
|
57
|
-
if (!existsSync(folder)) return []
|
|
58
|
-
const out: string[] = []
|
|
59
|
-
const walk = (d: string): void => {
|
|
60
|
-
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
61
|
-
const f = join(d, e.name)
|
|
62
|
-
const rel = relative(folder, f)
|
|
63
|
-
if (e.isDirectory()) {
|
|
64
|
-
if (e.name !== '.lock') walk(f)
|
|
65
|
-
} else if (!/^item(\.replaced)?\.json$/.test(rel) && !(rel.startsWith('thread/') && rel.endsWith('.json')) && !e.name.endsWith('.tmp') && !isLockFile(e.name)) out.push(rel)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
walk(folder)
|
|
69
|
-
return out
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** each file of `src` that `dst` lacks, linked there (copied across two disks): `src` stays as it is */
|
|
73
|
-
function carryFiles(src: string, dst: string, names: readonly string[]): number {
|
|
74
|
-
let n = 0
|
|
75
|
-
for (const rel of names) {
|
|
76
|
-
const t = join(dst, rel)
|
|
77
|
-
if (existsSync(t)) continue
|
|
78
|
-
n++
|
|
79
|
-
mkdirSync(dirname(t), { recursive: true })
|
|
80
|
-
try {
|
|
81
|
-
linkSync(join(src, rel), t)
|
|
82
|
-
} catch {
|
|
83
|
-
copyFileSync(join(src, rel), t)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return n
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** one item of the folder into the rows: its head when the rows lack it or hold an older one, each message they lack,
|
|
90
|
-
* its media into the spool. The head the rows hold later stays */
|
|
91
|
-
function importItem(id: string, from: ReturnType<typeof folderOf>, to: ItemBackend, out: Imported, dry: boolean, deleted: ReadonlySet<string>): void {
|
|
92
|
-
let h: { head: unknown; at: number } | null
|
|
93
|
-
try {
|
|
94
|
-
h = from.head(id)
|
|
95
|
-
} catch (e) {
|
|
96
|
-
out.broken.push(`${id}: ${(e as Error).message}`)
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
if (h == null) return void out.broken.push(`${id}: a folder with no item.json`)
|
|
100
|
-
const problems = itemProblems(h.head)
|
|
101
|
-
if (problems.length > 0 || (h.head as { id?: unknown }).id !== id) return void out.broken.push(`${id}: ${problems.join('; ') || 'another id in its head'}`)
|
|
102
|
-
const created = String((h.head as { created?: unknown }).created ?? '')
|
|
103
|
-
if (to.head(id) == null && deleted.has(`${id} ${created}`)) return void out.kept.push(`${id}: deleted in the rows, it stays deleted`)
|
|
104
|
-
const msgs: Message[] = []
|
|
105
|
-
for (const mid of from.threadIds(id)) {
|
|
106
|
-
try {
|
|
107
|
-
const m = from.message(id, mid)
|
|
108
|
-
const p = MESSAGE_RE.test(mid) ? messageProblems(m, mid) : ['no message name']
|
|
109
|
-
if (p.length > 0) out.broken.push(`${id}/${mid}: ${p.join('; ')}`)
|
|
110
|
-
else msgs.push(m as Message)
|
|
111
|
-
} catch (e) {
|
|
112
|
-
out.broken.push(`${id}/${mid}: ${(e as Error).message}`)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
out.items++
|
|
116
|
-
const there = to.head(id)
|
|
117
|
-
if (there != null && (there.head as { created?: unknown }).created !== (h.head as { created?: unknown }).created) return void out.kept.push(`${id}: another item of that id is in the rows, made at another moment: each stays`)
|
|
118
|
-
if (there == null || revOf(there.head) !== revOf(h.head)) {
|
|
119
|
-
if (there != null && there.at > h.at) out.kept.push(`${id}: the rows hold a later head, it stays`)
|
|
120
|
-
else {
|
|
121
|
-
// the head it replaces is an earlier write of the same item on this machine
|
|
122
|
-
if (!dry) to.write(id, h.head, h.at)
|
|
123
|
-
out.heads++
|
|
124
|
-
}
|
|
125
|
-
} else out.same++
|
|
126
|
-
for (const m of msgs) {
|
|
127
|
-
if (to.hasMessage(id, m.id)) {
|
|
128
|
-
if (revOf(to.message(id, m.id)) !== revOf(m)) out.kept.push(`${id}/${m.id}: another message of that id is in the rows, each stays`)
|
|
129
|
-
continue
|
|
130
|
-
}
|
|
131
|
-
if (!dry) to.append(id, m)
|
|
132
|
-
out.msgs++
|
|
133
|
-
}
|
|
134
|
-
out.read.push({ id, msgs: msgs.map((m) => m.id) })
|
|
135
|
-
const media = mediaOf(from.folder(id)).filter((rel) => !existsSync(join(to.folder(id), rel)))
|
|
136
|
-
out.files += media.length
|
|
137
|
-
if (!dry) carryFiles(from.folder(id), to.folder(id), media)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** every item of the folder `from` (the store's own old folder by default) the rows of `dir` lack, into them, with its
|
|
141
|
-
* items set aside. `dry` counts and writes nothing */
|
|
142
|
-
export function importFolders(dir: string, o: { from?: string; dry?: boolean } = {}): Imported {
|
|
143
|
-
const src = o.from ?? dir
|
|
144
|
-
const out = fresh(dir)
|
|
145
|
-
const from = folderOf(src)
|
|
146
|
-
const to = rowsIO(dir)
|
|
147
|
-
const deleted = new Set(rowsGone(dir).map((g) => `${g.id} ${rowsGoneCreated(dir, g.entry) ?? ''}`))
|
|
148
|
-
for (const id of from.names()) importItem(id, from, to, out, o.dry === true, deleted)
|
|
149
|
-
const held = new Set(rowsGone(dir).map((g) => g.entry))
|
|
150
|
-
for (const g of goneFolders(src)) {
|
|
151
|
-
if (held.has(g.entry)) continue
|
|
152
|
-
const folder = join(src, GONE, g.entry)
|
|
153
|
-
try {
|
|
154
|
-
const head = JSON.parse(readFileSync(join(folder, 'item.json'), 'utf8')) as { created?: unknown }
|
|
155
|
-
const t = join(folder, 'thread')
|
|
156
|
-
const thread = existsSync(t) ? readdirSync(t).filter((n) => n.endsWith('.json')).sort().map((n) => JSON.parse(readFileSync(join(t, n), 'utf8')) as unknown) : []
|
|
157
|
-
if (!o.dry) rowsKeepGone(dir, { entry: g.entry, id: g.id, created: typeof head.created === 'string' ? head.created : '', at: Math.floor(statSync(folder).ctimeMs), head, thread })
|
|
158
|
-
out.gone++
|
|
159
|
-
} catch (e) {
|
|
160
|
-
out.broken.push(`${GONE}/${g.entry}: ${(e as Error).message}`)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return out
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** what an import read that the rows do not hold: an item, or a message of one. Empty once it took everything */
|
|
167
|
-
export function notInRows(p: Imported): string[] {
|
|
168
|
-
const rows = rowsIO(p.dir)
|
|
169
|
-
return p.read.flatMap((r) => (rows.has(r.id) ? r.msgs.filter((m) => !rows.hasMessage(r.id, m)).map((m) => `message ${r.id}/${m}`) : [`item ${r.id}`]))
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** an import's lines, one a store that did something; a look says each store */
|
|
173
|
-
export function importLines(passes: readonly Imported[], dry: boolean): string[] {
|
|
174
|
-
const w = dry ? 'would ' : ''
|
|
175
|
-
const lines: string[] = []
|
|
176
|
-
for (const p of passes) {
|
|
177
|
-
if (p.heads + p.msgs + p.gone + p.files > 0 || dry) lines.push(`${p.dir}: ${p.items} items, ${w}write ${p.heads} heads and ${p.msgs} messages, ${w}carry ${p.files} media files, ${p.gone} items set aside, ${p.same} alike`)
|
|
178
|
-
for (const k of p.kept.slice(0, 5)) lines.push(` kept: ${k}`)
|
|
179
|
-
if (p.kept.length > 5) lines.push(` kept: and ${p.kept.length - 5} more`)
|
|
180
|
-
// a folder that does not read stays a folder: never a row, never lost, said here
|
|
181
|
-
if (p.broken.length > 0) lines.push(` ${p.broken.length} files do not read and stay as they are (${p.broken.slice(0, 3).join('; ')})`)
|
|
182
|
-
}
|
|
183
|
-
return lines
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** items of the rows written as folders into `to`, never the store's own: each head, message and media file this
|
|
187
|
-
* machine still holds; a media file the disk let go is named, its key in the head's media. Nothing in the rows moves */
|
|
188
|
-
export function exportFolders(dir: string, to: string, ids?: readonly string[]): Imported {
|
|
189
|
-
const out = fresh(dir)
|
|
190
|
-
out.media = { copied: 0, missing: [] }
|
|
191
|
-
const rows = rowsIO(dir)
|
|
192
|
-
for (const id of ids ?? rows.names()) {
|
|
193
|
-
const h = rows.head(id)
|
|
194
|
-
if (h == null) {
|
|
195
|
-
out.kept.push(`${id}: no item of that id in the rows`)
|
|
196
|
-
continue
|
|
197
|
-
}
|
|
198
|
-
out.items++
|
|
199
|
-
const folder = join(to, id)
|
|
200
|
-
mkdirSync(join(folder, 'thread'), { recursive: true })
|
|
201
|
-
const head = join(folder, 'item.json')
|
|
202
|
-
writeFileSync(head, jsonText(h.head))
|
|
203
|
-
utimesSync(head, new Date(h.at), new Date(h.at))
|
|
204
|
-
out.heads++
|
|
205
|
-
for (const mid of rows.threadIds(id)) {
|
|
206
|
-
writeFileSync(join(folder, 'thread', `${mid}.json`), jsonText(rows.message(id, mid)))
|
|
207
|
-
out.msgs++
|
|
208
|
-
}
|
|
209
|
-
const x = rows.raw(id)
|
|
210
|
-
const names = x == null ? [] : mediaFilesOf(x)
|
|
211
|
-
const here = names.filter((n) => existsSync(join(rows.folder(id), n)))
|
|
212
|
-
out.media.copied += carryFiles(rows.folder(id), folder, here)
|
|
213
|
-
for (const n of names) if (!here.includes(n)) out.media.missing.push(`${id}/${n}`)
|
|
214
|
-
}
|
|
215
|
-
return out
|
|
216
|
-
}
|
package/src/review/hook-ask.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// the inbox hook asks the daemon first (wiki tools/shipkit/threads-how-it-fits.md, The inbox hook): one request on its
|
|
2
|
-
// loopback port, answered by its hook thread (serve/hook-thread.ts) from what that thread keeps warm, and the lines
|
|
3
|
-
// printed as the hook's own. Any doubt is « not served », and the hook runs in its own process as before
|
|
4
|
-
// (cli/inbox-hook-run.ts).
|
|
5
|
-
// the one constraint a reader breaks first: this module is the whole cost of a served hook, so it imports nothing but
|
|
6
|
-
// the daemon's port; a module added here is paid at every prompt of every agent (tests/hook-served.test.ts counts them)
|
|
7
|
-
import { daemonPort } from '../core/daemon-port.ts'
|
|
8
|
-
|
|
9
|
-
/** the request and its answer between the hook and the daemon's hook thread: a change of either moves the version */
|
|
10
|
-
export const HOOK_WIRE = 1
|
|
11
|
-
export const HOOK_PATH = '/api/hook/inbox'
|
|
12
|
-
|
|
13
|
-
/** the env a hook's work reads: who acts (Claude Code's session, a lane, an orchestrator) and where the stores are */
|
|
14
|
-
export const hookEnvKey = (k: string): boolean => /^(CLAUDE_|SK_|SHIPKIT_)/.test(k) || k === 'HOME' || k === 'CI'
|
|
15
|
-
|
|
16
|
-
export interface HookAsk {
|
|
17
|
-
v: number
|
|
18
|
-
/** the shipkit source this hook runs: only a daemon on the same tree answers */
|
|
19
|
-
src: string
|
|
20
|
-
cwd: string
|
|
21
|
-
/** the hook's stdin as Claude Code wrote it */
|
|
22
|
-
text: string
|
|
23
|
-
env: Record<string, string>
|
|
24
|
-
/** epoch ms past which the daemon starts no work for it: the hook has run it itself by then */
|
|
25
|
-
until: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** a served hook: what its work printed on stdout and stderr, as it printed it, and its exit code */
|
|
29
|
-
export type HookServed = { served: true; out: string; err: string; code: number }
|
|
30
|
-
export type HookAnswer = HookServed | { served: false; why: string }
|
|
31
|
-
|
|
32
|
-
/** how soon the daemon's hook thread must start the work, from the hook's ask: a thread that cannot (cold, busy with
|
|
33
|
-
* other hooks, its loop held) answers « not served » at once and does none of it, so the hook runs it itself and the
|
|
34
|
-
* work never runs twice. A warm thread starts within a few ms of the ask on the Mac that set it */
|
|
35
|
-
export const HOOK_START_MS = 60
|
|
36
|
-
/** how long the hook waits for an answer once asked: a thread that started the work finishes it (20 to 30 ms on that
|
|
37
|
-
* Mac), so the hook waits for it rather than run it a second time; past this the daemon is stalled */
|
|
38
|
-
export const HOOK_WAIT_MS = 1_000
|
|
39
|
-
|
|
40
|
-
const set = (v: string | undefined): boolean => v !== undefined && v !== '' && v !== '0'
|
|
41
|
-
|
|
42
|
-
/** the daemon's answer to this hook, null when it did not serve it: no home here (CI, SHIPKIT_NO_HOME), the daemon
|
|
43
|
-
* down, slow to start it (HOOK_START_MS) or stalled (HOOK_WAIT_MS), on another tree or older code, or the env moves a
|
|
44
|
-
* store it does not hold */
|
|
45
|
-
export async function askDaemon(text: string, cwd: string, env: Record<string, string | undefined> = process.env, o: { start?: number; wait?: number } = {}): Promise<HookServed | null> {
|
|
46
|
-
if (set(env.CI) || set(env.SHIPKIT_NO_HOME)) return null
|
|
47
|
-
const own: Record<string, string> = {}
|
|
48
|
-
for (const [k, v] of Object.entries(env)) if (v !== undefined && hookEnvKey(k)) own[k] = v
|
|
49
|
-
const ask: HookAsk = { v: HOOK_WIRE, src: import.meta.dir.slice(0, -'/review'.length), cwd, text, env: own, until: Date.now() + (o.start ?? HOOK_START_MS) }
|
|
50
|
-
try {
|
|
51
|
-
const r = await fetch(`http://127.0.0.1:${daemonPort(env)}${HOOK_PATH}`, { method: 'POST', body: JSON.stringify(ask), headers: { 'content-type': 'application/json' }, signal: AbortSignal.timeout(o.wait ?? HOOK_WAIT_MS) })
|
|
52
|
-
if (!r.ok) return null
|
|
53
|
-
const a = (await r.json()) as HookAnswer
|
|
54
|
-
return a.served === true && typeof a.out === 'string' && typeof a.err === 'string' && Number.isInteger(a.code) ? a : null
|
|
55
|
-
} catch {
|
|
56
|
-
return null
|
|
57
|
-
}
|
|
58
|
-
}
|
package/src/review/role.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// the dispatcher role (wiki tools/shipkit/threads.md, Raised items): one session routes what the owner, the players and
|
|
2
|
-
// the rules raise. Its file sits beside the store, out of the store's watch
|
|
3
|
-
import { mkdirSync, readFileSync } from 'node:fs'
|
|
4
|
-
import { join } from 'node:path'
|
|
5
|
-
import { AGENT_RE } from './model.ts'
|
|
6
|
-
import { atomicWriteJson } from '../core/atomic-write.ts'
|
|
7
|
-
|
|
8
|
-
/** the role's holder, and when it last acted */
|
|
9
|
-
export interface Role {
|
|
10
|
-
name: string
|
|
11
|
-
since: string
|
|
12
|
-
beat: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const roleFile = (dir: string): string => join(dir, '..', 'review-dispatcher.json')
|
|
16
|
-
/** another session may take the role once its holder did nothing for this long */
|
|
17
|
-
export const ROLE_IDLE_MS = 30 * 60 * 1000
|
|
18
|
-
|
|
19
|
-
export function roleOf(dir: string): Role | null {
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(readFileSync(roleFile(dir), 'utf8')) as Role
|
|
22
|
-
} catch {
|
|
23
|
-
return null
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** `name` takes the role: refused while another holder acted within ROLE_IDLE_MS, unless `take` */
|
|
28
|
-
export function takeRole(dir: string, name: string, take: boolean, now = new Date()): { ok: true; was: Role | null } | { ok: false; why: string } {
|
|
29
|
-
if (!AGENT_RE.test(name)) return { ok: false, why: `« ${name} » is no agent name (${AGENT_RE.source})` }
|
|
30
|
-
const was = roleOf(dir)
|
|
31
|
-
if (was && was.name !== name && !take && now.getTime() - Date.parse(was.beat) < ROLE_IDLE_MS)
|
|
32
|
-
return { ok: false, why: `${was.name} holds the dispatcher role (active ${Math.round((now.getTime() - Date.parse(was.beat)) / 60000)} min ago): --take to take it over` }
|
|
33
|
-
const at = now.toISOString()
|
|
34
|
-
writeRole(dir, { name, since: was?.name === name ? was.since : at, beat: at })
|
|
35
|
-
return { ok: true, was }
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** the holder acted: its beat moves to `now` */
|
|
39
|
-
export function beatRole(dir: string, now: Date): void {
|
|
40
|
-
const r = roleOf(dir)
|
|
41
|
-
if (r) writeRole(dir, { ...r, beat: now.toISOString() })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function writeRole(dir: string, r: Role): void {
|
|
45
|
-
const file = roleFile(dir)
|
|
46
|
-
mkdirSync(join(file, '..'), { recursive: true })
|
|
47
|
-
atomicWriteJson(file, r, { indent: 4 })
|
|
48
|
-
}
|