rvlib-shipkit 2.27.0 → 2.28.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 +16 -0
- package/package.json +1 -1
- package/src/agent-time/hooks.ts +10 -3
- package/src/agent-time/live.ts +11 -5
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/store.ts +2 -2
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +12 -11
- package/src/asks/ask-after.ts +6 -2
- package/src/asks/ask-bar-fold.ts +57 -0
- package/src/asks/ask-migrate.ts +280 -0
- package/src/asks/ask-steps-fold.ts +166 -0
- package/src/asks/ask-store.ts +586 -0
- package/src/assets/kits/identity-kit.ts +106 -38
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +8 -4
- package/src/checks/SK013-one-way-in-policy.check.ts +10 -0
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- package/src/cli/cmd_Asks.ts +204 -53
- package/src/cli/cmd_Backup.ts +151 -8
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Review.ts +931 -229
- package/src/cli/cmd_Secret.ts +255 -34
- package/src/cli/cmd_Social.ts +36 -33
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +146 -0
- package/src/cli/cmd_ThreadReflect.ts +83 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- package/src/cli/cmd_Vault.ts +1 -1
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +2 -2
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +21 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +25 -74
- package/src/collections/collection-types.ts +9 -5
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +53 -61
- package/src/collections/reflections.ts +9 -4
- package/src/core/discover-checks.ts +18 -3
- package/src/core/git.ts +31 -0
- package/src/core/house-layout.ts +17 -0
- package/src/core/layout.ts +10 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-db.ts +5 -3
- package/src/core/migrate-layout.ts +8 -10
- package/src/home/activity.ts +8 -15
- package/src/home/daemon-jobs.ts +13 -1
- package/src/home/home-paths.ts +6 -3
- package/src/home/home-routes.ts +8 -0
- package/src/home/inbox-shape.ts +233 -100
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +10 -15
- package/src/home/machine-host.ts +19 -1
- package/src/home/other-macs.ts +2 -2
- package/src/home/serve-web.ts +6 -5
- package/src/home/space-page.ts +1 -1
- package/src/home/vault-page.ts +51 -17
- package/src/home/vault-words.ts +2 -2
- package/src/hooks/one-way-in-guard.ts +24 -2
- package/src/hq/files-send.ts +27 -28
- package/src/hq/hq-db.ts +4 -1
- package/src/hq/hq-local.ts +37 -4
- package/src/hq/hq-routes.ts +10 -2
- package/src/hq/hq-store.ts +6 -2
- package/src/hq/kinds/ask.ts +6 -6
- package/src/hq/outbox.ts +5 -3
- package/src/hq/replica.ts +1 -2
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +9 -8
- package/src/identities/machine-route.ts +8 -3
- package/src/ledger/db.ts +8 -1
- package/src/media-store/backup/daemon.ts +48 -8
- package/src/media-store/backup/keys.ts +1 -1
- package/src/media-store/backup/manifest.ts +20 -2
- package/src/media-store/backup/prune.ts +365 -0
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +14 -8
- package/src/media-store/backup/sources.ts +18 -17
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +3 -4
- package/src/media-store/copy/store.ts +2 -2
- package/src/media-store/db.ts +2 -2
- package/src/media-store/forget.ts +118 -0
- package/src/media-store/purge.ts +3 -2
- package/src/media-store/space-listing.ts +20 -4
- package/src/media-store/space.ts +6 -5
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +1 -1
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +2 -2
- package/src/messages/score.ts +1 -1
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +181 -4
- package/src/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +2 -1
- package/src/release/git-facts.ts +3 -2
- package/src/release/public-clean.ts +3 -2
- package/src/repo-config.ts +40 -18
- package/src/review/anim.ts +1 -1
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +16 -6
- package/src/review/card-rows.ts +4 -3
- package/src/review/cells.ts +297 -65
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +8 -16
- package/src/review/draft-model.ts +2 -2
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +128 -14
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +1 -1
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +41 -0
- package/src/review/inbox-hook.ts +22 -9
- package/src/review/inbox-read.ts +201 -0
- package/src/review/instructions.ts +199 -0
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kinds.ts +278 -0
- package/src/review/lane-ask.ts +109 -0
- package/src/review/model.ts +396 -86
- package/src/review/move.ts +3 -3
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +182 -0
- package/src/review/previews.ts +3 -1
- package/src/review/projections.ts +235 -0
- package/src/review/referring.ts +54 -0
- package/src/review/reflection-object.ts +195 -0
- package/src/review/routes.ts +137 -32
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +4 -4
- package/src/review/store.ts +366 -85
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +20 -7
- package/src/review/threads.ts +236 -39
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-card.ts +2 -2
- package/src/review/unit.ts +71 -5
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/wait.ts +85 -0
- package/src/review/watchers.ts +22 -9
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +83 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +8 -5
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +16 -22
- package/src/secrets/manager.ts +31 -16
- package/src/secrets/read.ts +161 -33
- package/src/secrets/tail.ts +31 -0
- package/src/serve/hub-app/asks-page.tsx +2 -1
- package/src/serve/hub-app/auto-text.tsx +14 -6
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +31 -40
- package/src/serve/hub-app/col-list-page.tsx +5 -2
- package/src/serve/hub-app/col-tables-view.tsx +7 -4
- package/src/serve/hub-app/col-tables.ts +5 -5
- package/src/serve/hub-app/cols-svc.ts +4 -79
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/controls.css +83 -0
- package/src/serve/hub-app/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/home-st.ts +57 -6
- package/src/serve/hub-app/home-strip.css +1 -6
- package/src/serve/hub-app/home-strip.tsx +2 -1
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +48 -32
- package/src/serve/hub-app/hub-types.ts +2 -0
- package/src/serve/hub-app/hub.css +50 -61
- package/src/serve/hub-app/icons.tsx +14 -4
- package/src/serve/hub-app/identities-view.tsx +4 -3
- package/src/serve/hub-app/inbox-st.ts +203 -42
- package/src/serve/hub-app/inbox-view.tsx +189 -101
- package/src/serve/hub-app/inbox.css +47 -44
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/keys.ts +5 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-view.tsx +4 -11
- package/src/serve/hub-app/machines.css +0 -9
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +18 -40
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +2 -2
- package/src/serve/hub-app/messages/messages-page.tsx +2 -1
- package/src/serve/hub-app/messages/messages-st.ts +1 -1
- package/src/serve/hub-app/messages.css +0 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +1 -1
- package/src/serve/hub-app/pages-frames.tsx +11 -1
- package/src/serve/hub-app/palette-st.ts +4 -4
- package/src/serve/hub-app/pane-boundary.tsx +72 -0
- package/src/serve/hub-app/pane-errors.ts +54 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/planned-view.tsx +3 -3
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +5 -13
- package/src/serve/hub-app/project-list.tsx +3 -6
- package/src/serve/hub-app/projects-svc.ts +6 -2
- package/src/serve/hub-app/readme.css +9 -15
- package/src/serve/hub-app/reflections-page.tsx +54 -1
- package/src/serve/hub-app/releases/releases-page.tsx +3 -2
- package/src/serve/hub-app/releases.css +0 -1
- package/src/serve/hub-app/review/code-colors.ts +30 -0
- package/src/serve/hub-app/review/diff-view.tsx +75 -0
- package/src/serve/hub-app/review/dock.tsx +104 -0
- package/src/serve/hub-app/review/draft-card.tsx +2 -2
- package/src/serve/hub-app/review/group-block.tsx +209 -0
- package/src/serve/hub-app/review/instructions-view.tsx +116 -0
- package/src/serve/hub-app/review/item-verdict.tsx +38 -0
- package/src/serve/hub-app/review/kind-states.tsx +193 -0
- package/src/serve/hub-app/review/kind-view.tsx +1 -37
- package/src/serve/hub-app/review/kit.tsx +57 -54
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- package/src/serve/hub-app/review/object-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +179 -0
- package/src/serve/hub-app/review/question-views.tsx +385 -0
- package/src/serve/hub-app/review/review-cells.tsx +86 -105
- package/src/serve/hub-app/review/review-list.tsx +104 -47
- package/src/serve/hub-app/review/review-page.tsx +5 -4
- package/src/serve/hub-app/review/review-st.ts +68 -28
- package/src/serve/hub-app/review/review-thread.tsx +171 -40
- package/src/serve/hub-app/review/review-views.tsx +35 -31
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control.tsx +4 -4
- package/src/serve/hub-app/review/thread-st.ts +222 -22
- package/src/serve/hub-app/review/trailer-card.tsx +1 -1
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +216 -57
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +23 -10
- package/src/serve/hub-app/social/kit.tsx +8 -15
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +3 -0
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +5 -9
- package/src/serve/hub-app/social/social-model.ts +13 -5
- package/src/serve/hub-app/social/social-page.tsx +1 -1
- package/src/serve/hub-app/social/social-st.ts +42 -5
- package/src/serve/hub-app/social.css +7 -17
- package/src/serve/hub-app/space.css +1 -1
- package/src/serve/hub-app/stores/stores-page.tsx +6 -2
- package/src/serve/hub-app/thread-row.tsx +101 -0
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-view.tsx +2 -1
- package/src/serve/hub-app/time.css +2 -5
- package/src/serve/hub-app/tree-row.tsx +1 -9
- package/src/serve/hub-app/vault-view.tsx +4 -4
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +4 -4
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +30 -4
- package/src/serve/hub-app/wikis-view.tsx +4 -3
- package/src/serve/hub-runtime.ts +20 -6
- package/src/serve/project-gutter-route.ts +16 -6
- package/src/serve/project-gutter.ts +6 -53
- package/src/serve/same-origin.ts +3 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +29 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit.ts +2 -2
- package/src/site/desk.ts +2 -2
- package/src/smoke/run-smoke.ts +3 -4
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/desk-index.ts +34 -13
- package/src/social/drafts.ts +4 -4
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +89 -64
- package/src/social/media-kind.ts +68 -161
- package/src/social/media-of.ts +5 -4
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +103 -0
- package/src/social/posts.ts +378 -0
- package/src/social/presence.ts +7 -5
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +2 -2
- package/src/social/release-stage.ts +58 -57
- package/src/social/routes.ts +64 -24
- package/src/social/stage.ts +42 -57
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +135 -43
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/desk.ts +16 -11
- package/src/stores/unit.ts +2 -2
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/urls/rows.ts +1 -1
- package/src/vault/vault-http.ts +11 -3
- package/src/vault/vault-import.ts +6 -1
- package/src/veille/identity.ts +2 -2
- package/src/wiki/graph-pages.ts +13 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/asks/asks-queue.ts +0 -424
- package/src/messages/suggest.ts +0 -96
- package/src/social/migrate.ts +0 -123
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 2.28.0
|
|
2
|
+
|
|
3
|
+
- **Threads replace review cards.** One thread per subject at its own address; the hub, the CLI and the hooks speak of threads only. A thread holds objects of many kinds: messages, versions, before and after, typed diffs, questions with buttons, proposed changes, instructions, checklists, secret fields, 3D views, branches. Every item can ask the owner's verdict (`--verdict`); « judge », « answer » and « do » filter the list by what waits on the owner.
|
|
4
|
+
- **The timeline is where everything lives.** Every item shows in full in the thread, the owner's messages in the same left column; the dock above the reply box is only a stack of one line reminders that jump to their item. Every action on an object is one muted trace line.
|
|
5
|
+
- **Objects stand on their own.** A thread item refers to objects by kind and id, so one object can appear in many threads; an object an agent creates is linked to its lane's thread in the same call, never an orphan. Every kind declares its widget, its SVG icon and a muted colour; one side panel opens any object whole. `sk thread kinds` writes the always loaded catalog and the objects page.
|
|
6
|
+
- **Events, like Matrix.** One append only table of events, per kind projections rebuilt and checked (`sk thread events --check`). Posts live there: one post per platform in a group, draft, posted or dropped; the comms page indexes them.
|
|
7
|
+
- **Asks are threads.** An ask's instructions are its checklist: each `##` heading is a step the owner ticks, a step can hold a secret, url or text field, and a step ticks itself once its fields are in. `--replaces` gives an ask new instructions and folds the old ones. An ask closes on its check or the owner's « done », never on answers alone.
|
|
8
|
+
- **Holders and lanes.** Each thread shows who holds it and whether anyone hears it. `sk thread seen` and `sk thread working` show the owner that an agent read and works on the owner's words. « Start a lane » on a thread notifies the orchestrator, who assigns it (`sk thread assign`); nothing starts a process by itself. A branch attached to a thread holds it open until it merges.
|
|
9
|
+
- **Reflections are objects**, read from their file, linked into the thread of the agent that wrote them (`sk thread reflect`), with accept, rework and discard on the object.
|
|
10
|
+
- **Personas, value propositions, phrasings and page tops** are objects read from the messages store; `sk messages propose` suggests one in a thread and an approval writes it back.
|
|
11
|
+
- **Secrets.** `sk secret` does everything: `tail` shows only the masked end a dashboard shows, `archive` and `unarchive` soft delete in the vault, `rm --keychain|--vault` says what it removes. A registry row can mark a token that may lapse, with its refresh command: expired, its probe informs instead of failing. A second machine reads the one master vault over the tailnet.
|
|
12
|
+
- **Backups keep a calendar:** every run of the last day, then one per day, week and month, set in one place; `sk backup pin` keeps a run.
|
|
13
|
+
- **Every command named.** The everyday commands page and each project CLI's essentials page name every command; a guard fails on one missing.
|
|
14
|
+
- **`sk sound credits`** reads the ElevenLabs balance in one free call.
|
|
15
|
+
- **Faster tests.** One git interface with a fake checked against real git, a suite home that never waits for the disk, fewer spawns.
|
|
16
|
+
|
|
1
17
|
## 2.27.0
|
|
2
18
|
|
|
3
19
|
- **The hq: one place for every machine.** Every daemon carries an hq and reports to it (`sk machines`); another machine joins with `sk hq`. Review cards, asks, reflections, prompts and agent time days travel through it, each behind its own switch. `sk hq replicate` and `sk hq drill` keep a second copy and prove it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rvlib-shipkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.0",
|
|
4
4
|
"funding": "https://github.com/sponsors/rvion",
|
|
5
5
|
"description": "All-in-one repo companion: ci gate (task DAG), auto-discovered health checks, release-contract fulfillness, asks queue, md-wiki tools, asset atelier, live tui",
|
|
6
6
|
"license": "MIT",
|
package/src/agent-time/hooks.ts
CHANGED
|
@@ -137,11 +137,18 @@ const PROBE_ID = 'shipkit-hook-probe'
|
|
|
137
137
|
/** the probe runs a hook only on what the harness itself sends for a Bash
|
|
138
138
|
* `true`, a call that changes nothing, so it does no more than a real no-op
|
|
139
139
|
* call does. A hook whose matcher takes no Bash call is never run: on a
|
|
140
|
-
* made up save it may write, and its cost hangs on the file it is given
|
|
141
|
-
|
|
140
|
+
* made up save it may write, and its cost hangs on the file it is given. The one exception is shipkit's own PreToolUse
|
|
141
|
+
* guard, which only reads and decides: on an edit it is probed on its heaviest path, an Edit of the messages store
|
|
142
|
+
* that adds nothing (hooks/one-way-in-guard.ts) */
|
|
143
|
+
const ownGuard = (h: DeclaredHook): boolean => h.event === 'PreToolUse' && h.command.includes('one-way-in-guard')
|
|
144
|
+
const editsOnly = (h: DeclaredHook): boolean => !matcherMatches(h.matcher, 'Bash') && ownGuard(h) && matcherMatches(h.matcher, 'Edit')
|
|
145
|
+
export const probeable = (h: DeclaredHook): boolean => h.command !== '' && (h.event === 'PreToolUse' || h.event === 'PostToolUse') && (matcherMatches(h.matcher, 'Bash') || editsOnly(h))
|
|
142
146
|
|
|
143
147
|
export function probeInput(h: DeclaredHook, root: string): string {
|
|
144
|
-
const
|
|
148
|
+
const tool = editsOnly(h)
|
|
149
|
+
? { tool_name: 'Edit', tool_input: { file_path: `${root}/.shipkit/messages/messages.md`, old_string: 'shipkit-hook-probe', new_string: 'shipkit-hook-probe' } }
|
|
150
|
+
: { tool_name: 'Bash', tool_input: { command: 'true', description: 'a no-op' } }
|
|
151
|
+
const base = { session_id: PROBE_ID, transcript_path: '', cwd: root, permission_mode: 'default', hook_event_name: h.event, ...tool, tool_use_id: PROBE_ID }
|
|
145
152
|
return JSON.stringify(h.event === 'PostToolUse' ? { ...base, tool_response: { stdout: '', stderr: '', interrupted: false, isImage: false } } : base)
|
|
146
153
|
}
|
|
147
154
|
|
package/src/agent-time/live.ts
CHANGED
|
@@ -133,13 +133,19 @@ export function oneRowAnAgent<T extends { session: string; agent: string; mtime:
|
|
|
133
133
|
return [...by.values()]
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
/** the rows as a table, repos in name order, a session before its lanes
|
|
137
|
-
|
|
136
|
+
/** the rows as a table, repos in name order, a session before its lanes. A session and its lanes share one repo, the
|
|
137
|
+
* session's (its lanes' when its own transcript names no folder, as a session resumed in another account's does), so a
|
|
138
|
+
* lane never reads under another session. `tag`: words after a row's name (who hears for it) */
|
|
139
|
+
export function liveTable(rows: readonly LiveRow[], now: number, tag: (r: LiveRow) => string = () => ''): string[] {
|
|
138
140
|
if (rows.length === 0) return ['no agent wrote in the window']
|
|
139
|
-
const
|
|
141
|
+
const repoOfSession = new Map<string, string>()
|
|
142
|
+
for (const r of [...rows].sort((a, b) => Number(a.agent !== '') - Number(b.agent !== '')))
|
|
143
|
+
if (r.cwd !== '' && !repoOfSession.has(r.session)) repoOfSession.set(r.session, repoOf(r))
|
|
144
|
+
const group = (r: LiveRow): string => repoOfSession.get(r.session) ?? repoOf(r)
|
|
145
|
+
const sorted = [...rows].sort((a, b) => group(a).localeCompare(group(b)) || a.session.localeCompare(b.session) || (a.agent === '' ? -1 : b.agent === '' ? 1 : (a.startedAt ?? 0) - (b.startedAt ?? 0)))
|
|
140
146
|
const cells = sorted.map((r) => [
|
|
141
|
-
|
|
142
|
-
r.agent === '' ? `session ${r.session.slice(0, 8)}` : ` ${r.name === '' ? r.agent.slice(0, 12) : r.name}${r.model === '' ? '' : ` [${r.model}]`}`,
|
|
147
|
+
group(r),
|
|
148
|
+
`${r.agent === '' ? `session ${r.session.slice(0, 8)}` : ` ${r.name === '' ? r.agent.slice(0, 12) : r.name}${r.model === '' ? '' : ` [${r.model}]`}`}${tag(r)}`,
|
|
143
149
|
r.startedAt == null ? '?' : span(now - r.startedAt),
|
|
144
150
|
r.calls == null ? '-' : String(r.calls),
|
|
145
151
|
doing(r, now),
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// the registry of parties (wiki tools/shipkit/threads-how-it-fits.md, The rules): each Claude Code session that acted in
|
|
2
|
+
// a thread, its process and the stores it and its lanes wrote in, one small file per session; its lanes read from the
|
|
3
|
+
// transcripts `sk lanes` already reads; the watches from each store's watcher files. Its one reader: readParties
|
|
4
|
+
import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { basename, dirname, join } from 'node:path'
|
|
6
|
+
import { stateOf } from './live.ts'
|
|
7
|
+
import { pidAlive } from '../review/watchers.ts'
|
|
8
|
+
import { machinePath } from '../core/machine-layout.ts'
|
|
9
|
+
import type { Watcher } from '../review/model.ts'
|
|
10
|
+
import { NO_PARTIES, type LaneParty, type Parties, type SessionParty } from '../review/parties.ts'
|
|
11
|
+
|
|
12
|
+
/** one session as its acts left it: the process that runs it, the repo it was in, the stores it or its lanes wrote in */
|
|
13
|
+
export interface SessionRecord {
|
|
14
|
+
session: string
|
|
15
|
+
pid: number
|
|
16
|
+
stores: string[]
|
|
17
|
+
at: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const sessionsDir = (): string => process.env.SHIPKIT_SESSIONS_DIR ?? machinePath('agent-sessions')
|
|
21
|
+
|
|
22
|
+
const fileOf = (session: string): string => join(sessionsDir(), `${session.replace(/[^\w-]/g, '_')}.json`)
|
|
23
|
+
|
|
24
|
+
function readRecord(file: string): SessionRecord | null {
|
|
25
|
+
try {
|
|
26
|
+
const v = JSON.parse(readFileSync(file, 'utf8')) as SessionRecord
|
|
27
|
+
return typeof v.session === 'string' && Number.isInteger(v.pid) && Array.isArray(v.stores) ? v : null
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** the session of this process acted on `store`: its record names the store and its process. Silent and cheap: it
|
|
34
|
+
* writes only when something changed, and never fails the act that called it */
|
|
35
|
+
export function noteSession(store: string, o: { env?: Record<string, string | undefined>; now?: Date } = {}): void {
|
|
36
|
+
const env = o.env ?? process.env
|
|
37
|
+
const session = env.CLAUDE_CODE_SESSION_ID?.trim()
|
|
38
|
+
const pid = Number(env.CLAUDE_PID)
|
|
39
|
+
if (!session || !Number.isInteger(pid) || pid <= 0) return
|
|
40
|
+
try {
|
|
41
|
+
const file = fileOf(session)
|
|
42
|
+
const was = readRecord(file)
|
|
43
|
+
if (was && was.pid === pid && was.stores.includes(store)) return
|
|
44
|
+
const r: SessionRecord = { session, pid, stores: [...new Set([...(was?.pid === pid ? was.stores : []), store])], at: (o.now ?? new Date()).toISOString() }
|
|
45
|
+
mkdirSync(sessionsDir(), { recursive: true })
|
|
46
|
+
writeFileSync(`${file}.${process.pid}.tmp`, `${JSON.stringify(r)}\n`)
|
|
47
|
+
renameSync(`${file}.${process.pid}.tmp`, file)
|
|
48
|
+
} catch {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** stores a session's hook can no longer act in (a folder gone, a repo no longer shipkit's) leave its record, so no
|
|
52
|
+
* hook asks about them again */
|
|
53
|
+
export function forgetStores(session: string, gone: readonly string[]): void {
|
|
54
|
+
if (gone.length === 0) return
|
|
55
|
+
try {
|
|
56
|
+
const file = fileOf(session)
|
|
57
|
+
const was = readRecord(file)
|
|
58
|
+
if (was === null) return
|
|
59
|
+
const r: SessionRecord = { ...was, stores: was.stores.filter((s) => !gone.includes(s)) }
|
|
60
|
+
writeFileSync(`${file}.${process.pid}.tmp`, `${JSON.stringify(r)}\n`)
|
|
61
|
+
renameSync(`${file}.${process.pid}.tmp`, file)
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function readSessionRecords(): SessionRecord[] {
|
|
66
|
+
let names: string[]
|
|
67
|
+
try {
|
|
68
|
+
names = readdirSync(sessionsDir())
|
|
69
|
+
} catch {
|
|
70
|
+
return []
|
|
71
|
+
}
|
|
72
|
+
return names.filter((n) => n.endsWith('.json')).flatMap((n) => readRecord(join(sessionsDir(), n)) ?? [])
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** a lane's name from the description its session gave it: its first word (`L26 richer threads` → `L26`) */
|
|
76
|
+
export const laneNameOf = (description: string): string | null => {
|
|
77
|
+
const w = description.trim().split(/\s+/)[0] ?? ''
|
|
78
|
+
return /^[A-Za-z][A-Za-z0-9-]{0,23}$/.test(w) ? w : null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** every name a lane may carry: its description's first word, and in its brief (the first message its session sent
|
|
82
|
+
* it) an `export SK_AGENT=<name>` or « you are lane L<n> », so a lane whose description says other words is still
|
|
83
|
+
* found. Only the brief: later lines quote help examples and other lanes' names */
|
|
84
|
+
export function laneNamesOf(description: string, brief: string): string[] {
|
|
85
|
+
const out = new Set<string>()
|
|
86
|
+
const first = laneNameOf(description)
|
|
87
|
+
if (first) out.add(first)
|
|
88
|
+
for (const m of brief.matchAll(/export SK_AGENT=([A-Za-z][A-Za-z0-9-]{0,23})\b/g)) out.add(m[1]!)
|
|
89
|
+
for (const m of brief.matchAll(/\byou are (?:lane )?(L\d{1,5})\b/gi)) out.add(m[1]!)
|
|
90
|
+
return [...out]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** a lane's brief: the text of the first user message of its transcript */
|
|
94
|
+
function headOf(path: string): string {
|
|
95
|
+
try {
|
|
96
|
+
const fd = openSync(path, 'r')
|
|
97
|
+
try {
|
|
98
|
+
const buf = Buffer.alloc(64 * 1024)
|
|
99
|
+
const n = readSync(fd, buf, 0, buf.length, 0)
|
|
100
|
+
for (const line of buf.subarray(0, n).toString('utf8').split('\n')) {
|
|
101
|
+
let e: { type?: string; message?: { content?: unknown } }
|
|
102
|
+
try {
|
|
103
|
+
e = JSON.parse(line) as typeof e
|
|
104
|
+
} catch {
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
if (e.type !== 'user') continue
|
|
108
|
+
const c = e.message?.content
|
|
109
|
+
return typeof c === 'string' ? c : Array.isArray(c) ? c.map((p: { text?: unknown }) => (typeof p?.text === 'string' ? p.text : '')).join('\n') : ''
|
|
110
|
+
}
|
|
111
|
+
return ''
|
|
112
|
+
} finally {
|
|
113
|
+
closeSync(fd)
|
|
114
|
+
}
|
|
115
|
+
} catch {
|
|
116
|
+
return ''
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** the processes among `pids` that live and run Claude Code, in one `ps` */
|
|
121
|
+
export function claudeAlive(pids: readonly number[]): Set<number> {
|
|
122
|
+
const out = new Set<number>()
|
|
123
|
+
// only the pids a signal reaches: one gone or out of range makes `ps` refuse the whole list
|
|
124
|
+
const live = [...new Set(pids)].filter((p) => Number.isInteger(p) && p > 0 && pidAlive(p))
|
|
125
|
+
if (live.length === 0) return out
|
|
126
|
+
const ps = Bun.spawnSync(['ps', '-o', 'pid=,comm=', '-p', live.join(',')], { stdout: 'pipe', stderr: 'ignore' })
|
|
127
|
+
for (const line of (ps.stdout?.toString() ?? '').split('\n')) {
|
|
128
|
+
const m = /^\s*(\d+)\s+(.*)$/.exec(line)
|
|
129
|
+
if (m && /claude/i.test(m[2]!.split('/').at(-1) ?? '')) out.add(Number(m[1]))
|
|
130
|
+
}
|
|
131
|
+
return out
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** a lane that wrote nothing for this long has ended, whatever its last entry says */
|
|
135
|
+
export const LANE_IDLE_MS = 30 * 60 * 1000
|
|
136
|
+
|
|
137
|
+
/** the parties of the machine for these sessions (every recorded one when none is named): each session, live while its
|
|
138
|
+
* Claude Code process runs; every lane it started, from their transcripts (live until their hand back, an ended turn or
|
|
139
|
+
* 30 min of silence, and never past their session); each one's watch from the live watchers given. `self`: the
|
|
140
|
+
* caller's session, live since it asks */
|
|
141
|
+
export async function readParties(o: { sessions?: readonly string[]; watchers?: readonly Watcher[]; self?: string | null; now?: number } = {}): Promise<Parties> {
|
|
142
|
+
const now = o.now ?? Date.now()
|
|
143
|
+
const records = readSessionRecords()
|
|
144
|
+
const ids = new Set(o.sessions ?? records.map((r) => r.session))
|
|
145
|
+
if (o.self) ids.add(o.self)
|
|
146
|
+
if (ids.size === 0) return NO_PARTIES
|
|
147
|
+
const alive = claudeAlive(records.filter((r) => ids.has(r.session)).map((r) => r.pid))
|
|
148
|
+
const { listTranscripts } = await import('./store.ts')
|
|
149
|
+
// every lane a session ever started is listed (its name only), so a name none of them has is the session's own
|
|
150
|
+
// newest first: of two transcripts that carry one lane name, the latest is the one a resume reaches
|
|
151
|
+
const files = listTranscripts().filter((f) => ids.has(f.session)).sort((a, b) => b.mtime - a.mtime)
|
|
152
|
+
const ws = o.watchers ?? []
|
|
153
|
+
const sessions: SessionParty[] = [...ids].map((id) => {
|
|
154
|
+
const r = records.find((x) => x.session === id)
|
|
155
|
+
// the session's own transcript first: a lane may start in a sub folder or another repo
|
|
156
|
+
const own = files.filter((f) => f.session === id).sort((a, b) => Number(a.agent !== '') - Number(b.agent !== ''))
|
|
157
|
+
const cwd = own.map((f) => cwdOf(f.path)).find((c) => c !== '')
|
|
158
|
+
const repo = cwd ? repoNameOf(cwd) : r?.stores[0] ? repoNameOf(dirname(dirname(r.stores[0]))) : 'a repo'
|
|
159
|
+
const live = id === o.self || (r !== undefined && alive.has(r.pid))
|
|
160
|
+
return { id, repo, live, watch: ws.some((w) => w.lane === null && (w.session === id || (w.session === null && w.by === id))) }
|
|
161
|
+
})
|
|
162
|
+
const lanes: LaneParty[] = files.flatMap((f) => {
|
|
163
|
+
if (f.agent === '') return []
|
|
164
|
+
let what = ''
|
|
165
|
+
try {
|
|
166
|
+
const meta = JSON.parse(readFileSync(f.path.replace(/\.jsonl$/, '.meta.json'), 'utf8')) as { description?: unknown }
|
|
167
|
+
what = typeof meta.description === 'string' ? meta.description : ''
|
|
168
|
+
} catch {}
|
|
169
|
+
const names = laneNamesOf(what, headOf(f.path))
|
|
170
|
+
if (names.length === 0) return []
|
|
171
|
+
const sessionLive = sessions.find((s) => s.id === f.session)?.live ?? false
|
|
172
|
+
// a lane silent for its idle time has ended: its file is never read
|
|
173
|
+
const live = sessionLive && now - f.mtime < LANE_IDLE_MS && laneRunning(f.path)
|
|
174
|
+
const id = agentIdOf(f.agent)
|
|
175
|
+
return names.map((name) => ({ name, session: f.session, live, watch: ws.some((w) => w.lane === name && (w.session === null || w.session === f.session) && (w.by === undefined || w.by === f.session)), what, ...(id ? { id } : {}) }))
|
|
176
|
+
})
|
|
177
|
+
// a lane whose transcript names it no way the registry reads, while its watch lives: live, since a watch ends with its lane
|
|
178
|
+
for (const w of ws) {
|
|
179
|
+
const session = w.by ?? w.session
|
|
180
|
+
if (w.lane === null || session === null || !ids.has(session) || lanes.some((l) => l.name === w.lane && l.session === session)) continue
|
|
181
|
+
lanes.push({ name: w.lane, session, live: sessions.find((s) => s.id === session)?.live ?? false, watch: true })
|
|
182
|
+
}
|
|
183
|
+
return { sessions, lanes }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** a lane's resume handle from its transcript's name: `agent-<id>` → `<id>`, the id its session's SendMessage takes.
|
|
187
|
+
* Measured: inside a lane no variable names it (CLAUDE_CODE_SESSION_ID is its parent's), so the file is the one source */
|
|
188
|
+
export const agentIdOf = (agent: string): string | null => /^agent-([A-Za-z0-9_-]{4,64})$/.exec(agent)?.[1] ?? null
|
|
189
|
+
|
|
190
|
+
/** a lane ended holding these threads, and its session heard his message on them: its next `sk` call takes them back
|
|
191
|
+
* (review/take-back.ts), unless its session took one itself first */
|
|
192
|
+
export interface Handed {
|
|
193
|
+
lane: string
|
|
194
|
+
session: string
|
|
195
|
+
threads: { dir: string; head: string; address: string }[]
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export const handedFile = (session: string, lane: string): string => `${fileOf(session).slice(0, -'.json'.length)}.${lane.replace(/[^\w-]/g, '_')}.handed`
|
|
199
|
+
|
|
200
|
+
export function readHanded(session: string, lane: string): Handed | null {
|
|
201
|
+
try {
|
|
202
|
+
const v = JSON.parse(readFileSync(handedFile(session, lane), 'utf8')) as Handed
|
|
203
|
+
return Array.isArray(v.threads) ? v : null
|
|
204
|
+
} catch {
|
|
205
|
+
return null
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function writeHanded(h: Handed): void {
|
|
210
|
+
const file = handedFile(h.session, h.lane)
|
|
211
|
+
if (h.threads.length === 0) {
|
|
212
|
+
rmSync(file, { force: true })
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
mkdirSync(sessionsDir(), { recursive: true })
|
|
216
|
+
writeFileSync(`${file}.${process.pid}.tmp`, `${JSON.stringify(h)}\n`)
|
|
217
|
+
renameSync(`${file}.${process.pid}.tmp`, file)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** his message on a thread of an ended lane reached its session: the lane's next `sk` call takes the thread back */
|
|
221
|
+
export function noteHanded(lane: string, session: string, t: Handed['threads'][number]): void {
|
|
222
|
+
try {
|
|
223
|
+
const was = readHanded(session, lane)?.threads ?? []
|
|
224
|
+
if (was.some((x) => x.dir === t.dir && x.head === t.head)) return
|
|
225
|
+
writeHanded({ lane, session, threads: [...was, t] })
|
|
226
|
+
} catch {}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** a take by anyone but `keep` (the session itself, another lane): that thread is no longer the ended lane's to take back */
|
|
230
|
+
export function dropHanded(session: string, dir: string, head: string, keep: string | null): void {
|
|
231
|
+
const prefix = basename(fileOf(session)).slice(0, -'.json'.length)
|
|
232
|
+
let names: string[]
|
|
233
|
+
try {
|
|
234
|
+
names = readdirSync(sessionsDir())
|
|
235
|
+
} catch {
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
for (const n of names) {
|
|
239
|
+
if (!n.startsWith(`${prefix}.`) || !n.endsWith('.handed')) continue
|
|
240
|
+
const h = readHanded(session, n.slice(prefix.length + 1, -'.handed'.length))
|
|
241
|
+
if (h === null || h.lane === keep) continue
|
|
242
|
+
const rest = h.threads.filter((x) => !(x.dir === dir && x.head === head))
|
|
243
|
+
if (rest.length !== h.threads.length) writeHanded({ ...h, threads: rest })
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export const clearHanded = (session: string, lane: string): void => rmSync(handedFile(session, lane), { force: true })
|
|
248
|
+
|
|
249
|
+
/** the folder a transcript's agent works in, from its first lines */
|
|
250
|
+
function cwdOf(path: string): string {
|
|
251
|
+
try {
|
|
252
|
+
const fd = openSync(path, 'r')
|
|
253
|
+
try {
|
|
254
|
+
const buf = Buffer.alloc(16 * 1024)
|
|
255
|
+
const n = readSync(fd, buf, 0, buf.length, 0)
|
|
256
|
+
return /"cwd":"([^"]+)"/.exec(buf.subarray(0, n).toString('utf8'))?.[1] ?? ''
|
|
257
|
+
} finally {
|
|
258
|
+
closeSync(fd)
|
|
259
|
+
}
|
|
260
|
+
} catch {
|
|
261
|
+
return ''
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** a lane's last entries say it still works: no hand back, no ended turn (live.ts stateOf over its tail) */
|
|
266
|
+
function laneRunning(path: string): boolean {
|
|
267
|
+
try {
|
|
268
|
+
const size = statSync(path).size
|
|
269
|
+
const fd = openSync(path, 'r')
|
|
270
|
+
try {
|
|
271
|
+
const len = Math.min(size, 32 * 1024)
|
|
272
|
+
const buf = Buffer.alloc(len)
|
|
273
|
+
readSync(fd, buf, 0, len, size - len)
|
|
274
|
+
const lines = buf.toString('utf8').split('\n').filter((l) => l !== '')
|
|
275
|
+
return stateOf(size > len ? lines.slice(1) : lines).state.kind !== 'ended'
|
|
276
|
+
} finally {
|
|
277
|
+
closeSync(fd)
|
|
278
|
+
}
|
|
279
|
+
} catch {
|
|
280
|
+
return false
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** the repo a folder is in: the name of its git root, a linked worktree counted with its repo */
|
|
285
|
+
export function repoNameOf(dir: string): string {
|
|
286
|
+
const clean = dir.replace(/\/\.claude\/worktrees\/.*$/, '')
|
|
287
|
+
for (let at = clean; at !== '/' && at !== ''; at = dirname(at)) if (existsSync(join(at, '.git'))) return basename(at)
|
|
288
|
+
return basename(clean)
|
|
289
|
+
}
|
package/src/agent-time/store.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { homedir } from 'os'
|
|
|
19
19
|
import { basename, dirname, join } from 'path'
|
|
20
20
|
import { foldRefusal, MACHINE_DB_FILE, machineFileCreate, ownerOnlyFile, StoreRefused, storeHome } from '../core/machine-db.ts'
|
|
21
21
|
import { createRefusal, machinePath } from '../core/machine-layout.ts'
|
|
22
|
-
import { ensureWal } from '../ledger/db.ts'
|
|
22
|
+
import { ensureWal, storeSync } from '../ledger/db.ts'
|
|
23
23
|
import { type ConfigRoot, discoverConfigRoots } from '../reflect/prompt-corpus.ts'
|
|
24
24
|
import { type TranscriptEvent, readTranscriptLine } from '../reflect/transcript.ts'
|
|
25
25
|
import { SHAPE_VERSION, toolShape } from './shape.ts'
|
|
@@ -152,7 +152,7 @@ export function openIndex(path = agentTimeDbPath()): Database {
|
|
|
152
152
|
db.exec('pragma busy_timeout = 30000')
|
|
153
153
|
machineFileCreate(path, db)
|
|
154
154
|
ensureWal(db, 5_000)
|
|
155
|
-
db
|
|
155
|
+
storeSync(db, 'NORMAL')
|
|
156
156
|
db.exec(SCHEMA)
|
|
157
157
|
migrate(db)
|
|
158
158
|
return db
|
package/src/annex/born.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { basename, dirname, join, resolve } from 'node:path'
|
|
|
12
12
|
import { machineGet, machineRead, machineSet } from '../core/machine-db.ts'
|
|
13
13
|
import { type AnnexSpec, driveFree, isPresent, keepFree } from './annex.ts'
|
|
14
14
|
import { flushDrive, syncFile } from './flush.ts'
|
|
15
|
-
import { asidesOf, type Checks, editOffloads, entries,
|
|
15
|
+
import { askGit, asidesOf, type Checks, editOffloads, entries, inScratch, type Offload, offloads, ownerOf, PART_MARK, refusal, stageOf, stampOf, tally, toTrash } from './offload.ts'
|
|
16
16
|
|
|
17
17
|
const GB = 1e9
|
|
18
18
|
export type Say = (line: string) => void
|
|
@@ -421,7 +421,7 @@ export async function bornCheck(root: string, rel: string, specs: readonly Annex
|
|
|
421
421
|
if (l) {
|
|
422
422
|
const why = await refusal(root, rel, { ...o, open: false })
|
|
423
423
|
if (why) return { why: `stays on the Mac: ${why}` }
|
|
424
|
-
} else if (!(o.git
|
|
424
|
+
} else if (!askGit(o.git, root, ['check-ignore', '-q', '--', rel]).ok) return { why: 'is declared born on the annex, and git does not ignore it' }
|
|
425
425
|
const bytes = l ? tally(at).bytes : 0
|
|
426
426
|
const annex = specs.find((a) => isPresent(a) && driveFree(a.path) - bytes >= keepFree(a))
|
|
427
427
|
if (!annex) return { why: 'is declared born on the annex, and no annex is present with room: it stays on the Mac' }
|
package/src/annex/offload.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, readlinkSync, readSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
6
6
|
import { homedir } from 'node:os'
|
|
7
7
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
8
|
+
import { realGit, type GitIo } from '../core/git.ts'
|
|
8
9
|
import { machineGet, machineRead, machineSet } from '../core/machine-db.ts'
|
|
9
10
|
import { openOf } from '../media-store/purge.ts'
|
|
10
11
|
import { driveFree, keepFree, presentAnnexes } from './annex.ts'
|
|
@@ -157,9 +158,10 @@ export function tally(path: string): { files: number; bytes: number } {
|
|
|
157
158
|
return { files: all.length, bytes: all.reduce((n, e) => n + e.size, 0) }
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
/** `git -C root …args` through `io` (the real git by default): did it exit 0, and what it printed */
|
|
162
|
+
export const askGit = (io: GitIo | undefined, root: string, args: string[]): { ok: boolean; out: string } => {
|
|
163
|
+
const r = (io ?? realGit).runSync(root, args)
|
|
164
|
+
return { ok: r.code === 0, out: r.out.trim() }
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
/** the folders whose content is scratch by the house's own rule: the backup denies them, a gate rebuilds them */
|
|
@@ -175,16 +177,16 @@ export type Probe = {
|
|
|
175
177
|
flush?: (dir: string) => void
|
|
176
178
|
/** the paths some process holds open (`lsof`, about 180 ms a call, by default) */
|
|
177
179
|
openOf?: (paths: readonly string[]) => Set<string>
|
|
178
|
-
/** git in the repo (
|
|
179
|
-
git?:
|
|
180
|
+
/** git in the repo, for the place checks and the backup's inventory (the real git, about 20 ms a call, by default) */
|
|
181
|
+
git?: GitIo
|
|
180
182
|
/** the first path at or under `path` the backup's own inventory holds (`collect`, about 45 ms, by default) */
|
|
181
183
|
backupHolds?: (root: string, path: string, home: string) => Promise<string | null>
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/** the backup's own inventory of `root`: the first path it holds at or under `path` */
|
|
185
|
-
async function backupHolds(root: string, path: string, home: string): Promise<string | null> {
|
|
187
|
+
async function backupHolds(root: string, path: string, home: string, git?: GitIo): Promise<string | null> {
|
|
186
188
|
const { collect } = await import('../media-store/backup/sources.ts')
|
|
187
|
-
return (await collect({ home, repos: [root] })).find((x) => x.abs === path || x.abs.startsWith(`${path}/`))?.abs ?? null
|
|
189
|
+
return (await collect({ home, repos: [root], git })).find((x) => x.abs === path || x.abs.startsWith(`${path}/`))?.abs ?? null
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
/** a copy first move (born.ts) checks the open files on the aside after its copy: this switches that check off */
|
|
@@ -197,9 +199,8 @@ export async function refusal(root: string, rel: string, o: Checks = {}): Promis
|
|
|
197
199
|
if (!s) return `${rel} does not exist`
|
|
198
200
|
if (s.isSymbolicLink()) return `${rel} is a symlink already${offloads().some((o) => o.repo === root && o.rel === rel) ? ' (offloaded)' : ''}`
|
|
199
201
|
if (!inScratch(rel)) return `${rel} is outside ${SCRATCH.join(' and ')}: only scratch leaves the Mac`
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
if (!run(root, ['check-ignore', '-q', '--', rel]).ok) return `git does not ignore ${rel}: work in progress stays on the Mac`
|
|
202
|
+
if (askGit(o.git, root, ['ls-files', '--', rel]).out !== '') return `git tracks files under ${rel}`
|
|
203
|
+
if (!askGit(o.git, root, ['check-ignore', '-q', '--', rel]).ok) return `git does not ignore ${rel}: work in progress stays on the Mac`
|
|
203
204
|
const list = s.isDirectory() ? entries(path) : [{ rel: basename(rel), dir: false, file: s.isFile(), link: false, size: s.size }]
|
|
204
205
|
const base = s.isDirectory() ? path : dirname(path)
|
|
205
206
|
const names = list.map((e) => e.rel)
|
|
@@ -215,7 +216,7 @@ export async function refusal(root: string, rel: string, o: Checks = {}): Promis
|
|
|
215
216
|
return lands !== path && !lands.startsWith(`${path}/`)
|
|
216
217
|
})
|
|
217
218
|
if (out) return `${rel} holds a relative link that points out of it (${out.rel} -> ${readlinkSync(join(base, out.rel))}): moved, it would point elsewhere`
|
|
218
|
-
const kept = await (o.backupHolds ?? backupHolds)(root, path, o.home ?? homedir())
|
|
219
|
+
const kept = await (o.backupHolds ?? ((r, p, h) => backupHolds(r, p, h, o.git)))(root, path, o.home ?? homedir())
|
|
219
220
|
if (kept) return `the backup holds ${relative(root, kept)}: what a backup keeps stays on the Mac`
|
|
220
221
|
const { mediaDb } = await import('../media-store/db.ts')
|
|
221
222
|
const rows = (mediaDb()?.query('select store, item, name from media_files where local = 1').all() ?? []) as { store: string; item: string; name: string }[]
|
package/src/asks/ask-after.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// an ask's `after:` value: the moment the ask waits for. Before it the ask is later (out of the open count and the
|
|
2
|
-
// ping), from it an open ask. Pure and browser safe: the
|
|
2
|
+
// ping), from it an open ask. Pure and browser safe: the asks (ask-store.ts) read with it, the hub draws with it
|
|
3
3
|
const VALUE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?$/
|
|
4
4
|
|
|
5
5
|
export const AFTER_FORMS = 'YYYY-MM-DD or YYYY-MM-DDTHH:MM, local time'
|
|
@@ -22,8 +22,12 @@ const dayOf = (t: Date): string => `${t.getFullYear()}-${pad(t.getMonth() + 1)}-
|
|
|
22
22
|
export function afterValue(arg: string, now: Date): string {
|
|
23
23
|
const v = arg.trim()
|
|
24
24
|
if (afterMs(v) != null) return v
|
|
25
|
+
// the words a thread's « set aside » reads too (review/snooze.ts): tomorrow and next week at 9:00
|
|
26
|
+
const at9 = (d: number): string => `${dayOf(new Date(now.getFullYear(), now.getMonth(), now.getDate() + d))}T09:00`
|
|
27
|
+
if (v === 'tomorrow') return at9(1)
|
|
28
|
+
if (v === 'next-week' || v === 'next week') return at9(((8 - now.getDay()) % 7) || 7)
|
|
25
29
|
const rel = /^(\d+)([dw])$/.exec(v)
|
|
26
|
-
if (rel == null) throw new Error(`--after '${arg}' names no day: write ${AFTER_FORMS}, or 2d, 1w from today`)
|
|
30
|
+
if (rel == null) throw new Error(`--after '${arg}' names no day: write ${AFTER_FORMS}, or 2d, 1w from today, tomorrow, next-week`)
|
|
27
31
|
const days = Number(rel[1]) * (rel[2] === 'w' ? 7 : 1)
|
|
28
32
|
return dayOf(new Date(now.getFullYear(), now.getMonth(), now.getDate() + days))
|
|
29
33
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// the « Done: <title> » question an older `sk ask` posted on an ask with nothing else to ask, folded into the ask bar
|
|
2
|
+
// (wiki tools/shipkit/threads-asks.md, The ask bar): the bar's « done ✓ » answers the same thing, so one `askBar` message
|
|
3
|
+
// names it as the bar's own and no cell or dock entry draws it again. Re-runnable: a question named already is left alone
|
|
4
|
+
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
5
|
+
import { partyOf, type Message } from '../review/model.ts'
|
|
6
|
+
import { appendMessage, readAll, storeDir } from '../review/store.ts'
|
|
7
|
+
import { askStateOf, membersOf, orderedThreads, type Thread } from '../review/threads.ts'
|
|
8
|
+
import { barOwnOf } from '../review/supersede.ts'
|
|
9
|
+
import { askOfThread, isClosed } from './ask-store.ts'
|
|
10
|
+
|
|
11
|
+
/** 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
|
+
function doneConfirmsOf(t: Thread): { home: string; m: Message }[] {
|
|
13
|
+
const a = askOfThread(t)
|
|
14
|
+
if (a === null) return []
|
|
15
|
+
const members = membersOf(t)
|
|
16
|
+
const titles = new Set([t.head.item.title, a.title, ...members.flatMap((x) => x.thread.flatMap((m) => (m.instructions ? [m.instructions.title] : [])))])
|
|
17
|
+
const bar = barOwnOf(members)
|
|
18
|
+
return members.flatMap((x) =>
|
|
19
|
+
x.thread
|
|
20
|
+
.filter((m) => partyOf(m.who) === 'agent' && m.ask?.kind === 'confirm' && m.text?.startsWith('Done: ') === true && titles.has(m.text.slice('Done: '.length).trim()) && !bar.has(m.id))
|
|
21
|
+
.map((m) => ({ home: x.item.id, m })),
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** one folded question: its ask, its message, his answer on it when he gave one (kept: a tick is the ask's « done », his
|
|
26
|
+
* words stay his reply in the thread) */
|
|
27
|
+
export type FoldLine = { ask: string; question: string; his: string | null }
|
|
28
|
+
|
|
29
|
+
/** every « Done: » question of the repo's asks, counted, then (`go`) folded into the bar under the repo's asks lease.
|
|
30
|
+
* The `askBar` message is dated with its question, 1 ms after it: the question was the bar's from the start, and a
|
|
31
|
+
* fold neither makes its lane the thread's holder nor moves the thread in his « since you left » */
|
|
32
|
+
export async function foldDoneConfirms(root: string, o: { go: boolean; lane?: string }): Promise<{ before: number; lines: FoldLine[]; after: number }> {
|
|
33
|
+
const store = storeDir(root)
|
|
34
|
+
const count = (): number => orderedThreads(readAll(store).items).reduce((n, t) => n + doneConfirmsOf(t).length, 0)
|
|
35
|
+
const leased = await withMutateLease(mutateLease(root, 'asks'), { label: 'asks fold', print: () => {}, maxWaitMs: 45_000 }, () => {
|
|
36
|
+
const before = count()
|
|
37
|
+
const lines: FoldLine[] = []
|
|
38
|
+
for (const t of orderedThreads(readAll(store).items)) {
|
|
39
|
+
const qs = doneConfirmsOf(t)
|
|
40
|
+
if (qs.length === 0) continue
|
|
41
|
+
const a = askOfThread(t)!
|
|
42
|
+
for (const { home, m } of qs) {
|
|
43
|
+
const his = membersOf(t).flatMap((x) => x.thread).filter((y) => y.re === m.id && partyOf(y.who) === 'owner').at(-1) ?? null
|
|
44
|
+
lines.push({ ask: a.id, question: m.id, his: his === null ? null : his.answer?.tick === true ? 'done' : his.answer?.tick === false ? 'not done' : `the owner's words: ${his.text ?? ''}` })
|
|
45
|
+
if (!o.go) continue
|
|
46
|
+
appendMessage(store, home, { who: o.lane ?? 'agent', askBar: [m.id] }, { now: new Date(Date.parse(m.at) + 1) })
|
|
47
|
+
// his « done » on it is the ask's: an open ask whose state said nothing since closes done
|
|
48
|
+
const state = askStateOf(t)
|
|
49
|
+
if (his?.answer?.tick === true && !isClosed(a.status) && (state === null || state.at < his.at))
|
|
50
|
+
appendMessage(store, t.head.item.id, { who: 'owner', askState: { state: 'done', why: `his « done » on « ${m.text} »` } }, { now: new Date(Date.parse(his.at) + 1) })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { before, lines, after: o.go ? count() : before }
|
|
54
|
+
})
|
|
55
|
+
if (!leased.ok) throw new Error(`asks of ${root} not folded: ${leased.warn}`)
|
|
56
|
+
return leased.value
|
|
57
|
+
}
|